diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b67e308..b0439e49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 898ee47f..6b99a4f4 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -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. diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index 6d3a6b1c..9bf02e19 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -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}) } diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index 768f1c34..a43f3780 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -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 }