File tree Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change 1818*
1919*/
2020
21- import { takeUntil , filter } from 'rxjs/operators' ;
21+ import { interval } from 'rxjs' ;
22+ import { filter , startWith , takeUntil } from 'rxjs/operators' ;
2223
2324import Daemon from './daemon' ;
2425
26+ const POLLING_INTERVAL = 2000 ;
27+
2528export default class ChromeOsDaemon extends Daemon {
2629 constructor ( chromeExtensionId ) {
2730 super ( ) ;
@@ -31,15 +34,31 @@ export default class ChromeOsDaemon extends Daemon {
3134 command : 'listPorts'
3235 } ) ) ;
3336
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+ } ) ;
3554 }
3655
3756 /**
3857 * Instantiate connection and events listeners for chrome app
3958 */
40- _appConnect ( chromeExtensionId ) {
59+ _appConnect ( ) {
4160 if ( chrome . runtime ) {
42- this . channel = chrome . runtime . connect ( chromeExtensionId ) ;
61+ this . channel = chrome . runtime . connect ( this . chromeExtensionId ) ;
4362 this . channel . onMessage . addListener ( message => {
4463 if ( message . version ) {
4564 this . agentInfo = message ;
You can’t perform that action at this time.
0 commit comments