script: add openUrl function

This commit is contained in:
bordun 2021-03-01 17:39:41 +01:00
parent c32c268f16
commit 3f75756fda
4 changed files with 25 additions and 5 deletions

View file

@ -8,6 +8,8 @@
- custom module
- expose `process` global
- scripting
- add `openUrl` function
## 1.8.10

View file

@ -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"

View file

@ -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.

View file

@ -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])
}