From e99cdaa677f6d3a68889c77e6cdb504052d21701 Mon Sep 17 00:00:00 2001 From: bordun Date: Thu, 18 Jun 2020 13:37:50 +0200 Subject: [PATCH] script: add unfocus function (built-in client only) --- resources/docs/docs/widgets/scripting.md | 6 ++++++ src/client/widgets/scripts/script-vm.js | 8 +++++++- src/server/electron-window.js | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index d4f82c6b..47bcf805 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -125,3 +125,9 @@ Reference: - https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval ---- + +#### `unfocus`: `function()` + +*Built-in client only*: tells the operating system to give the focus to the window that was focused before. + +---- diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index b2f0e9e4..70697a63 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -278,8 +278,14 @@ class ScriptVm extends Vm { } + this.sandbox.contentWindow.unfocus = ()=>{ + + console.debug('ELECTRON.BLUR()') + + } + for (var imports of ['set', 'get', 'getProp', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage', - 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout']) { + 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'unfocus']) { this.sanitize(this.sandbox.contentWindow[imports]) } diff --git a/src/server/electron-window.js b/src/server/electron-window.js index 1de8564c..65c790b6 100644 --- a/src/server/electron-window.js +++ b/src/server/electron-window.js @@ -79,6 +79,12 @@ module.exports = function(options={}) { }) + window.webContents.on('console-message', (event, level, message)=>{ + + if (level === 0 && message === 'ELECTRON.BLUR()') window.blur() + + }) + window.webContents.setVisualZoomLevelLimits(1, 1) window.on('closed', function() {