From a90211223f4a67e83cf956ed32c910493faa5188 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Mon, 7 Nov 2022 13:07:02 +0100 Subject: [PATCH] scripting: soft and hard reload --- resources/docs/docs/widgets/scripting.md | 5 +++-- src/client/widgets/scripts/script-vm.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 6b99a4f4..dda377ce 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -352,8 +352,9 @@ Run `callback` function as if executed by another that widget matches specified ---- -#### `reload()` +#### `reload(keepState)` +- `keepState` (optional): `true` by default, set to false to discard the client's state. -Reload the client application (retains session and state). Cannot be called from the `onCreate` property. +Reload the client application. 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/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index a43f3780..d9e58f36 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -530,7 +530,7 @@ class ScriptVm extends Vm { } - this.sandbox.contentWindow.reload = ()=>{ + this.sandbox.contentWindow.reload = (keepState = true)=>{ this.checkContext('reload') @@ -540,7 +540,8 @@ class ScriptVm extends Vm { var widget = this.getWidget() widget.errorProp('onCreate', '', 'reload() cannot be called from onCreate') } else if (options.send){ - ipc.trigger('reload') + if (keepState) ipd.trigger('reload') + else window.location.href = window.location.href }