File tree 4 files changed +108
-29
lines changed 4 files changed +108
-29
lines changed Original file line number Diff line number Diff line change 18
18
-->
19
19
20
20
< html lang ="en ">
21
+
21
22
< head >
22
23
< meta charset ="UTF-8 ">
23
24
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
26
27
< style >
27
28
body {
28
29
color : # 2c353a ;
29
- font-family : Lucida Grande, Lucida, Verdana, sans-serif;
30
+ font-family : Lucida Grande, Lucida, Verdana, sans-serif;
30
31
padding : 15px ;
31
32
}
32
33
33
- # error , .not-found , .closed , .error {
34
+ # error ,
35
+ .not-found ,
36
+ .closed ,
37
+ .error {
34
38
color : red
35
39
}
36
40
37
- .found , .open , .success {
41
+ .found ,
42
+ .open ,
43
+ .success {
38
44
color : green;
39
45
}
40
46
53
59
.section {
54
60
margin : 20px ;
55
61
}
62
+
63
+ table {
64
+ border-collapse : collapse;
65
+ }
66
+
67
+ table td {
68
+ border : 1px solid black;
69
+ padding : 3px ;
70
+ }
56
71
</ style >
57
72
</ head >
73
+
58
74
< body >
59
75
< div id ="root "> </ div >
60
76
</ body >
61
- </ html >
77
+
78
+ </ html >
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
3
3
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
+ } ;
9
9
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
+ }
17
11
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
+ }
30
53
}
31
54
32
55
export default V2 ;
Original file line number Diff line number Diff line change @@ -22,10 +22,11 @@ import io from 'socket.io-client';
22
22
import semVerCompare from 'semver-compare' ;
23
23
import { detect } from 'detect-browser' ;
24
24
25
- import { timer } from 'rxjs' ;
25
+ import { timer , BehaviorSubject } from 'rxjs' ;
26
26
import { filter , takeUntil , first } from 'rxjs/operators' ;
27
27
28
28
import Daemon from './daemon' ;
29
+ import V2 from './v2' ;
29
30
30
31
// Required agent version
31
32
const browser = detect ( ) ;
@@ -62,10 +63,14 @@ export default class SocketDaemon extends Daemon {
62
63
63
64
this . openChannel ( ( ) => this . socket . emit ( 'command' , 'list' ) ) ;
64
65
66
+ this . agentV2Found = new BehaviorSubject ( null ) ;
67
+
65
68
this . agentFound
66
69
. subscribe ( agentFound => {
67
70
if ( agentFound ) {
68
71
this . _wsConnect ( ) ;
72
+ this . v2 = new V2 ( this . pluginURL ) ;
73
+ this . agentV2Found . next ( this . v2 ) ;
69
74
}
70
75
else {
71
76
this . findAgent ( ) ;
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments