scripting: add runAs()

This commit is contained in:
jean-emmanuel 2022-02-18 09:31:56 +01:00
parent c8a361b765
commit 7a24fb16a2
4 changed files with 31 additions and 3 deletions

View file

@ -190,7 +190,6 @@ class Button extends Widget {
newstate = 0
} else if (mode === 'momentary' && (v === null || v === undefined)) {
newstate = 1
}

View file

@ -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])
}