diff --git a/package.json b/package.json index ed1dfc0b..d8ff9829 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "open-stage-control", "productName": "Open Stage Control", "description": "Libre and modular OSC / MIDI controller", - "version": "1.14.6", + "version": "1.15.0", "author": { "name": "Jean-Emmanuel Doucet", "email": "jean-emmanuel@ammd.net" diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 35ad76bf..f802b565 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -305,6 +305,7 @@ Triggers toolbar action at specified index. Actions will only be triggered if initiated with a user interaction. Fullscreen cannot be toggled with a simulated interaction (i.e. using `/SET`) +---- #### `openUrl(url)` - `url`: http(s) url @@ -313,3 +314,11 @@ Triggers toolbar action at specified index. *External client only*: opens url in a new tab If the event that triggered the script's execution was not initiated by a user interaction, this function will have no effect. + +---- + +#### `runAs(id, callback)` +- `id`: widget `id` as a string. +- `callback`: function to be executed + +Run `callback` function as if executed by another that widget matches specified id. This will not change the value of any local variable but `"this"` and `"parent"` arguments (accepted by functions such as `set()`) will be interpreted differently. Timeouts and intervals will be created and cleared in the target widget's scope. diff --git a/src/client/widgets/basics/button.js b/src/client/widgets/basics/button.js index 4514db94..ec61a7a4 100644 --- a/src/client/widgets/basics/button.js +++ b/src/client/widgets/basics/button.js @@ -190,7 +190,6 @@ class Button extends Widget { newstate = 0 } else if (mode === 'momentary' && (v === null || v === undefined)) { - newstate = 1 } diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index d64c9184..0650aff0 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -486,9 +486,29 @@ class ScriptVm extends Vm { } + this.sandbox.contentWindow.runAs = (id, callback)=>{ + + this.checkContext('runAs') + + var widgets = this.resolveId(id) + + if (widgets.length) { + + this.setWidget(widgets[0]) + try { + callback() + } catch(e) { + widget.errorProp('script', 'runAs', e) + } + this.setWidget() + + } + + } + for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage', 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus', 'setScroll', 'getScroll', 'toolbar', - 'openUrl', 'getVar', 'setVar']) { + 'openUrl', 'getVar', 'setVar', 'runAs']) { this.sanitize(this.sandbox.contentWindow[imports]) }