From 9cd107fd5cd85bd67ee48a7a69d7c4822573211f Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 4 Aug 2018 17:05:04 +0200 Subject: [PATCH] settings: add "--state" (#349) --- CHANGELOG.md | 2 ++ app/main/callbacks.js | 17 +++++++++++++++++ app/main/settings.js | 9 +++++++++ resources/docs/getting-started.md | 1 + src/browser/js/app/ipc/callbacks.js | 6 ++++++ 5 files changed, 35 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a603f7f3..fbf71b26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.35.0 +- main + - added `--state` option for loading a state file with a session file - state - loading a state file doesn't replace the quick save slot anymore - widgets diff --git a/app/main/callbacks.js b/app/main/callbacks.js index 42cb42c0..4ebe8933 100644 --- a/app/main/callbacks.js +++ b/app/main/callbacks.js @@ -133,7 +133,24 @@ module.exports = { }, sessionOpened: function(data, clientId) { + + if (settings.read('stateFile')) { + var send = true + for (var id in ipc.clients) { + // only make the client send its osc state if there are no other active clients + if (id !== clientId && ipc.clients[id].connected()) { + send = false + } + } + var state = { + state: settings.read('stateFile'), + send: send + } + ipc.send('stateLoad', state, clientId) + } + ipc.send('stateSend', null, null, clientId) + }, savingSession: function(data, clientId) { diff --git a/app/main/settings.js b/app/main/settings.js index c0bd6f69..21e6db0a 100644 --- a/app/main/settings.js +++ b/app/main/settings.js @@ -21,6 +21,7 @@ var options = { } }, 'l':{alias:'load',type:'string',file:{name:'OSC Session (.json)', extensions: ['json', 'js']},describe:'session file to load'}, + 'state':{type:'string',file:{name:'OSC State (.state)', extensions: ['state']},describe:'state file to load'}, 'b':{alias:'blank',type:'boolean',describe:'load a blank session and start the editor'}, 'c':{alias:'custom-module',type:'string',file:{name:'OSC Custom module (.js)', extensions: ['js']},describe:'custom module file to load'}, 'p':{alias:'port',type:'number',describe:'http port of the server (default to 8080)', @@ -145,6 +146,14 @@ var makeDefaultConfig = function(argv){ noGpu: argv['disable-gpu'] || false, readOnly: argv['read-only'] || false, midi: argv['midi'], + stateFile: (function(){ + if (!argv['state']) return false + try { + return JSON.parse(fs.readFileSync(argv['state'], 'utf8')) + } catch(err) { + return false + } + })(), appAddresses:function(){ var appAddresses = [] diff --git a/resources/docs/getting-started.md b/resources/docs/getting-started.md index b962eedf..65d09137 100644 --- a/resources/docs/getting-started.md +++ b/resources/docs/getting-started.md @@ -15,6 +15,7 @@ Below are the available command-line options. Note that when running without any |---||---| | `-s` | `--send` | default targets for all widgets (ip:port pairs)| | `-l` | `--load` | session file to load | +| | `--state` | state file to load (osc messages will be sent, unless there are other clients connected) | | `-b` | `--blank` | load a blank session and start the editor | | `-c` | `--custom-module` | custom module file to load | | `-p` | `--port` | http port of the server (default to 8080) | diff --git a/src/browser/js/app/ipc/callbacks.js b/src/browser/js/app/ipc/callbacks.js index 4aa0528e..eb256e9a 100644 --- a/src/browser/js/app/ipc/callbacks.js +++ b/src/browser/js/app/ipc/callbacks.js @@ -39,6 +39,12 @@ module.exports = { }, + stateLoad: function(data){ + + state.set(data.state, data.send) + + }, + stateSend:function(){ var p = utils.loading('New client connecting...')