Merge pull request #852 from matthijskooijman/create-session-osc-command

remote control: Add `/SESSION/CREATE` command
This commit is contained in:
jean-emmanuel 2024-06-22 12:04:53 +02:00 • committed by GitHub
commit 92d71019c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 60 additions and 0 deletions

View file

@ -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')
})
```

View file

@ -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`.

View file

@ -263,6 +263,11 @@ var callbacks = {
console.log(args)
},
'/SESSION/CREATE': function(args) {
sessionManager.create()
},
'/SESSION/OPEN': function(args) {