Skip to content

Commit 9bd32a2

Browse files
committed
Show installed tools table
1 parent e7dd7b6 commit 9bd32a2

File tree

4 files changed

+108
-29
lines changed

4 files changed

+108
-29
lines changed

demo/index.html

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
-->
1919

2020
<html lang="en">
21+
2122
<head>
2223
<meta charset="UTF-8">
2324
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -26,15 +27,20 @@
2627
<style>
2728
body {
2829
color: #2c353a;
29-
font-family: Lucida Grande,Lucida,Verdana,sans-serif;
30+
font-family: Lucida Grande, Lucida, Verdana, sans-serif;
3031
padding: 15px;
3132
}
3233

33-
#error, .not-found, .closed, .error {
34+
#error,
35+
.not-found,
36+
.closed,
37+
.error {
3438
color: red
3539
}
3640

37-
.found, .open, .success {
41+
.found,
42+
.open,
43+
.success {
3844
color: green;
3945
}
4046

@@ -53,9 +59,20 @@
5359
.section {
5460
margin: 20px;
5561
}
62+
63+
table {
64+
border-collapse: collapse;
65+
}
66+
67+
table td {
68+
border: 1px solid black;
69+
padding: 3px;
70+
}
5671
</style>
5772
</head>
73+
5874
<body>
5975
<div id="root"></div>
6076
</body>
61-
</html>
77+
78+
</html>

demo/v2/v2.jsx

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,55 @@
11
import React from 'react';
22

33
class V2 extends React.Component {
4-
constructor() {
5-
super();
6-
this.state = {
7-
indexes: []
8-
};
4+
constructor() {
5+
super();
6+
this.state = {
7+
tools: []
8+
};
99

10-
console.debug(this)
11-
}
12-
render() {
13-
const indexes = this.state.indexes.map((index, i) =>
14-
<li key={i}>
15-
{index}
16-
</li>);
10+
}
1711

18-
return (
19-
<section>
20-
<h2>V2</h2>
21-
<section>
22-
<h3>Indexes</h3>
23-
<ul>
24-
{ indexes }
25-
</ul>
26-
</section>
27-
</section>
28-
)
29-
}
12+
componentDidMount() {
13+
this.daemon = this.props.daemon;
14+
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
23+
});
24+
});
25+
})
26+
}
27+
28+
render() {
29+
const tools = this.state.tools.map((tool, i) =>
30+
<tr>
31+
<td>{tool.packager}</td>
32+
<td>{tool.name}</td>
33+
<td>{tool.version}</td>
34+
</tr>);
35+
36+
return (
37+
<section>
38+
<h2>V2</h2>
39+
<section>
40+
<h3>Installed tools</h3>
41+
<table>
42+
<tr>
43+
<th>Packager</th>
44+
<th>Name</th>
45+
<th>Version</th>
46+
</tr>
47+
{tools}
48+
</table>
49+
</section>
50+
</section >
51+
)
52+
}
3053
}
3154

3255
export default V2;

src/socket-daemon.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import io from 'socket.io-client';
2222
import semVerCompare from 'semver-compare';
2323
import { detect } from 'detect-browser';
2424

25-
import { timer } from 'rxjs';
25+
import { timer, BehaviorSubject } from 'rxjs';
2626
import { filter, takeUntil, first } from 'rxjs/operators';
2727

2828
import Daemon from './daemon';
29+
import V2 from './v2';
2930

3031
// Required agent version
3132
const browser = detect();
@@ -62,10 +63,14 @@ export default class SocketDaemon extends Daemon {
6263

6364
this.openChannel(() => this.socket.emit('command', 'list'));
6465

66+
this.agentV2Found = new BehaviorSubject(null);
67+
6568
this.agentFound
6669
.subscribe(agentFound => {
6770
if (agentFound) {
6871
this._wsConnect();
72+
this.v2 = new V2(this.pluginURL);
73+
this.agentV2Found.next(this.v2);
6974
}
7075
else {
7176
this.findAgent();

src/v2.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export default class SocketDaemonV2 {
2+
constructor(daemonURL) {
3+
this.daemonURL = daemonURL + '/v2/';
4+
}
5+
6+
// installedTools uses the new v2 apis to ask the daemon a list of the tools already present in the system
7+
installedTools() {
8+
return fetch(`${this.daemonURL}/pkgs/tools/installed`, {
9+
method: 'GET',
10+
}).then(res => {
11+
return res.json();
12+
})
13+
}
14+
15+
// installTool uses the new v2 apis to ask the daemon to download a specific tool on the system
16+
// The expected payload is
17+
// {
18+
// "name": "avrdude",
19+
// "version": "6.3.0-arduino9",
20+
// "packager": "arduino",
21+
// "url": "https://downloads.arduino.cc/...", // system-specific package containing the tool
22+
// "signature": "e7Gh8309...", // proof that the url comes from a trusted source
23+
// "checksum": "SHA256:90384nhfoso8..." // proof that the package wasn't tampered with
24+
// }
25+
installTool(payload) {
26+
fetch(`${this.daemonURL}/pkgs/tools/installed`, {
27+
method: 'POST',
28+
body: JSON.stringify(payload)
29+
})
30+
.catch(error => {
31+
console.error(error);
32+
});
33+
}
34+
}

0 commit comments

Comments
 (0)