@@ -8,7 +8,7 @@ import { OutputStreamHandler } from 'services/platform-apps/api/modules/native-c
88import crypto from 'crypto' ;
99import { importExtractZip } from 'util/slow-imports' ;
1010import { pipeline } from 'stream/promises' ;
11- import { HostsService , SourcesService , UserService } from 'app-services' ;
11+ import { HostsService , SourcesService , SettingsService , UserService } from 'app-services' ;
1212import { RealmObject } from 'services/realm' ;
1313import { ObjectSchema } from 'realm' ;
1414import http from 'http' ;
@@ -34,6 +34,7 @@ export class VisionState extends RealmObject {
3434 isRunning : boolean ;
3535 pid : number ;
3636 port : number ;
37+ needsUpdate : boolean ;
3738
3839 static schema : ObjectSchema = {
3940 name : 'VisionState' ,
@@ -44,7 +45,8 @@ export class VisionState extends RealmObject {
4445 isRunning : { type : 'bool' , default : false } ,
4546 isInstalling : { type : 'bool' , default : false } ,
4647 pid : { type : 'int' , default : 0 } ,
47- port : { type : 'int' , default : 0 }
48+ port : { type : 'int' , default : 0 } ,
49+ needsUpdate : { type : 'bool' , default : false } ,
4850 } ,
4951 } ;
5052}
@@ -64,6 +66,7 @@ export class VisionService extends Service {
6466 @Inject ( ) userService : UserService ;
6567 @Inject ( ) hostsService : HostsService ;
6668 @Inject ( ) private sourcesService : SourcesService ;
69+ @Inject ( ) settingsService : SettingsService ;
6770
6871 state = VisionState . inject ( ) ;
6972
@@ -104,25 +107,46 @@ export class VisionService extends Service {
104107 }
105108
106109 /**
107- * Ensures the following:
108- * - vision is downloaded and up to date
109- * - vision is running and sending events
110- * - we are subscribed to events
110+ * Will pop up a dialog if vision is not installed
111+ * or requires an update.
111112 */
112113 async ensureVision ( ) {
114+ if ( this . proc && this . proc . exitCode != null ) return ;
115+
113116 const needsUpdate = await this . isNewVersionAvailable ( ) ;
114117
118+ this . state . db . write ( ( ) => {
119+ this . state . needsUpdate = needsUpdate ;
120+ } ) ;
121+
115122 if ( needsUpdate ) {
116- await this . update ( progress => {
117- this . state . db . write ( ( ) => {
118- this . state . percentDownloaded = progress . percent ;
119- } ) ;
123+ this . settingsService . showSettings ( 'Vision' ) ;
124+ } else {
125+ await this . startVision ( ) ;
126+ }
127+ }
128+
129+ async installOrUpdate ( ) {
130+ if ( this . state . isCurrentlyUpdating ) return ;
131+
132+ await this . update ( progress => {
133+ this . state . db . write ( ( ) => {
134+ this . state . percentDownloaded = progress . percent ;
120135 } ) ;
136+ } ) ;
121137
122- await this . loadCurrentManifest ( ) ;
123- }
138+ await this . loadCurrentManifest ( ) ;
139+
140+ this . state . db . write ( ( ) => {
141+ this . state . needsUpdate = false ;
142+ this . state . percentDownloaded = 0 ;
143+ } ) ;
124144
125- if ( this . proc && this . proc . killed ) {
145+ await this . startVision ( ) ;
146+ }
147+
148+ async startVision ( ) {
149+ if ( this . proc && this . proc . exitCode != null ) {
126150 this . proc = null ;
127151 }
128152
@@ -435,6 +459,9 @@ export class VisionService extends Service {
435459 this . eventSource . onmessage = e => {
436460 console . log ( 'GOT EVENT' , e . data ) ;
437461
462+ // Filter out game process detection events
463+ if ( e . data [ 'events' ] . find ( ( e : any ) => e . name === 'game_process_detected' ) ) return ;
464+
438465 const headers = authorizedHeaders (
439466 this . userService . apiToken ,
440467 new Headers ( { 'Content-Type' : 'application/json' } ) ,
0 commit comments