From f0da56120002eed60d2ef81af67543a55f78f9d9 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 28 Aug 2024 15:10:51 -0500 Subject: [PATCH 1/2] save callback on this, and await folder functions --- js/workflows/usb.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/js/workflows/usb.js b/js/workflows/usb.js index e150a76..1c1b1ec 100644 --- a/js/workflows/usb.js +++ b/js/workflows/usb.js @@ -163,11 +163,18 @@ class USBWorkflow extends Workflow { btnRequestSerialDevice.removeEventListener('click', serialConnect); btnRequestSerialDevice.addEventListener('click', serialConnect); - btnSelectHostFolder.removeEventListener('click', this._selectHostFolder); - btnSelectHostFolder.addEventListener('click', this._selectHostFolder); + btnSelectHostFolder.removeEventListener('click', this.btnSelectHostFolderCallback) + this.btnSelectHostFolderCallback = async (event) => { + await this._selectHostFolder(); + }; + btnSelectHostFolder.addEventListener('click', this.btnSelectHostFolderCallback); + - btnUseHostFolder.removeEventListener('click', this._useHostFolder); - btnUseHostFolder.addEventListener('click', this._useHostFolder); + btnUseHostFolder.removeEventListener('click', this.btnUseHostFolderCallback); + this.btnUseHostFolderCallback = async (event) => { + await this._useHostFolder(); + } + btnUseHostFolder.addEventListener('click', this.btnUseHostFolderCallback); // Check if WebSerial is available if (!(await this.available() instanceof Error)) { From 66f50e5ca2c8e30e12378bbb0d7231bb9b48c6fe Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 28 Aug 2024 16:41:29 -0500 Subject: [PATCH 2/2] make fields private and add to constructor --- js/workflows/usb.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/js/workflows/usb.js b/js/workflows/usb.js index 1c1b1ec..de14ae4 100644 --- a/js/workflows/usb.js +++ b/js/workflows/usb.js @@ -21,6 +21,9 @@ class USBWorkflow extends Workflow { this._partialToken = null; this._uid = null; this._readLoopPromise = null; + this._btnSelectHostFolderCallback = null; + this._btnUseHostFolderCallback = null; + } async init(params) { @@ -163,18 +166,18 @@ class USBWorkflow extends Workflow { btnRequestSerialDevice.removeEventListener('click', serialConnect); btnRequestSerialDevice.addEventListener('click', serialConnect); - btnSelectHostFolder.removeEventListener('click', this.btnSelectHostFolderCallback) - this.btnSelectHostFolderCallback = async (event) => { + btnSelectHostFolder.removeEventListener('click', this._btnSelectHostFolderCallback) + this._btnSelectHostFolderCallback = async (event) => { await this._selectHostFolder(); }; - btnSelectHostFolder.addEventListener('click', this.btnSelectHostFolderCallback); + btnSelectHostFolder.addEventListener('click', this._btnSelectHostFolderCallback); - btnUseHostFolder.removeEventListener('click', this.btnUseHostFolderCallback); - this.btnUseHostFolderCallback = async (event) => { + btnUseHostFolder.removeEventListener('click', this._btnUseHostFolderCallback); + this._btnUseHostFolderCallback = async (event) => { await this._useHostFolder(); } - btnUseHostFolder.addEventListener('click', this.btnUseHostFolderCallback); + btnUseHostFolder.addEventListener('click', this._btnUseHostFolderCallback); // Check if WebSerial is available if (!(await this.available() instanceof Error)) {