From 8f30a60c2ed0a0c29f36b1e4a2bafa9134b0d923 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Mon, 26 Jul 2021 15:00:35 +0000 Subject: [PATCH] Add handling for "camera actions" 3rd checkbox state --- api.cpp | 15 ++++++++++++++- ui/widget.js | 15 ++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/api.cpp b/api.cpp index 506029d..1aad780 100644 --- a/api.cpp +++ b/api.cpp @@ -86,6 +86,9 @@ class Context { if (event_type == GP_EVENT_TIMEOUT) { break; } + if (event_type == GP_EVENT_UNKNOWN) { + EM_ASM({ console.log(UTF8ToString($0)); }, event_data.get()); + } had_events = true; } return had_events; @@ -240,7 +243,17 @@ class Context { } case GP_WIDGET_TOGGLE: { result.set("type", "toggle"); - result.set("value", GPP_CALL(int, gp_widget_get_value(widget, _)) != 0); + int value = GPP_CALL(int, gp_widget_get_value(widget, _)); + // Note: explicitly not adding `value` for any other values + // (e.g. camera actions often would return 2 here...) + switch (value) { + case 0: + result.set("value", false); + break; + case 1: + result.set("value", true); + break; + } break; } diff --git a/ui/widget.js b/ui/widget.js index c454c26..e50d6a1 100644 --- a/ui/widget.js +++ b/ui/widget.js @@ -27,12 +27,17 @@ export class Widget extends Component { if (this.state.inProgress && nextState.inProgress) { return false; } + if (this.state.inProgress || nextState.inProgress) { + return true; + } + let prevConfig = this.props.config; + let { config } = nextProps; + if (config.type === 'toggle' && config.value === undefined) { + return false; + } return ( - this.state.inProgress || - nextState.inProgress || - getValueForComparison(this.props.config) !== - getValueForComparison(nextProps.config) || - this.props.config.readonly !== nextProps.config.readonly + getValueForComparison(config) !== getValueForComparison(prevConfig) || + config.readonly !== prevConfig.readonly ); }