From b5446c08ac1a7e9a15e8ce96d636f4c0182c8d78 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 1 Mar 2021 09:29:17 +0100 Subject: [PATCH 01/12] modal: remove visibility optimization (hard to track edge effect) --- CHANGELOG.md | 7 ++++++- src/client/ui/ui-colorpicker.js | 7 ------- src/client/widgets/common/widget.js | 8 +------- src/client/widgets/containers/modal.js | 7 ------- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b339a0..71d227a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,17 @@ # Changelog +# 1.8.10 + +- bug fixes + - modal: issues with children's visibility + # 1.8.9 - bug fixes - script: issue when using the `options` argument in `set()` (options leaked to subsequent set() calls in the script) - multixy: `decimals` property not applied - multixy: spring behavior not working until all points are released - - custom module: prevent require() from reading submodules files each time and instead return the object in memory + - custom module: prevent require() from reading submodules files each time and instead return the object in memory # 1.8.8 diff --git a/src/client/ui/ui-colorpicker.js b/src/client/ui/ui-colorpicker.js index 5871f016..8d962438 100644 --- a/src/client/ui/ui-colorpicker.js +++ b/src/client/ui/ui-colorpicker.js @@ -100,13 +100,6 @@ class ColorPicker extends UiWidget { } - childrenVisible() { - - return true - - } - - setName(n = '') { this.name = n diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index 84749641..4892c509 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -1065,13 +1065,7 @@ class Widget extends EventEmitter { isVisible() { - return this.getProp('visible') && this.parent.childrenVisible() - - } - - childrenVisible() { - - return this.isVisible() + return this.getProp('visible') && this.parent.isVisible() } diff --git a/src/client/widgets/containers/modal.js b/src/client/widgets/containers/modal.js index 1010654c..b3cc5311 100644 --- a/src/client/widgets/containers/modal.js +++ b/src/client/widgets/containers/modal.js @@ -126,13 +126,6 @@ class Modal extends Panel { } - - childrenVisible() { - - return this.init && this.value && this.isVisible() - - } - setValue(v, options={}) { if (this.init === undefined) return From e9a829b32392c8e8a007f9b212a15c0fccee6783 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 1 Mar 2021 10:41:55 +0100 Subject: [PATCH 02/12] scripting: add setFocus(id) --- CHANGELOG.md | 3 +++ resources/docs/docs/widgets/scripting.md | 10 ++++++++++ src/client/widgets/scripts/script-vm.js | 22 +++++++++++++++++++++- src/server/electron-window.js | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71d227a8..c754d7fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ - bug fixes - modal: issues with children's visibility +- scripting + - add `setFocus` function to focus an input widget programmatically + # 1.8.9 - bug fixes diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 9f0a3a75..0f44424a 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -170,6 +170,16 @@ Reference: ---- +#### `setFocus(id)` + +- `id` (optional): widget `id` as a string + +Give focus to a widget (ie input widget). + +*Built-in client only*: tells the operating system to give the focus to the client window + +---- + #### `unfocus()` *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 e896534d..007a9b22 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -326,8 +326,28 @@ class ScriptVm extends Vm { } + + this.sandbox.contentWindow.setFocus = (id)=>{ + + if (id) { + var widgets = this.resolveId(id) + + if (widgets.length) { + setTimeout(()=>{ + + widgets[0].widget.focus() + }) + } + } + + // built-in client only: electron will call window.focus() + console.debug('ELECTRON.FOCUS()') + + } + this.sandbox.contentWindow.unfocus = ()=>{ + window.blur() // built-in client only: electron will call window.blur() console.debug('ELECTRON.BLUR()') @@ -354,7 +374,7 @@ class ScriptVm extends Vm { } for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage', - 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'unfocus', 'setScroll', 'getScroll', 'toolbar']) { + 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus', 'setScroll', 'getScroll', 'toolbar']) { this.sanitize(this.sandbox.contentWindow[imports]) } diff --git a/src/server/electron-window.js b/src/server/electron-window.js index 0c76e3a4..f605d6ae 100644 --- a/src/server/electron-window.js +++ b/src/server/electron-window.js @@ -101,6 +101,7 @@ module.exports = function(options={}) { window.webContents.on('console-message', (event, level, message)=>{ if (level === 0 && message === 'ELECTRON.BLUR()') window.blur() + if (level === 0 && message === 'ELECTRON.FOCUS()') window.focus() }) From f4261812af8918b399d660843e0f9d969f335bb7 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 1 Mar 2021 10:42:09 +0100 Subject: [PATCH 03/12] package: next is 1.8.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0707b56b..b4ccad68 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "open-stage-control", "productName": "Open Stage Control", "description": "Libre and modular OSC / MIDI controller", - "version": "1.8.9", + "version": "1.8.10", "author": { "name": "Jean-Emmanuel Doucet", "email": "jean-emmanuel@ammd.net" From ba08c2381fa173b9ba27eda89afa656dfd5f7c1c Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 1 Mar 2021 10:49:09 +0100 Subject: [PATCH 04/12] console: allow multiple arguments in console.log() --- CHANGELOG.md | 1 + src/client/ui/ui-console.js | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c754d7fb..d37f8f0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - bug fixes - modal: issues with children's visibility + - console: allow multiple arguments in console.log() - scripting - add `setFocus` function to focus an input widget programmatically diff --git a/src/client/ui/ui-console.js b/src/client/ui/ui-console.js index 719f0b0c..ddccd1e6 100644 --- a/src/client/ui/ui-console.js +++ b/src/client/ui/ui-console.js @@ -37,13 +37,17 @@ class UiConsole extends UiSidePanel { console._log = console.log console.log = function(message){ - _this.log('log', message) + for (let arg of arguments) { + _this.log('log', arg) + } console._log(...arguments) } console._error = console.error console.error = function(message){ - _this.log('error', message) + for (let arg of arguments) { + _this.log('error', arg) + } console._error(...arguments) } From b7a34162cb97afa57db70cedcb73f4258d60c94c Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 1 Mar 2021 11:26:21 +0100 Subject: [PATCH 05/12] launcher: add many keyboard shortcuts --- CHANGELOG.md | 3 ++ .../docs/docs/user-interface/launcher.md | 25 ++++++++++ src/launcher/toolbar.js | 48 +++++++++++++++---- 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d37f8f0b..c89640e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ - modal: issues with children's visibility - console: allow multiple arguments in console.log() +- launcher + - add many keyboard shortcuts + - scripting - add `setFocus` function to focus an input widget programmatically diff --git a/resources/docs/docs/user-interface/launcher.md b/resources/docs/docs/user-interface/launcher.md index 50be9631..8d73093b 100644 --- a/resources/docs/docs/user-interface/launcher.md +++ b/resources/docs/docs/user-interface/launcher.md @@ -30,17 +30,42 @@ The console diplays various informations, runtime errors and server debug messag | Shortcut | Description | |---|---| + | ++f5++ | start server | + | ++f6++ | stop server | + | ++ctrl+n++ | open new client window | + | ++ctrl+o++ | load settings | + | ++ctrl+s++ | save settings | + | ++ctrl+shift+s++ | save settings as... | + | ++ctrl+m++ | list midi devices | + | ++ctrl+l++ | clear console | | ++ctrl+w++ | close window | + === "Windows" | Shortcut | Description | |---|---| + | ++f5++ | start server | + | ++f6++ | stop server | + | ++ctrl+n++ | open new client window | + | ++ctrl+o++ | load settings | + | ++ctrl+s++ | save settings | + | ++ctrl+shift+s++ | save settings as... | + | ++ctrl+m++ | list midi devices | + | ++ctrl+l++ | clear console | | ++alt+f4++ | close window | === "Mac" | Shortcut | Description | |---|---| + | ++f5++ | start server | + | ++f6++ | stop server | + | ++cmd+n++ | open new client window | + | ++cmd+o++ | load settings | + | ++cmd+s++ | save settings | + | ++cmd+shift+s++ | save settings as... | + | ++cmd+m++ | list midi devices | + | ++cmd+l++ | clear console | | ++cmd+w++ | close window | | ++cmd+q++ | quit app | diff --git a/src/launcher/toolbar.js b/src/launcher/toolbar.js index e44be988..05f99439 100644 --- a/src/launcher/toolbar.js +++ b/src/launcher/toolbar.js @@ -3,6 +3,7 @@ var {remote, ipcRenderer} = require('electron'), menu = new Menu(), terminal = require('./terminal'), settings = require('./settings'), + keyboardJS = require('keyboardjs/dist/keyboard.min.js'), {midilist, openDocs} = remote.getGlobal('launcherSharedGlobals'), serverStarted = false, serverStart = ()=>{ @@ -16,18 +17,21 @@ var {remote, ipcRenderer} = require('electron'), var start = new MenuItem({ label: 'Start', - click: serverStart + click: serverStart, + accelerator: 'f5' }) var stop = new MenuItem({ label: 'Stop', - click: serverStop + click: serverStop, + accelerator: 'f6' }) var newWindow = new MenuItem({ label: 'New window', visible: false, click: ()=>{ ipcRenderer.send('openClient') - } + }, + accelerator: 'CmdOrCtrl + n' }) menu.append(start) menu.append(stop) @@ -39,19 +43,22 @@ menu.append(new MenuItem({ label: 'Load', click: ()=>{ settings.load() - } + }, + accelerator: 'CmdOrCtrl + o' })) menu.append(new MenuItem({ label: 'Save', click: ()=>{ settings.save() - } + }, + accelerator: 'CmdOrCtrl + s' })) menu.append(new MenuItem({ label: 'Save as...', click: ()=>{ settings.saveAs() - } + }, + accelerator: 'CmdOrCtrl + shift + s' })) menu.append(new MenuItem({ type: 'separator' @@ -60,14 +67,16 @@ menu.append(new MenuItem({ label: 'List MIDI Devices', click: ()=>{ midilist() - } + }, + accelerator: 'CmdOrCtrl + m' })) menu.append(new MenuItem({type: 'submenu' , label: 'Console', submenu: [ new MenuItem({ label: 'Clear', click: ()=>{ terminal.clear() - } + }, + accelerator: 'CmdOrCtrl + l' }), new MenuItem({ label: 'Autoscroll', @@ -106,6 +115,29 @@ menu.append(new MenuItem({ role: 'Quit' })) + +function bindShortcuts(menu) { + + for (let m of menu.items) { + + if (m.type === 'submenu') { + + bindShortcuts(m.submenu) + + } else if (m.accelerator && m.click) { + + keyboardJS.bind(m.accelerator.replace('CmdOrCtrl', 'mod'), (e)=>{ + m.click() + }) + + } + + } + +} + +bindShortcuts(menu) + class Toolbar { constructor() { From f6aaa2c63387d3b4eb2fdcefff58fd1747898bfd Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 1 Mar 2021 11:28:31 +0100 Subject: [PATCH 06/12] client: add clear console kb shortcut --- CHANGELOG.md | 5 +++-- resources/docs/docs/user-interface/client.md | 3 +++ src/client/ui/main-menu.js | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c89640e7..a74072d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,9 @@ - modal: issues with children's visibility - console: allow multiple arguments in console.log() -- launcher - - add many keyboard shortcuts +- ui + - launcher: add many keyboard shortcuts + - client: add keyboard shortcuts for clearing the console - scripting - add `setFocus` function to focus an input widget programmatically diff --git a/resources/docs/docs/user-interface/client.md b/resources/docs/docs/user-interface/client.md index 0a632661..b99398e7 100644 --- a/resources/docs/docs/user-interface/client.md +++ b/resources/docs/docs/user-interface/client.md @@ -55,6 +55,7 @@ Modals are virtual popup windows that may contain various content: file browser, |---|---| | ++ctrl+e++ | enable/disable editor | | ++ctrl+k++ | show/hide console | + | ++ctrl+l++ | clear console | | ++ctrl+s++ | save session | | ++ctrl+shift+s++ | save session as... | | ++ctrl+o++ | open a session file | @@ -66,6 +67,7 @@ Modals are virtual popup windows that may contain various content: file browser, |---|---| | ++ctrl+e++ | enable/disable editor | | ++ctrl+k++ | show/hide console | + | ++ctrl+l++ | clear console | | ++ctrl+s++ | save session | | ++ctrl+shift+s++ | save session as... | | ++ctrl+o++ | open a session file | @@ -77,6 +79,7 @@ Modals are virtual popup windows that may contain various content: file browser, |---|---| | ++cmd+e++ | enable/disable editor | | ++cmd+k++ | show/hide console | + | ++cmd+l++ | clear console | | ++cmd+s++ | save session | | ++cmd+shift+s++ | save session as... | | ++cmd+o++ | open a session file | diff --git a/src/client/ui/main-menu.js b/src/client/ui/main-menu.js index 72cb9777..7772cb48 100644 --- a/src/client/ui/main-menu.js +++ b/src/client/ui/main-menu.js @@ -184,6 +184,7 @@ var menuEntries = [ { label: locales('console_clear'), action: uiConsole.clear.bind(uiConsole), + shortcut: 'mod + l' }, ] }, From 98aad56781faa5b2748f52aa964707a002af6948 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 1 Mar 2021 11:38:50 +0100 Subject: [PATCH 07/12] misc: add usePercents to client options --- CHANGELOG.md | 3 +++ resources/docs/docs/client-options.md | 2 ++ src/client/editor/index.js | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a74072d8..dee662c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ - scripting - add `setFocus` function to focus an input widget programmatically +- misc + - add `usePercents` client option + # 1.8.9 - bug fixes diff --git a/resources/docs/docs/client-options.md b/resources/docs/docs/client-options.md index 89b712d1..83f47f70 100644 --- a/resources/docs/docs/client-options.md +++ b/resources/docs/docs/client-options.md @@ -12,6 +12,8 @@ Client options can be set either with the server's `--client-options` option, or | lang | string | *system_default* | use a different language than the default if available (available languages: en, fr) | | consoleLength | number | 300 | sets the maximum number of log messages in the client's console | | id | string | *random_id* | client's unique id (use with caution: two clients should never have the same id) | +| usePercents | 1 / 0 | 0 | sets the editor's "relative units" option | + Example: diff --git a/src/client/editor/index.js b/src/client/editor/index.js index 6820b395..8b4a8e20 100644 --- a/src/client/editor/index.js +++ b/src/client/editor/index.js @@ -130,7 +130,7 @@ class Editor { this.idClipboard = data.idClipboard }) - this.usePercents = false + this.usePercents = !!ENV.usePercents this.enabled = false this.grid = true From 82b83356f210320862ec5bc03deed9de78fe1655 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 1 Mar 2021 11:44:40 +0100 Subject: [PATCH 08/12] readme: irc link --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 93a0c8c3..146c9df5 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,12 @@ Open Stage Control *Libre and modular OSC / MIDI controller* -https://openstagecontrol.ammd.net/ + +Website: https://openstagecontrol.ammd.net/ +Forum: https://openstagecontrol.discourse.group/ +IRC: Freenode #openstagecontrol ---- -Copyleft © Jean-Emmanuel Doucet @ [AMMD](http://ammd.net) 2014-2020. +Copyleft © Jean-Emmanuel Doucet @ [AMMD](http://ammd.net) 2014-2021. This program is a free software released under the [GNU/GPL3](ttps://github.com/jean-emmanuel/open-stage-control/blob/master/LICENSE) license. From e44e5e48c777f212fa7c9d3104978df460503fc9 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 1 Mar 2021 11:46:54 +0100 Subject: [PATCH 09/12] readme: format --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 146c9df5..23a1dce3 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ Open Stage Control *Libre and modular OSC / MIDI controller* -Website: https://openstagecontrol.ammd.net/ -Forum: https://openstagecontrol.discourse.group/ -IRC: Freenode #openstagecontrol +- Website: https://openstagecontrol.ammd.net/ +- Forum: https://openstagecontrol.discourse.group/ +- IRC: Freenode #openstagecontrol ---- From 1d6794e6afb53d67e0d17f6348caaa89ad619eea Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 1 Mar 2021 17:23:11 +0100 Subject: [PATCH 10/12] custom module: expose `process` global --- CHANGELOG.md | 14 ++++++++++---- resources/docs/docs/custom-module/custom-module.md | 1 + src/server/custom-module.js | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dee662c5..15aa479b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog -# 1.8.10 +## next + +- custom module + - expose `process` global + + +## 1.8.10 - bug fixes - modal: issues with children's visibility @@ -14,9 +20,9 @@ - add `setFocus` function to focus an input widget programmatically - misc - - add `usePercents` client option + - add `usePercents` client option -# 1.8.9 +## 1.8.9 - bug fixes - script: issue when using the `options` argument in `set()` (options leaked to subsequent set() calls in the script) @@ -24,7 +30,7 @@ - multixy: spring behavior not working until all points are released - custom module: prevent require() from reading submodules files each time and instead return the object in memory -# 1.8.8 +## 1.8.8 - launcher - add file browser button for the `theme` option and fix parsing path containing spaces if only one theme is set diff --git a/resources/docs/docs/custom-module/custom-module.md b/resources/docs/docs/custom-module/custom-module.md index 01617bed..d1b0e5c0 100644 --- a/resources/docs/docs/custom-module/custom-module.md +++ b/resources/docs/docs/custom-module/custom-module.md @@ -136,6 +136,7 @@ This function can be used to load native node modules or locally installed modul - `clearInterval` - `__dirname` - `__filename` +- `process` ---- diff --git a/src/server/custom-module.js b/src/server/custom-module.js index 6b6178cf..b5c4336f 100644 --- a/src/server/custom-module.js +++ b/src/server/custom-module.js @@ -60,7 +60,8 @@ class CustomModule { setInterval: this.setInterval.bind(this), clearInterval: this.clearInterval.bind(this), require: this.require.bind(this), - nativeRequire: require + nativeRequire: require, + process: process } if (!this.submodule && !modulePathExtended) { From c32c268f16acb9599f3e152e9ddf83fe754c5276 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 1 Mar 2021 17:34:22 +0100 Subject: [PATCH 11/12] switch: widget not reacting at first touch when traversing is enabled on parent --- CHANGELOG.md | 3 +++ src/client/widgets/basics/switch.js | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15aa479b..09eb34ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## next +- bug fixes + - switch: widget not reacting at first touch when traversing is enabled on parent + - custom module - expose `process` global diff --git a/src/client/widgets/basics/switch.js b/src/client/widgets/basics/switch.js index edd2ea6b..69952bab 100644 --- a/src/client/widgets/basics/switch.js +++ b/src/client/widgets/basics/switch.js @@ -56,6 +56,10 @@ class Switch extends MenuBase { var index = 0, node = e.target + if (e.target === this.widget && e.traversing === true && e.firstTarget) { + node = e.firstTarget + } + if (touchFix && e.isTouch) { // special traversing touch fix node = document.elementFromPoint(e.clientX, e.clientY) From 3f75756fdae64da390b4e9c632bee5e222d46a8b Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 1 Mar 2021 17:39:41 +0100 Subject: [PATCH 12/12] script: add `openUrl` function --- CHANGELOG.md | 2 ++ package.json | 2 +- resources/docs/docs/widgets/scripting.md | 15 ++++++++++++--- src/client/widgets/scripts/script-vm.js | 11 ++++++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09eb34ff..5193c538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - custom module - expose `process` global +- scripting + - add `openUrl` function ## 1.8.10 diff --git a/package.json b/package.json index b4ccad68..c8255e61 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "open-stage-control", "productName": "Open Stage Control", "description": "Libre and modular OSC / MIDI controller", - "version": "1.8.10", + "version": "1.8.11", "author": { "name": "Jean-Emmanuel Doucet", "email": "jean-emmanuel@ammd.net" diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 0f44424a..f2c7ce42 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -161,7 +161,7 @@ Reference: #### `clearTimeout(id)` / `clearInterval(id)` -Clear timeout with matching `id`. +Clears timeout with matching `id`. Reference: @@ -174,7 +174,7 @@ Reference: - `id` (optional): widget `id` as a string -Give focus to a widget (ie input widget). +Gives focus to a widget (ie input widget). *Built-in client only*: tells the operating system to give the focus to the client window @@ -205,7 +205,7 @@ Sets the scroll state of a container. #### `toolbar(i1, i2, ...)` - `iX`: menu entry index -Trigger toolbar action at specified index. +Triggers toolbar action at specified index. !!! example "Examples" @@ -213,3 +213,12 @@ Trigger toolbar action at specified index. - `toolbar(3)` -> Toggle full screen Actions will only be triggered if initiated with a user interaction. Fullscreen cannot be toggled with a simulated interaction (i.e. using `/SET`) + + +#### `openUrl(url)` +- `url`: http(s) url + +*Built-in client only*: opens url with the system's default browser +*External client only*: opens url in a new tab + +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 007a9b22..99c66890 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -373,8 +373,17 @@ class ScriptVm extends Vm { } + this.sandbox.contentWindow.openUrl = (url)=>{ + + var options = this.getValueOptions() + + if (options.send) window.open(url, '_blank') + + } + for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage', - 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus', 'setScroll', 'getScroll', 'toolbar']) { + 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus', 'setScroll', 'getScroll', 'toolbar', + 'openUrl']) { this.sanitize(this.sandbox.contentWindow[imports]) }