File tree 1 file changed +23
-4
lines changed
1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change 18
18
*
19
19
*/
20
20
21
- import { takeUntil , filter } from 'rxjs/operators' ;
21
+ import { interval } from 'rxjs' ;
22
+ import { filter , startWith , takeUntil } from 'rxjs/operators' ;
22
23
23
24
import Daemon from './daemon' ;
24
25
26
+ const POLLING_INTERVAL = 2000 ;
27
+
25
28
export default class ChromeOsDaemon extends Daemon {
26
29
constructor ( chromeExtensionId ) {
27
30
super ( ) ;
@@ -31,15 +34,31 @@ export default class ChromeOsDaemon extends Daemon {
31
34
command : 'listPorts'
32
35
} ) ) ;
33
36
34
- this . _appConnect ( chromeExtensionId ) ;
37
+ this . chromeExtensionId = chromeExtensionId ;
38
+
39
+ this . agentFound
40
+ . subscribe ( agentFound => {
41
+ if ( ! agentFound ) {
42
+ this . findApp ( ) ;
43
+ }
44
+ } ) ;
45
+ }
46
+
47
+ findApp ( ) {
48
+ interval ( POLLING_INTERVAL )
49
+ . pipe ( startWith ( 0 ) )
50
+ . pipe ( takeUntil ( this . channelOpen . pipe ( filter ( status => status ) ) ) )
51
+ . subscribe ( ( ) => {
52
+ this . _appConnect ( ) ;
53
+ } ) ;
35
54
}
36
55
37
56
/**
38
57
* Instantiate connection and events listeners for chrome app
39
58
*/
40
- _appConnect ( chromeExtensionId ) {
59
+ _appConnect ( ) {
41
60
if ( chrome . runtime ) {
42
- this . channel = chrome . runtime . connect ( chromeExtensionId ) ;
61
+ this . channel = chrome . runtime . connect ( this . chromeExtensionId ) ;
43
62
this . channel . onMessage . addListener ( message => {
44
63
if ( message . version ) {
45
64
this . agentInfo = message ;
You can’t perform that action at this time.
0 commit comments