Skip to content

Commit 561fa81

Browse files
committed
Working with double permissoin, SAMD flasher only
1 parent dac4bb1 commit 561fa81

File tree

9 files changed

+465
-54
lines changed

9 files changed

+465
-54
lines changed

demo/app.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020

2121
import React from 'react';
22-
import Daemon from '../src';
22+
import Daemon, { isChromeOs } from '../src';
2323
import FirmwareUpdater from '../src/firmware-updater';
2424

2525
import { HEX } from './serial_mirror';
@@ -151,6 +151,17 @@ class App extends React.Component {
151151
}
152152
}
153153

154+
requestDevicePermission = async () => {
155+
if ('serial' in navigator) {
156+
const port = await navigator.serial.requestPort([{ usbVendorId: 0x2341 }]);
157+
daemon.devicesList.next({
158+
serial: [port],
159+
network: []
160+
});
161+
162+
}
163+
};
164+
154165
showError(err) {
155166
this.setState({ error: err });
156167
scrollToBottom(document.body);
@@ -275,8 +286,10 @@ class App extends React.Component {
275286
</div>
276287

277288
<div className="section">
278-
<h2>Connected Devices</h2>
279-
289+
<div>
290+
<h2 style={{ display: 'inline-block', marginRight: 10 } }>Connected Devices </h2>
291+
{ isChromeOs() && <button type="button" onClick={() => this.requestDevicePermission()}>Request access to serial port</button> }
292+
</div>
280293
<strong>serial:</strong>
281294
<ul>
282295
{ listSerialDevices }

demo/v2/install_tool.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ export class V2InstallTool extends React.Component {
2121
componentDidMount() {
2222
this.daemon = this.props.daemon;
2323

24-
this.daemon.agentV2Found.subscribe(daemonV2 => {
25-
if (!daemonV2) {
26-
return;
27-
}
28-
this.daemonV2 = daemonV2;
29-
});
24+
if (this.daemon.agentV2Found) { // agentV2Found not available for instance on chromebooks
25+
this.daemon.agentV2Found.subscribe(daemonV2 => {
26+
if (!daemonV2) {
27+
return;
28+
}
29+
this.daemonV2 = daemonV2;
30+
});
31+
}
3032
}
3133

3234
handleChange(event) {

demo/v2/v2.jsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ class V2 extends React.Component {
1212
componentDidMount() {
1313
this.daemon = this.props.daemon;
1414

15-
this.daemon.agentV2Found.subscribe(daemonV2 => {
16-
if (!daemonV2) {
17-
return;
18-
}
19-
this.daemonV2 = daemonV2;
20-
this.daemonV2.installedTools().then(res => {
21-
this.setState({
22-
tools: res
15+
if (this.daemon.agentV2Found) { // agentV2Found not available for instance on chromebooks
16+
this.daemon.agentV2Found.subscribe(daemonV2 => {
17+
if (!daemonV2) {
18+
return;
19+
}
20+
this.daemonV2 = daemonV2;
21+
this.daemonV2.installedTools().then(res => {
22+
this.setState({
23+
tools: res
24+
});
2325
});
2426
});
25-
});
27+
}
2628
}
2729

2830
render() {

src/chrome-app-daemon.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,18 @@ const POLLING_INTERVAL = 2000;
4040
// onDisconnect (message) {}
4141
// onSerialData (name, data) {}
4242
// }
43-
export default class ChromeOsDaemon extends Daemon {
44-
constructor(boardsUrl, options) { // , chromeExtensionId) {
43+
export default class ChromeAppDaemon extends Daemon {
44+
constructor(boardsUrl, chromeExtensionId) {
4545
super(boardsUrl);
46-
if (typeof options === 'string') {
47-
this.chromeExtensionId = options;
48-
}
49-
else {
50-
this.chromeExtensionId = options.chromeExtensionId;
51-
}
52-
this.webSerialChannel = null;
46+
this.chromeExtensionId = chromeExtensionId;
5347
this.channel = null;
48+
this.init();
49+
}
5450

51+
init() {
5552
this.openChannel(() => this.channel.postMessage({
5653
command: 'listPorts'
5754
}));
58-
5955
this.agentFound
6056
.pipe(distinctUntilChanged())
6157
.subscribe(agentFound => {
@@ -69,9 +65,7 @@ export default class ChromeOsDaemon extends Daemon {
6965
interval(POLLING_INTERVAL)
7066
.pipe(startWith(0))
7167
.pipe(takeUntil(this.channelOpen.pipe(filter(status => status))))
72-
.subscribe(() => {
73-
this._appConnect();
74-
});
68+
.subscribe(() => this._appConnect());
7569
}
7670

7771
/**

0 commit comments

Comments
 (0)