scripting: add reload() function

This commit is contained in:
jean-emmanuel 2022-11-07 13:02:01 +01:00
parent 2164964116
commit a77a9c01dd
4 changed files with 28 additions and 2 deletions

View file

@ -337,7 +337,7 @@ class Widget extends EventEmitter {
index: index
})
if (this.scripts.onCreate) this.scripts.onCreate.run({}, {sync: true, send: true})
if (this.scripts.onCreate) this.scripts.onCreate.run({}, {sync: true, send: true, onCreate: true})
}

View file

@ -4,6 +4,7 @@ var widgetManager = require('../../managers/widgets'),
{deepCopy} = require('../../utils'),
{urlParser} = require('../utils'),
Vm = require('../vm'),
ipc = require('../../ipc'),
toolbar
@ -529,13 +530,29 @@ class ScriptVm extends Vm {
}
this.sandbox.contentWindow.reload = ()=>{
this.checkContext('reload')
var options = this.getValueOptions()
if (options.onCreate) {
var widget = this.getWidget()
widget.errorProp('onCreate', '', 'reload() cannot be called from onCreate')
} else if (options.send){
ipc.trigger('reload')
}
}
this.sandbox.contentWindow.Image = Image
this.globals = {}
for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage',
'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus' , 'setFocusable', 'setScroll', 'getScroll', 'toolbar',
'openUrl', 'getVar', 'setVar', 'runAs', 'Image', 'updateCanvas']) {
'openUrl', 'getVar', 'setVar', 'runAs', 'reload', 'Image', 'updateCanvas']) {
this.sanitize(this.sandbox.contentWindow[imports])
this.globals[imports] = true
}