From 7464b77561af6aec96cf9972b23396bc3daa4c5c Mon Sep 17 00:00:00 2001 From: Christian Sarnataro Date: Tue, 27 Sep 2022 01:26:08 +0200 Subject: [PATCH 1/7] Improved support for Web Serial API. * Now the interaction between the client library (e.g. the Arduino `arduino-chromeos-uploader` library) has been simplified. * Added a parameter to pass dialog customization to the web serial api uploader library * Removed `connectToSerialDevice` function from the Web Serial API daemon. * Added functionality to write on the serial port --- CHANGELOG.md | 16 +++++++++++++++- package.json | 2 +- src/daemon.js | 9 +++++++-- src/web-serial-daemon.js | 39 +++++++++++++++++++++++---------------- 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc4c1bf..a4a6336 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,21 @@ # Changelog All notable changes to this project will be documented in this file. -## [2.10.0] - 2022-09-08 +## [2.11.0] - 2022-09-27 + +### Changed +- When using Web Serial API, the interactions between the client library + (as an example, the Arduino `arduino-chromeos-uploader` libray) has been simplified. +- A new parameter `dialogCustomizations` has been added to the upload functionality. It's used + to provide custom confirmation dialogs when using the Web Serial API. + It has no effect with other daemons. + +### Removed +- `connectToSerialDevice` functionality, now it's embedded in the `upload` functionality + in the Web Serial daemon. +### Changed + +## [2.10.1] - 2022-09-08 ### Changed - Fixed a bug released in 2.9.1 caused by the wrong assumption that the build filename is always at the end of the command line. This fix makes the library backward compatible with older ESP boards. diff --git a/package.json b/package.json index e800e36..e4446e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "arduino-create-agent-js-client", - "version": "2.10.1", + "version": "2.11.0-alpha.2", "description": "JS module providing discovery of the Arduino Create Plugin and communication with it", "main": "lib/index.js", "module": "es/index.js", diff --git a/src/daemon.js b/src/daemon.js index 2e3d769..0474f90 100644 --- a/src/daemon.js +++ b/src/daemon.js @@ -115,8 +115,12 @@ export default class Daemon { * @param {string} sketchName * @param {Object} compilationResult * @param {boolean} verbose + * @param {any[]} dialogCustomizations Optional - Used in Web Serial API to customize the permission dialogs. + * It's an array because the Web Serial API library can use more than one dialog, e.g. one to + * ask permission and one to give instruction to save an UF2 file. + * It's called 'customizations' because the library already provides a basic non-styled dialog. */ - uploadSerial(target, sketchName, compilationResult, verbose = true) { + uploadSerial(target, sketchName, compilationResult, verbose = true, dialogCustomizations) { this.uploadingPort = target.port; this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'Upload started' }); this.serialDevicesBeforeUpload = this.devicesList.getValue().serial; @@ -142,7 +146,8 @@ export default class Daemon { commandline: uploadCommandInfo.commandline, filename: `${sketchName}.${ext}`, hex: data, // For desktop agent - data // For chromeOS plugin, consider to align this + data, // For chromeOS plugin, consider to align this + dialogCustomizations // used only in Web Serial API uploader }; this.uploadingDone.subscribe(() => { diff --git a/src/web-serial-daemon.js b/src/web-serial-daemon.js index 0fa2b8c..d44ee45 100644 --- a/src/web-serial-daemon.js +++ b/src/web-serial-daemon.js @@ -190,6 +190,21 @@ export default class WebSerialDaemon extends Daemon { } } + /** + * Send the 'writePort' message to the serial port + * @param {string} port the port name + * @param {string} message the text to be sent to serial + */ + writeSerial(port, message) { + this.channel.postMessage({ + command: 'writePort', + data: { + name: port, + data: message + } + }); + } + /** * Request serial port open * @param {string} port the port name @@ -247,23 +262,12 @@ export default class WebSerialDaemon extends Daemon { }); } - cdcReset({ fqbn, port }) { - this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'CDC reset started' }); - this.channel.postMessage({ - command: 'cdcReset', - data: { - fqbn, - port - } - }); - } - - connectToSerialDevice({ fqbn }) { - this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'Board selection started' }); + connectToSerialDevice({ from, dialogCustomization }) { this.channel.postMessage({ command: 'connectToSerial', data: { - fqbn + from, + dialogCustomization } }); } @@ -274,9 +278,11 @@ export default class WebSerialDaemon extends Daemon { */ _upload(uploadPayload, uploadCommandInfo) { const { - board, port, commandline, data, pid, vid + board, port, commandline, data, pid, vid, dialogCustomizations } = uploadPayload; + const extrafiles = uploadCommandInfo && uploadCommandInfo.files && Array.isArray(uploadCommandInfo.files) ? uploadCommandInfo.files : []; + try { window.oauth.getAccessToken().then(token => { this.channel.postMessage({ @@ -289,7 +295,8 @@ export default class WebSerialDaemon extends Daemon { token: token.token, extrafiles, pid, - vid + vid, + dialogCustomizations } }); }); From 0a6e465cb8ec85244d868731b616f95f03848f18 Mon Sep 17 00:00:00 2001 From: Christian Sarnataro Date: Mon, 10 Oct 2022 10:51:59 +0200 Subject: [PATCH 2/7] Rephrased the section in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4a6336..16d94c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ All notable changes to this project will be documented in this file. It has no effect with other daemons. ### Removed -- `connectToSerialDevice` functionality, now it's embedded in the `upload` functionality +- `cdcReset` functionality, now it's embedded in the `upload` functionality in the Web Serial daemon. ### Changed From efb68a25258351b93154ae39b5879ec27c127ed5 Mon Sep 17 00:00:00 2001 From: Christian Sarnataro Date: Mon, 28 Nov 2022 16:55:15 +0100 Subject: [PATCH 3/7] Improved support on ChromeOS Added file name to the uploading process. The file name is used in log messages --- src/chrome-app-daemon.js | 3 ++- src/web-serial-daemon.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/chrome-app-daemon.js b/src/chrome-app-daemon.js index 8ed1aff..d2f8e07 100644 --- a/src/chrome-app-daemon.js +++ b/src/chrome-app-daemon.js @@ -237,7 +237,7 @@ export default class ChromeAppDaemon extends Daemon { */ _upload(uploadPayload, uploadCommandInfo) { const { - board, port, commandline, data + board, port, commandline, data, filename } = uploadPayload; const extrafiles = uploadCommandInfo && uploadCommandInfo.files && Array.isArray(uploadCommandInfo.files) ? uploadCommandInfo.files : []; try { @@ -250,6 +250,7 @@ export default class ChromeAppDaemon extends Daemon { commandline, data, token: token.token, + filename, extrafiles } }); diff --git a/src/web-serial-daemon.js b/src/web-serial-daemon.js index d44ee45..90324f9 100644 --- a/src/web-serial-daemon.js +++ b/src/web-serial-daemon.js @@ -278,7 +278,7 @@ export default class WebSerialDaemon extends Daemon { */ _upload(uploadPayload, uploadCommandInfo) { const { - board, port, commandline, data, pid, vid, dialogCustomizations + board, port, commandline, data, pid, vid, filename, dialogCustomizations } = uploadPayload; const extrafiles = uploadCommandInfo && uploadCommandInfo.files && Array.isArray(uploadCommandInfo.files) ? uploadCommandInfo.files : []; @@ -296,6 +296,7 @@ export default class WebSerialDaemon extends Daemon { extrafiles, pid, vid, + filename, dialogCustomizations } }); From c3f7f9454e3054f263dfdb753e0886f18520580e Mon Sep 17 00:00:00 2001 From: Christian Sarnataro Date: Mon, 28 Nov 2022 17:50:04 +0100 Subject: [PATCH 4/7] Bumped version to 2.11.0-alpha.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e4446e9..25380f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "arduino-create-agent-js-client", - "version": "2.11.0-alpha.2", + "version": "2.11.0-alpha.3", "description": "JS module providing discovery of the Arduino Create Plugin and communication with it", "main": "lib/index.js", "module": "es/index.js", From 23034a08024947c61b71f16632f7e4b8f3a61734 Mon Sep 17 00:00:00 2001 From: Christian Sarnataro Date: Fri, 20 Jan 2023 09:16:28 +0100 Subject: [PATCH 5/7] [IOT-2186] Finalize PWA integration Bumped version to 2.11.0-beta.1 Removed unused code --- CHANGELOG.md | 2 ++ package.json | 2 +- src/web-serial-daemon.js | 19 ++----------------- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16d94c9..93d9807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## [2.11.0] - 2022-09-27 +The main goal of this release is to improve support for the Web Serial API on ChromeOS. +Other platforms should not be affected. ### Changed - When using Web Serial API, the interactions between the client library diff --git a/package.json b/package.json index 25380f5..6847138 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "arduino-create-agent-js-client", - "version": "2.11.0-alpha.3", + "version": "2.11.0-beta.1", "description": "JS module providing discovery of the Arduino Create Plugin and communication with it", "main": "lib/index.js", "module": "es/index.js", diff --git a/src/web-serial-daemon.js b/src/web-serial-daemon.js index 90324f9..4d68912 100644 --- a/src/web-serial-daemon.js +++ b/src/web-serial-daemon.js @@ -43,6 +43,8 @@ export default class WebSerialDaemon extends Daemon { this.channelOpenStatus.next(true); this.channel = channel; // channel is injected from the client app this.connectedPorts = []; + this.agentFound.next(true); + this.channelOpen.next(true); this.init(); } @@ -68,23 +70,6 @@ export default class WebSerialDaemon extends Daemon { } connectToChannel() { - this.channel.onMessage(message => { - if (message.version) { - this.agentInfo = message.version; - this.agentFound.next(true); - this.channelOpen.next(true); - } - else { - this.appMessages.next(message); - } - }); - this.channel.onDisconnect(() => { - this.channelOpen.next(false); - this.agentFound.next(false); - }); - } - - _appConnect() { this.channel.onMessage(message => { if (message.version) { this.agentInfo = { From 81d1d453a4895e5669be94118166258813ed1e55 Mon Sep 17 00:00:00 2001 From: Christian Sarnataro Date: Fri, 20 Jan 2023 12:05:30 +0100 Subject: [PATCH 6/7] Removed unused code --- src/web-serial-daemon.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/web-serial-daemon.js b/src/web-serial-daemon.js index 4d68912..0a8c03d 100644 --- a/src/web-serial-daemon.js +++ b/src/web-serial-daemon.js @@ -43,8 +43,6 @@ export default class WebSerialDaemon extends Daemon { this.channelOpenStatus.next(true); this.channel = channel; // channel is injected from the client app this.connectedPorts = []; - this.agentFound.next(true); - this.channelOpen.next(true); this.init(); } @@ -89,6 +87,26 @@ export default class WebSerialDaemon extends Daemon { }); } + // _appConnect() { + // this.channel.onMessage(message => { + // if (message.version) { + // this.agentInfo = { + // version: message.version, + // os: 'ChromeOS' + // }; + // this.agentFound.next(true); + // this.channelOpen.next(true); + // } + // else { + // this.appMessages.next(message); + // } + // }); + // this.channel.onDisconnect(() => { + // this.channelOpen.next(false); + // this.agentFound.next(false); + // }); + // } + handleAppMessage(message) { if (message.ports) { this.handleListMessage(message); From 3f0f20e456812bd31aeddff758d18537673ebe17 Mon Sep 17 00:00:00 2001 From: Christian Sarnataro Date: Fri, 20 Jan 2023 12:07:40 +0100 Subject: [PATCH 7/7] Removed unused code --- src/web-serial-daemon.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/web-serial-daemon.js b/src/web-serial-daemon.js index 0a8c03d..e23812e 100644 --- a/src/web-serial-daemon.js +++ b/src/web-serial-daemon.js @@ -87,26 +87,6 @@ export default class WebSerialDaemon extends Daemon { }); } - // _appConnect() { - // this.channel.onMessage(message => { - // if (message.version) { - // this.agentInfo = { - // version: message.version, - // os: 'ChromeOS' - // }; - // this.agentFound.next(true); - // this.channelOpen.next(true); - // } - // else { - // this.appMessages.next(message); - // } - // }); - // this.channel.onDisconnect(() => { - // this.channelOpen.next(false); - // this.agentFound.next(false); - // }); - // } - handleAppMessage(message) { if (message.ports) { this.handleListMessage(message);