diff --git a/resources/docs/docs/custom-module/examples.md b/resources/docs/docs/custom-module/examples.md index 5fa3eb3e..2fe6e37e 100644 --- a/resources/docs/docs/custom-module/examples.md +++ b/resources/docs/docs/custom-module/examples.md @@ -404,3 +404,53 @@ module.exports = { } } ``` + +## Dynamic widget creation +```js +function create_widgets() { + receive('', '', '/EDIT', 'root', { + widgets: [{ + type: 'panel', + id: 'my_panel', + layout: 'vertical', + width: '100%', + height: '200%', + widgets: [ + { + type: 'text', + id: 'notice', + value: 'Hello, world!', + width: '100%', + }, + { + type: 'button', + id: 'button', + address: '/foo', + preArgs: [1], + }, + ] + }] + }) +} + +module.exports = { + reload: function(){ + // When reloading this script, recreate all widgets + create_widgets() + }, +} + +// Called when a client is opened +// +// This can be omitted if you want to dynamically create additional widgets on top +// of a session loaded with --load +app.once('open', () => { + app.once('sessionSetPath', (data) => { + // Session was created + create_widgets() + }) + // Create a new empty session + receive('', '', '/SESSION/CREATE') +}) + +``` diff --git a/resources/docs/docs/remote-control.md b/resources/docs/docs/remote-control.md index 98ea8c63..168f80fa 100644 --- a/resources/docs/docs/remote-control.md +++ b/resources/docs/docs/remote-control.md @@ -202,6 +202,11 @@ Save state session to `path.state`. ---- +#### `/SESSION/CREATE` + +Create a new empty session + +---- #### `/SESSION/OPEN path.json` Open session file `path.json`. diff --git a/src/client/remote-control.js b/src/client/remote-control.js index 1f0380c8..ad4705d5 100644 --- a/src/client/remote-control.js +++ b/src/client/remote-control.js @@ -263,6 +263,11 @@ var callbacks = { console.log(args) + }, + '/SESSION/CREATE': function(args) { + + sessionManager.create() + }, '/SESSION/OPEN': function(args) {