From 75f600d20083be4bf39608e12be8f6823ff0841c Mon Sep 17 00:00:00 2001 From: bordun Date: Sat, 1 May 2021 16:15:09 +0200 Subject: [PATCH 1/3] docs: fancy download links --- resources/docs/download.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/resources/docs/download.md b/resources/docs/download.md index 8150ffe0..e6df6c79 100644 --- a/resources/docs/download.md +++ b/resources/docs/download.md @@ -20,6 +20,14 @@ function text(id, str) { el.textContent = str } +var names = { + 'amd64': 'GNU/Linux Debian (64-bit)', + 'linux-x64': 'GNU/Linux (64-bit)', + 'node': 'Node.js', + 'osx': 'MacOS', + 'win32-x64': 'Windows (64-bit)' +} + function reqListener () { var data = JSON.parse(this.responseText) @@ -30,9 +38,16 @@ function reqListener () { var list = document.createElement('ul') for (var i in data.assets) { var item = document.createElement('li'), - link = document.createElement('a') + link = document.createElement('a'), + name = data.assets[i].name - link.textContent = data.assets[i].name + ' (' + (data.assets[i].size / 1024 / 1024).toFixed(1) + 'M)' + try { + name = names[name.match(/[0-9]+\.[0-9]+\.[0-9]+\-([^\.]+)/)[1]] + } catch(e) { + console.log(e) + } + + link.innerHTML = ' ' + name + ' (' + (data.assets[i].size / 1024 / 1024).toFixed(0) + 'M)' link.href = data.assets[i].browser_download_url item.appendChild(link) @@ -67,6 +82,16 @@ html { margin-left: .8rem; margin-right: .6rem; } +li { + list-style: none; +} +li i { + margin-right: 10px +} +.download-size { + color: var(--md-typeset-color); + opacity: 0.5; +}
From b56d05713d4c489458d9c44d89fb5dcd2920d564 Mon Sep 17 00:00:00 2001 From: bordun Date: Sat, 1 May 2021 17:08:32 +0200 Subject: [PATCH 2/3] docs: VAR{}, getVar, setVar --- .../docs/docs/widgets/advanced-syntaxes.md | 6 +++++- resources/docs/docs/widgets/scripting.md | 17 +++++++++++++++++ src/client/widgets/scripts/script-vm.js | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/resources/docs/docs/widgets/advanced-syntaxes.md b/resources/docs/docs/widgets/advanced-syntaxes.md index 22f5123f..82229fd3 100644 --- a/resources/docs/docs/widgets/advanced-syntaxes.md +++ b/resources/docs/docs/widgets/advanced-syntaxes.md @@ -56,10 +56,14 @@ Options can contain `@{}` blocks. }} ``` +## Custom variables: `VAR{variableName, default}` + +This syntax creates a custom variable in the widget that can be read and modified from any widget's `script` property (see [scripting](./scripting.md#getvarid-name)). Changes made to this variable will be applied automatically. + ## Javascript: `JS{{ }}` -This syntax allows writing formulas in [Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript). The code will be compiled as a function and executed in a restricted context. +This syntax allows defining a property using [Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript). The code will be compiled as a function and executed in a restricted context. - if no `return` statement is found, the formula will return an empty string - javascript [strict mode](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Strict_mode) is always enabled diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index de7cdc73..dd2be5eb 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -109,6 +109,23 @@ If the event that triggered the script's execution was initiated by a user inter ---- +#### `getVar(id, name)` +- `id`: widget `id` as a string. +- `name`: variable name as a string. + +Returns the value of a widget's custom variable. + +---- + +#### `setVar(id, name, value)` +- `id`: widget `id` as a string. Can be `"this"` to target the host widget, or `"parent"` to target the parent widget. `id` may contains wildcards ('\*'). +- `name`: variable name as a string. +- `value`: new value for the variable. + +Sets the value of a widget's custom variable. If `ìd` contains wildcards, affects all matching widgets. + +---- + #### `send(target, address, ...args)` - `target` (optional): `"ip:port"` or `"midi:device_name"` string. If omitted, the widget's target will be used. - `address`: osc address, must start with a `/` diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index e57ad13c..62430e69 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -384,7 +384,7 @@ class ScriptVm extends Vm { for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage', 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus', 'setScroll', 'getScroll', 'toolbar', - 'openUrl']) { + 'openUrl', 'getVar', 'setVar']) { this.sanitize(this.sandbox.contentWindow[imports]) } From 9605cdc978755b209ba79356c5d1a83ffc3fa4e7 Mon Sep 17 00:00:00 2001 From: bordun Date: Sat, 1 May 2021 17:12:15 +0200 Subject: [PATCH 3/3] log: custom variables --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dbc6b54..5ac7336d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ - bug fixes - prevent error with empty `OSC{}` blocks +- advanced syntaxes + - new syntax for using custom variables in properties: `VAR{name, default}` + +- scripting + - add `getVar()` and `setVar` for reading and modifying custom variables. This allows modifying properties directly from scripts. + ## 1.9.3 - bug fixes