From f0a79e5c6e0e8de279faec3dfe2c5a9ec2e31727 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Fri, 26 Apr 2019 10:12:20 +0200 Subject: [PATCH] remote control: add /STATE methods --- CHANGELOG.md | 4 +++ resources/docs/docs/remote-control.md | 22 ++++++++++++++++ src/client/app/remote-control.js | 38 +++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51bb3aa1..ac89f436 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ - bug fixes: - modal: `css` not properly applied if the property was previously empty and the modal had been opened at least once - image: allow overriding css background-image when value is empty +- widgets + - switchers: new `state` widget +- remote control + - added `/STATE/[GET|SET|STORE|RECALL]` methods ## 0.45.7 diff --git a/resources/docs/docs/remote-control.md b/resources/docs/docs/remote-control.md index 9b3305b2..c3b6edc5 100644 --- a/resources/docs/docs/remote-control.md +++ b/resources/docs/docs/remote-control.md @@ -109,6 +109,28 @@ Set a widget's value as if it was interacted with from the interface. This is li - `value`: `*`, widget's new value +## `/STATE/GET target` + +Sends back the app's state to specified target + +- `target`: `string`, `ip:port` pair + +## `/STATE/GET state` + +Set widgets' state + +- `state`: `string`, json stringified object (`"widget_id": value` pairs) + + +## `/STATE/STORE` + +Save the state of all widgets in the temporary slot. + +## `/STATE/RECALL` + +Reload saved state from the temporary slot. + + ## `/TABS id id etc` Open the tabs designated by the `id` parameters. diff --git a/src/client/app/remote-control.js b/src/client/app/remote-control.js index 926379a4..70db4bb4 100644 --- a/src/client/app/remote-control.js +++ b/src/client/app/remote-control.js @@ -1,6 +1,7 @@ var {updateWidget} = require('./editor/data-workers'), editor = require('./editor'), widgetManager = require('./managers/widgets'), + stateManager = require('./managers/state'), deepExtend = require('deep-extend') var callbacks = { @@ -174,6 +175,43 @@ var callbacks = { } + }, + '/STATE/GET': function(args) { + + if (Array.isArray(args)) args = args[0] + + var target = args, + root = widgetManager.getWidgetById('root')[0], + state = stateManager.get() + + root.sendValue({ + target: [target], + address: '/STATE/GET', + preArgs: [], + v: JSON.stringify(state), + noSync: true + }, {force: true}) + + }, + '/STATE/SET': function(args) { + + if (Array.isArray(args)) args = args[0] + + var json = args, + data = typeof json == 'string' ? JSON.parseFlex(json) : json + + stateManager.set(data) + + }, + '/STATE/STORE': function(args) { + + stateManager.quickSave() + + }, + '/STATE/RECALL': function(args) { + + stateManager.quickLoad() + }, '/TABS': function(args) {