scripting: add reload() function
This commit is contained in:
parent
2164964116
commit
a77a9c01dd
4 changed files with 28 additions and 2 deletions
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
- scripting
|
||||
- add `setFocusable()` function to change the focusability of the window on the fly (allows reenabling focus temporarely to interact with a text widget using a dedicated toggle button for example)
|
||||
- add `reload()` function
|
||||
|
||||
|
||||
## 1.19.2
|
||||
|
|
|
|||
|
|
@ -349,3 +349,11 @@ If the event that triggered the script's execution was not initiated by a user i
|
|||
- `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.
|
||||
|
||||
----
|
||||
|
||||
#### `reload()`
|
||||
|
||||
Reload the client application (retains session and state). Cannot be called from the `onCreate` property.
|
||||
|
||||
If the event that triggered the script's execution was not initiated by a user interaction, this function will have no effect.
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue