scripting: add runAs()
This commit is contained in:
parent
c8a361b765
commit
7a24fb16a2
4 changed files with 31 additions and 3 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -190,7 +190,6 @@ class Button extends Widget {
|
|||
newstate = 0
|
||||
|
||||
} else if (mode === 'momentary' && (v === null || v === undefined)) {
|
||||
|
||||
newstate = 1
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue