Skip to content

Commit 8ffb0d4

Browse files
authored
Improve Web Serial API support (#558)
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 * Added file name to the uploading process. The file name is used in log messages
1 parent 6ee305c commit 8ffb0d4

File tree

5 files changed

+51
-38
lines changed

5 files changed

+51
-38
lines changed

CHANGELOG.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [2.10.0] - 2022-09-08
4+
## [2.11.0] - 2022-09-27
5+
The main goal of this release is to improve support for the Web Serial API on ChromeOS.
6+
Other platforms should not be affected.
7+
8+
### Changed
9+
- When using Web Serial API, the interactions between the client library
10+
(as an example, the Arduino `arduino-chromeos-uploader` libray) has been simplified.
11+
- A new parameter `dialogCustomizations` has been added to the upload functionality. It's used
12+
to provide custom confirmation dialogs when using the Web Serial API.
13+
It has no effect with other daemons.
14+
15+
### Removed
16+
- `cdcReset` functionality, now it's embedded in the `upload` functionality
17+
in the Web Serial daemon.
18+
### Changed
19+
20+
## [2.10.1] - 2022-09-08
521

622
### Changed
723
- 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.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arduino-create-agent-js-client",
3-
"version": "2.10.1",
3+
"version": "2.11.0-beta.1",
44
"description": "JS module providing discovery of the Arduino Create Plugin and communication with it",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/chrome-app-daemon.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export default class ChromeAppDaemon extends Daemon {
237237
*/
238238
_upload(uploadPayload, uploadCommandInfo) {
239239
const {
240-
board, port, commandline, data
240+
board, port, commandline, data, filename
241241
} = uploadPayload;
242242
const extrafiles = uploadCommandInfo && uploadCommandInfo.files && Array.isArray(uploadCommandInfo.files) ? uploadCommandInfo.files : [];
243243
try {
@@ -250,6 +250,7 @@ export default class ChromeAppDaemon extends Daemon {
250250
commandline,
251251
data,
252252
token: token.token,
253+
filename,
253254
extrafiles
254255
}
255256
});

src/daemon.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,12 @@ export default class Daemon {
115115
* @param {string} sketchName
116116
* @param {Object} compilationResult
117117
* @param {boolean} verbose
118+
* @param {any[]} dialogCustomizations Optional - Used in Web Serial API to customize the permission dialogs.
119+
* It's an array because the Web Serial API library can use more than one dialog, e.g. one to
120+
* ask permission and one to give instruction to save an UF2 file.
121+
* It's called 'customizations' because the library already provides a basic non-styled dialog.
118122
*/
119-
uploadSerial(target, sketchName, compilationResult, verbose = true) {
123+
uploadSerial(target, sketchName, compilationResult, verbose = true, dialogCustomizations) {
120124
this.uploadingPort = target.port;
121125
this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'Upload started' });
122126
this.serialDevicesBeforeUpload = this.devicesList.getValue().serial;
@@ -142,7 +146,8 @@ export default class Daemon {
142146
commandline: uploadCommandInfo.commandline,
143147
filename: `${sketchName}.${ext}`,
144148
hex: data, // For desktop agent
145-
data // For chromeOS plugin, consider to align this
149+
data, // For chromeOS plugin, consider to align this
150+
dialogCustomizations // used only in Web Serial API uploader
146151
};
147152

148153
this.uploadingDone.subscribe(() => {

src/web-serial-daemon.js

+24-33
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,6 @@ export default class WebSerialDaemon extends Daemon {
6868
}
6969

7070
connectToChannel() {
71-
this.channel.onMessage(message => {
72-
if (message.version) {
73-
this.agentInfo = message.version;
74-
this.agentFound.next(true);
75-
this.channelOpen.next(true);
76-
}
77-
else {
78-
this.appMessages.next(message);
79-
}
80-
});
81-
this.channel.onDisconnect(() => {
82-
this.channelOpen.next(false);
83-
this.agentFound.next(false);
84-
});
85-
}
86-
87-
_appConnect() {
8871
this.channel.onMessage(message => {
8972
if (message.version) {
9073
this.agentInfo = {
@@ -190,6 +173,21 @@ export default class WebSerialDaemon extends Daemon {
190173
}
191174
}
192175

176+
/**
177+
* Send the 'writePort' message to the serial port
178+
* @param {string} port the port name
179+
* @param {string} message the text to be sent to serial
180+
*/
181+
writeSerial(port, message) {
182+
this.channel.postMessage({
183+
command: 'writePort',
184+
data: {
185+
name: port,
186+
data: message
187+
}
188+
});
189+
}
190+
193191
/**
194192
* Request serial port open
195193
* @param {string} port the port name
@@ -247,23 +245,12 @@ export default class WebSerialDaemon extends Daemon {
247245
});
248246
}
249247

250-
cdcReset({ fqbn, port }) {
251-
this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'CDC reset started' });
252-
this.channel.postMessage({
253-
command: 'cdcReset',
254-
data: {
255-
fqbn,
256-
port
257-
}
258-
});
259-
}
260-
261-
connectToSerialDevice({ fqbn }) {
262-
this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'Board selection started' });
248+
connectToSerialDevice({ from, dialogCustomization }) {
263249
this.channel.postMessage({
264250
command: 'connectToSerial',
265251
data: {
266-
fqbn
252+
from,
253+
dialogCustomization
267254
}
268255
});
269256
}
@@ -274,9 +261,11 @@ export default class WebSerialDaemon extends Daemon {
274261
*/
275262
_upload(uploadPayload, uploadCommandInfo) {
276263
const {
277-
board, port, commandline, data, pid, vid
264+
board, port, commandline, data, pid, vid, filename, dialogCustomizations
278265
} = uploadPayload;
266+
279267
const extrafiles = uploadCommandInfo && uploadCommandInfo.files && Array.isArray(uploadCommandInfo.files) ? uploadCommandInfo.files : [];
268+
280269
try {
281270
window.oauth.getAccessToken().then(token => {
282271
this.channel.postMessage({
@@ -289,7 +278,9 @@ export default class WebSerialDaemon extends Daemon {
289278
token: token.token,
290279
extrafiles,
291280
pid,
292-
vid
281+
vid,
282+
filename,
283+
dialogCustomizations
293284
}
294285
});
295286
});

0 commit comments

Comments
 (0)