From 4ab43e0743441b2017c24a6935db6110bbf6913b Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Thu, 4 Aug 2022 10:11:06 +0300 Subject: [PATCH] feat: add serial port config params --- .../serial-port-config.html | 67 +++++++++++++++++++ .../serial-port-config/serial-port-config.js | 24 +++++++ .../serial-signer/serial-signer.html | 38 +++++++---- .../components/serial-signer/serial-signer.js | 26 ++++++- .../extensions/watchonly/static/js/index.js | 3 + .../watchonly/templates/watchonly/index.html | 1 + 6 files changed, 144 insertions(+), 15 deletions(-) create mode 100644 lnbits/extensions/watchonly/static/components/serial-port-config/serial-port-config.html create mode 100644 lnbits/extensions/watchonly/static/components/serial-port-config/serial-port-config.js diff --git a/lnbits/extensions/watchonly/static/components/serial-port-config/serial-port-config.html b/lnbits/extensions/watchonly/static/components/serial-port-config/serial-port-config.html new file mode 100644 index 000000000..392ace177 --- /dev/null +++ b/lnbits/extensions/watchonly/static/components/serial-port-config/serial-port-config.html @@ -0,0 +1,67 @@ +
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+
diff --git a/lnbits/extensions/watchonly/static/components/serial-port-config/serial-port-config.js b/lnbits/extensions/watchonly/static/components/serial-port-config/serial-port-config.js new file mode 100644 index 000000000..8c1554356 --- /dev/null +++ b/lnbits/extensions/watchonly/static/components/serial-port-config/serial-port-config.js @@ -0,0 +1,24 @@ +async function serialPortConfig(path) { + const t = await loadTemplateAsync(path) + Vue.component('serial-port-config', { + name: 'serial-port-config', + template: t, + data() { + return { + config: { + baudRate: 9600, + bufferSize: 255, + dataBits: 8, + flowControl: 'none', + parity: 'none', + stopBits: 1 + } + } + }, + methods: { + getConfig: function () { + return this.config + } + } + }) +} diff --git a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.html b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.html index 7ae2bb8ec..b9605b97e 100644 --- a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.html +++ b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.html @@ -5,18 +5,9 @@ color="primary" icon="usb" :text-color="selectedPort ? hww.authenticated ? 'green' : 'orange' : 'white'" - @click="openSerialPort" + @click="openSerialPortDialog" > - - - Configure - Set the Serial Port communication parameters - - - Connect - Connect Serial Port device. + Set the Serial Port communication parameters. + + + + + Enter Config + + + +
+ Connect + Cancel +
+
+
+
+ diff --git a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js index 92cfce886..c6102bef9 100644 --- a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js +++ b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js @@ -22,6 +22,7 @@ async function serialSigner(path) { showMnemonic: false, authenticated: false, showPasswordDialog: false, + showConfigDialog: false, showWipeDialog: false, showRestoreDialog: false, showConfirmationDialog: false, @@ -48,9 +49,19 @@ async function serialSigner(path) { satBtc(val, showUnit = true) { return satOrBtc(val, showUnit, this.satsDenominated) }, - openSerialPort: async function () { + openSerialPortDialog: async function () { + await this.openSerialPort() + }, + openSerialPort: async function (config = {baudRate: 9600}) { if (!this.checkSerialPortSupported()) return false - if (this.selectedPort) return true + if (this.selectedPort) { + this.$q.notify({ + type: 'warning', + message: 'Already connected. Disconnect first!', + timeout: 10000 + }) + return true + } try { navigator.serial.addEventListener('connect', event => { @@ -68,7 +79,7 @@ async function serialSigner(path) { }) this.selectedPort = await navigator.serial.requestPort() // Wait for the serial port to open. - await this.selectedPort.open({baudRate: 9600}) + await this.selectedPort.open(config) this.startSerialPortReading() const textEncoder = new TextEncoderStream() @@ -89,6 +100,9 @@ async function serialSigner(path) { return false } }, + openSerialPortConfig: async function () { + this.hww.showConfigDialog = true + }, closeSerialPort: async function () { try { if (this.writer) this.writer.close() @@ -275,6 +289,12 @@ async function serialSigner(path) { }) } }, + hwwConfigAndConnect: async function () { + this.hww.showConfigDialog = false + const config = this.$refs.serialPortConfig.getConfig() + await this.openSerialPort(config) + return true + }, hwwLogin: async function () { try { await this.writer.write( diff --git a/lnbits/extensions/watchonly/static/js/index.js b/lnbits/extensions/watchonly/static/js/index.js index e21c91afb..68204aca4 100644 --- a/lnbits/extensions/watchonly/static/js/index.js +++ b/lnbits/extensions/watchonly/static/js/index.js @@ -10,6 +10,9 @@ const watchOnly = async () => { await sendTo('static/components/send-to/send-to.html') await payment('static/components/payment/payment.html') await serialSigner('static/components/serial-signer/serial-signer.html') + await serialPortConfig( + 'static/components/serial-port-config/serial-port-config.html' + ) Vue.filter('reverse', function (value) { // slice to make a copy of array, then reverse the copy diff --git a/lnbits/extensions/watchonly/templates/watchonly/index.html b/lnbits/extensions/watchonly/templates/watchonly/index.html index fd9bf4043..7b0d519d9 100644 --- a/lnbits/extensions/watchonly/templates/watchonly/index.html +++ b/lnbits/extensions/watchonly/templates/watchonly/index.html @@ -235,5 +235,6 @@ + {% endblock %}