From 29daf787fc4428ecbd70c3e5bacb0d40324b6817 Mon Sep 17 00:00:00 2001 From: bordun Date: Wed, 1 Jul 2020 09:27:28 +0200 Subject: [PATCH 1/6] editor: avoid breaking address=auto when pasting with id+1 --- src/client/editor/data-workers.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/client/editor/data-workers.js b/src/client/editor/data-workers.js index bae0ac81..d3a4eb47 100644 --- a/src/client/editor/data-workers.js +++ b/src/client/editor/data-workers.js @@ -171,11 +171,12 @@ var incrementWidget = function(data, root){ var id = data.id, address = data.address - if (id && address == '/'+id) { + if (id && address == '/' + id) { data.address = 'auto' - } else if (address){ + } else if (address !== 'auto') { + var addressref while (fakeStore.address.indexOf(address) != -1 || widgetManager.getWidgetByAddress(addressref).length) { address = address.replace(/([0-9]*)$/,function(m){ From 669b8cfd1af3f0bb6274af18dcd60b43c7d5b95b Mon Sep 17 00:00:00 2001 From: bordun Date: Wed, 1 Jul 2020 16:01:16 +0200 Subject: [PATCH 2/6] inspector: prevent edit errors from breaking sessions; add a notification; reverse the faulty change and prevent history push; --- src/client/editor/index.js | 35 ++++++++++++++++++++++++++++++++--- src/client/locales/en.js | 1 + src/client/locales/fr.js | 1 + 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/client/editor/index.js b/src/client/editor/index.js index c7312191..2f310d0d 100644 --- a/src/client/editor/index.js +++ b/src/client/editor/index.js @@ -9,6 +9,8 @@ var {updateWidget, incrementWidget} = require('./data-workers'), UiInspector = require('../ui/ui-inspector'), UiTree = require('../ui/ui-tree'), UiDragResize = require('../ui/ui-dragresize'), + notifications = require('../ui/notifications'), + locales = require('../locales'), {leftUiSidePanel, rightUiSidePanel} = require('../ui/'), ipc = require('../ipc'), sessionManager @@ -27,17 +29,44 @@ class Editor { this.inspector.on('update', (event)=>{ var {propName, value} = event, - newWidgets = [] + newWidgets = [], + error = false for (var w of this.selectedWidgets) { - if ((propName === 'label' || propName === 'popupLabel') && value === true) { + + let previousValue = w.props[propName] + + if ((propName === '' || propName === 'popupLabel') && value === true) { w.props[propName] = 'auto' } else { w.props[propName] = value !== '' ? value : deepCopy(defaults[w.props.type][propName].value) } - newWidgets.push(updateWidget(w, {changedProps: [propName], preventSelect: this.selectedWidgets.length > 1})) + + try { + + newWidgets.push(updateWidget(w, {changedProps: [propName], preventSelect: this.selectedWidgets.length > 1})) + + } catch (e) { + + w.props[propName] = previousValue + updateWidget(w, {changedProps: [propName], preventSelect: this.selectedWidgets.length > 1}) + + notifications.add({ + class: 'error', + message: locales('inspector_error'), + duration: 7000 + }) + console.error( + `Error while setting ${propName} to: ${JSON.stringify(value)}.`, + 'It\'s probably a bug, please a new bug ticket with these informations (https://github.com/jean-emmanuel/open-stage-control/issues).' + ) + console.error(e) + error = true + } } + if (error) return + this.pushHistory() if (newWidgets.length > 1) this.select(newWidgets) diff --git a/src/client/locales/en.js b/src/client/locales/en.js index 59173b52..877c930a 100644 --- a/src/client/locales/en.js +++ b/src/client/locales/en.js @@ -40,6 +40,7 @@ module.exports = { // inspector inspector_color_confirm: 'Confirm', inspector_color_apply: 'Apply', + inspector_error: 'An error just occured, open F12 to read more.', // nosleep nosleep: 'Prevent sleep', diff --git a/src/client/locales/fr.js b/src/client/locales/fr.js index a3385c08..40e089b5 100644 --- a/src/client/locales/fr.js +++ b/src/client/locales/fr.js @@ -40,6 +40,7 @@ module.exports = { // inspector inspector_color_confirm: 'Confirmer', inspector_color_apply: 'Appliquer', + inspector_error: 'Une erreur vient de survenir, appuyez sur F12 pour en savoir plus.', // nosleep nosleep: 'EmpĂȘcher la veille', From 330649e4d0b353f8e34658ec4982bb65186c75ca Mon Sep 17 00:00:00 2001 From: bordun Date: Wed, 1 Jul 2020 16:03:18 +0200 Subject: [PATCH 3/6] linkId: ensure it's a string --- src/client/managers/widgets.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/client/managers/widgets.js b/src/client/managers/widgets.js index b42d9684..940b8f92 100644 --- a/src/client/managers/widgets.js +++ b/src/client/managers/widgets.js @@ -41,7 +41,7 @@ class WidgetManager extends EventEmitter { if (linkId) { if (!Array.isArray(linkId)) linkId = [linkId] - linkId = linkId.map(x=>x.replace(/^>>\s*/, '')).filter(x=>x.indexOf('<<') < 0) + linkId = linkId.map(x=>String(x).replace(/^>>\s*/, '')).filter(x=>x.indexOf('<<') < 0) linkId = linkId.filter(x=>this.linkIdLock.indexOf(x)<0) this.linkIdLock = this.linkIdLock.concat(linkId) this.linkIdLockDepth++ @@ -118,7 +118,7 @@ class WidgetManager extends EventEmitter { if (linkId) { if (!Array.isArray(linkId)) linkId = [linkId] - linkId = linkId.map(x=>x.replace(/^<<\s*/, '')).filter(x=>x.indexOf('>>') < 0) + linkId = linkId.map(x=>String(x).replace(/^<<\s*/, '')).filter(x=>x.indexOf('>>') < 0) for (var i in linkId) { if (linkId[i]) { if (!this.linkIdRoute[linkId[i]]) this.linkIdRoute[linkId[i]] = [] @@ -185,6 +185,7 @@ class WidgetManager extends EventEmitter { if (scroll && this.scrollingWidgets.indexOf(hash) != -1) this.scrollingWidgets.splice(this.scrollingWidgets.indexOf(hash), 1) if (!Array.isArray(linkId)) linkId = [linkId] + linkId = linkId.map(x=>String(x)) for (var i in linkId) { if (linkId[i] && this.linkIdRoute[linkId[i]] && this.linkIdRoute[linkId[i]].indexOf(hash) != -1) this.linkIdRoute[linkId[i]].splice(this.linkIdRoute[linkId[i]].indexOf(hash), 1) } From c40a6157a21791a099cf68e654b9076afa5263a0 Mon Sep 17 00:00:00 2001 From: bordun Date: Thu, 2 Jul 2020 12:17:40 +0200 Subject: [PATCH 4/6] script: add getScroll and setScroll --- src/client/widgets/containers/panel.js | 4 ++-- src/client/widgets/scripts/script-vm.js | 28 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/client/widgets/containers/panel.js b/src/client/widgets/containers/panel.js index 550c5ebe..3bb648bf 100644 --- a/src/client/widgets/containers/panel.js +++ b/src/client/widgets/containers/panel.js @@ -223,8 +223,8 @@ class Panel extends Container() { if (!s) { return [this.widget.scrollLeft, this.widget.scrollTop] } else { - this.widget.scrollLeft = s[0] - this.widget.scrollTop = s[1] + if (s[0] !== undefined) this.widget.scrollLeft = s[0] + if (s[1] !== undefined) this.widget.scrollTop = s[1] } } diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index 6ce35d48..2d4b36af 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -147,6 +147,32 @@ class ScriptVm extends Vm { } + this.sandbox.contentWindow.getScroll = (id)=>{ + + var widgets = this.resolveId(id) + + for (var i = widgets.length - 1; i >= 0; i--) { + + if (widgets[i].scroll) return widgets[i].scroll() + + } + + return [] + + } + + this.sandbox.contentWindow.setScroll = (id, x, y)=>{ + + var widgets = this.resolveId(id) + + for (var i = widgets.length - 1; i >= 0; i--) { + + if (widgets[i].scroll) widgets[i].scroll([x, y]) + + } + + } + this.sandbox.contentWindow.httpGet = (url, callback)=>{ var parser = urlParser(url), @@ -286,7 +312,7 @@ class ScriptVm extends Vm { } for (var imports of ['set', 'get', 'getProp', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage', - 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'unfocus']) { + 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'unfocus', 'setScroll', 'getScroll']) { this.sanitize(this.sandbox.contentWindow[imports]) } From 234b81c7d88ec4bffbabb7e5db534133537ead18 Mon Sep 17 00:00:00 2001 From: bordun Date: Thu, 2 Jul 2020 12:29:46 +0200 Subject: [PATCH 5/6] docs: scripting set/getScroll --- resources/docs/docs/widgets/scripting.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index f75de7ab..f3da412d 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -6,7 +6,7 @@ The `script` property allows widgets to run javascript code when their value upd - `@{}`, `OSC{}`, `JS{{}}` and `#{}` blocks are replaced with their value before the script's compilation !!! warning "Avoid advanced syntax in scripts" - To avoid syntax errors it is recommended to use `getProp()` and `get()` instead of `@{}` and `OSC{}`. `JS{{}}` and `#{}` blocks should be avoided here as well. + To avoid syntax errors it is recommended to use `getProp()` and `get()` instead of `@{}` and `OSC{}`. `JS{{}}` and `#{}` blocks should be avoided here as well. ## Event-dependent variables @@ -134,3 +134,17 @@ Reference: *Built-in client only*: tells the operating system to give the focus to the window that was focused before. ---- + +#### `getScroll`: `function(id)` +- `id`: widget `id` as a string. + +Returns the scroll state of a container as a `[x, y]` array. + +---- + +#### `setScroll`: `function(id, x, y)` +- `id`: widget `id` as a string. Can be `"this"` to target the host widget, or `"parent"` to target the parent widget. +- `x`: horizontal scroll, `undefined` to use current value +- `y`: vertical scroll, `undefined` to use current value + +Sets the scroll state of a container. From 17fb29c44afa26ce4992d9aa5757444f27845c6f Mon Sep 17 00:00:00 2001 From: bordun Date: Fri, 3 Jul 2020 16:04:18 +0200 Subject: [PATCH 6/6] docs: add terminal launch example --- .../docs/docs/getting-started/server-configuration.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/resources/docs/docs/getting-started/server-configuration.md b/resources/docs/docs/getting-started/server-configuration.md index 209994f7..033e49ed 100644 --- a/resources/docs/docs/getting-started/server-configuration.md +++ b/resources/docs/docs/getting-started/server-configuration.md @@ -160,6 +160,13 @@ The **server** can be configured with many options, either from a terminal or wi Options name must be prepended with a double dash (`--`) in a terminal. +!!! example "Example" + ``` + open-stage-control --no-gui --load path/to/your/session.json --theme path/to/your/theme.css + ``` + + Launches the server in headless mode, and makes all clients load provided session and theme automatically. + ## Running in a terminal on Windows