From 61f1668d3f6e262276392e97227a89d5a3b7d6cb Mon Sep 17 00:00:00 2001 From: Roo Machell Date: Tue, 28 Jun 2022 18:35:32 +0100 Subject: [PATCH] feat: add Toggle to Enable or Disable Connection action (#65) --- index.js | 17 +++++++++++++++-- package.json | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 4f98ace..e2e40a5 100644 --- a/index.js +++ b/index.js @@ -386,7 +386,11 @@ instance.prototype.init_actions = function (system) { label: 'Enable', id: 'enable', default: 'true', - choices: self.CHOICES_YESNO_BOOLEAN, + choices: [ + { id: 'toggle', label: 'Toggle' }, + { id: 'true', label: 'Yes' }, + { id: 'false', label: 'No' }, + ], }, ], }, @@ -1207,7 +1211,16 @@ instance.prototype.action = function (action, extras) { self.system.emit('variable_get', id[0], id[1], (v) => (value = v)) self.system.emit('custom_variable_set_value', opt.name, value) } else if (id == 'instance_control') { - self.system.emit('instance_enable', opt.instance_id, opt.enable == 'true') + let newState = opt.enable == 'true' + if (opt.enable == 'toggle') { + let curState = false // no status entry if instance is disabled on startup + if (self.instance_status.hasOwnProperty(opt.instance_id)) { + curState = self.instance_status[opt.instance_id][0] == -1 + } + + newState = !curState + } + self.system.emit('instance_enable', opt.instance_id, newState) } else if (id == 'set_page') { self.changeControllerPage(theController, thePage) } else if (id == 'set_brightness') { diff --git a/package.json b/package.json index c6fdb6f..fdb0c6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bitfocus-companion", - "version": "1.9.1", + "version": "1.9.2", "api_version": "1.0.0", "description": "Internal functions", "keywords": [],