Skip to content

Commit d804213

Browse files
committed
Added support for Web Serial API on Chromebooks
1 parent 877a32a commit d804213

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"lib": "lib"
1616
},
1717
"dependencies": {
18-
"@bcmi-labs/arduino-chromeos-uploader": "file:../arduino-chromeos-uploader",
18+
"@bcmi-labs/arduino-chromeos-uploader": "git://github.com/bcmi-labs/arduino-chromeos-uploader#csarnataro/iot-1597-main-refactoring",
1919
"detect-browser": "^4.8.0",
2020
"rxjs": "^6.5.3",
2121
"semver-compare": "^1.0.0",
@@ -84,7 +84,8 @@
8484
"Stefania Mellai <[email protected]>",
8585
"Fabrizio Mirabito <[email protected]>",
8686
"Alberto Iannaccone <[email protected]>",
87-
"Gabriele Destefanis <[email protected]>"
87+
"Gabriele Destefanis <[email protected]>",
88+
"Christian Sarnataro <[email protected]>"
8889
],
8990
"license": "GPLv3",
9091
"bugs": {

src/chrome-os-daemon.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,23 @@ import ChromeAppDaemon from './chrome-app-daemon';
3030
*/
3131
export default function ChromeOsDaemon(boardsUrl, options) {
3232

33-
// const { cacheStorageKey } = options;
34-
if (false) { // typeof options === 'string') {
35-
console.dir('******** BEGIN: chrome-os-daemon:40 ********');
36-
console.dir('CREATING CHROME APP', { depth: null, colors: true });
37-
console.dir('******** END: chrome-os-daemon:40 ********');
38-
// chrome app
39-
this.flavour = new ChromeAppDaemon(boardsUrl, options);
33+
let useWebSerial = null;
34+
let chromeExtensionId;
35+
36+
// check chromeExtensionId OR web serial API
37+
if (typeof options === 'string') {
38+
chromeExtensionId = options;
4039
}
4140
else {
42-
console.dir('******** BEGIN: chrome-os-daemon:47 ********');
43-
console.dir('CREATING WEB SERIAL', { depth: null, colors: true });
44-
console.dir('******** END: chrome-os-daemon:47 ********');
45-
// const { cacheStorageKey } = options;
41+
useWebSerial = options.useWebSerial;
42+
chromeExtensionId = options.chromeExtensionId;
43+
}
44+
if (useWebSerial === 'true' && 'serial' in navigator) {
4645
this.flavour = new WebSerialDaemon(boardsUrl);
4746
}
47+
else {
48+
this.flavour = new ChromeAppDaemon(boardsUrl, chromeExtensionId);
49+
}
4850

4951
const handler = {
5052
get: (_, name) => this.flavour[name],
@@ -58,4 +60,3 @@ export default function ChromeOsDaemon(boardsUrl, options) {
5860
return new Proxy(this, handler);
5961

6062
}
61-

src/web-serial-daemon.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ export default class WebSerialDaemon extends Daemon {
130130
this.uploading.next({ status: this.UPLOAD_DONE, msg: 'Sketch uploaded' });
131131
}
132132
catch (error) {
133-
console.error(error);
134133
this.notifyUploadError(error.message);
135134
}
136135
}

0 commit comments

Comments
 (0)