33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { Event , Emitter } from 'vs/base/common/event' ;
6+ import { Event , Emitter , fromNodeEventEmitter , filterEvent , debounceEvent } from 'vs/base/common/event' ;
77import { Throttler , timeout } from 'vs/base/common/async' ;
8- import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
98import { ILifecycleService } from 'vs/platform/lifecycle/electron-main/lifecycleMain' ;
109import product from 'vs/platform/node/product' ;
1110import { TPromise } from 'vs/base/common/winjs.base' ;
1211import { IUpdateService , State , StateType , AvailableForDownload , UpdateType } from 'vs/platform/update/common/update' ;
1312import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
1413import { ILogService } from 'vs/platform/log/common/log' ;
15- import { IRequestService } from 'vs/platform/request/node/request' ;
1614import * as path from 'path' ;
17- import { realpath } from 'fs' ;
15+ import { realpath , watch } from 'fs' ;
1816import { spawn } from 'child_process' ;
1917import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
2018
@@ -40,24 +38,10 @@ abstract class AbstractUpdateService2 implements IUpdateService {
4038
4139 constructor (
4240 @ILifecycleService private lifecycleService : ILifecycleService ,
43- @IConfigurationService protected configurationService : IConfigurationService ,
44- @IEnvironmentService private environmentService : IEnvironmentService ,
45- @IRequestService protected requestService : IRequestService ,
41+ @IEnvironmentService environmentService : IEnvironmentService ,
4642 @ILogService protected logService : ILogService ,
4743 ) {
48- if ( this . environmentService . disableUpdates ) {
49- this . logService . info ( 'update#ctor - updates are disabled' ) ;
50- return ;
51- }
52-
53- if ( ! product . updateUrl || ! product . commit ) {
54- this . logService . info ( 'update#ctor - updates are disabled' ) ;
55- return ;
56- }
57-
58- const quality = this . getProductQuality ( ) ;
59-
60- if ( ! quality ) {
44+ if ( environmentService . disableUpdates ) {
6145 this . logService . info ( 'update#ctor - updates are disabled' ) ;
6246 return ;
6347 }
@@ -68,11 +52,6 @@ abstract class AbstractUpdateService2 implements IUpdateService {
6852 this . scheduleCheckForUpdates ( 30 * 1000 ) . then ( undefined , err => this . logService . error ( err ) ) ;
6953 }
7054
71- private getProductQuality ( ) : string | undefined {
72- const quality = this . configurationService . getValue < string > ( 'update.channel' ) ;
73- return quality === 'none' ? undefined : product . quality ;
74- }
75-
7655 private scheduleCheckForUpdates ( delay = 60 * 60 * 1000 ) : Thenable < void > {
7756 return timeout ( delay )
7857 . then ( ( ) => this . checkForUpdates ( null ) )
@@ -161,30 +140,39 @@ export class SnapUpdateService extends AbstractUpdateService2 {
161140
162141 constructor (
163142 @ILifecycleService lifecycleService : ILifecycleService ,
164- @IConfigurationService configurationService : IConfigurationService ,
165143 @IEnvironmentService environmentService : IEnvironmentService ,
166- @IRequestService requestService : IRequestService ,
167144 @ILogService logService : ILogService ,
168145 @ITelemetryService private telemetryService : ITelemetryService
169146 ) {
170- super ( lifecycleService , configurationService , environmentService , requestService , logService ) ;
147+ super ( lifecycleService , environmentService , logService ) ;
148+
149+ const watcher = watch ( path . dirname ( process . env . SNAP ) ) ;
150+ const onChange = fromNodeEventEmitter ( watcher , 'change' , ( _ , fileName : string ) => fileName ) ;
151+ const onCurrentChange = filterEvent ( onChange , n => n === 'current' ) ;
152+ const onDebouncedCurrentChange = debounceEvent ( onCurrentChange , ( _ , e ) => e , 2000 ) ;
153+ const listener = onDebouncedCurrentChange ( this . checkForUpdates , this ) ;
154+
155+ lifecycleService . onShutdown ( ( ) => {
156+ listener . dispose ( ) ;
157+ watcher . close ( ) ;
158+ } ) ;
171159 }
172160
173161 protected doCheckForUpdates ( context : any ) : void {
174162 this . setState ( State . CheckingForUpdates ( context ) ) ;
175163
176- this . isLatestVersion ( ) . then ( result => {
177- if ( ! result ) {
164+ this . isUpdateAvailable ( ) . then ( result => {
165+ if ( result ) {
166+ this . setState ( State . Ready ( { version : 'something' , productVersion : 'someting' } ) ) ;
167+ } else {
178168 /* __GDPR__
179- "update:notAvailable" : {
180- "explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
181- }
182- */
169+ "update:notAvailable" : {
170+ "explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
171+ }
172+ */
183173 this . telemetryService . publicLog ( 'update:notAvailable' , { explicit : ! ! context } ) ;
184174
185175 this . setState ( State . Idle ( UpdateType . Snap ) ) ;
186- } else {
187- this . setState ( State . Ready ( { version : 'something' , productVersion : 'someting' } ) ) ;
188176 }
189177 } , err => {
190178 this . logService . error ( err ) ;
@@ -209,17 +197,21 @@ export class SnapUpdateService extends AbstractUpdateService2 {
209197 } ) ;
210198 }
211199
212- isLatestVersion ( ) : TPromise < boolean | undefined > {
213- return new TPromise ( c => {
200+ private isUpdateAvailable ( ) : TPromise < boolean > {
201+ return new TPromise ( ( c , e ) => {
214202 realpath ( `/snap/${ product . applicationName } /current` , ( err , resolvedCurrentSnapPath ) => {
215- if ( err ) {
216- this . logService . error ( 'update#checkForSnapUpdate(): Could not get realpath of application.' ) ;
217- return c ( undefined ) ;
218- }
203+ if ( err ) { return e ( err ) ; }
219204
220205 const currentRevision = path . basename ( resolvedCurrentSnapPath ) ;
221- return process . env . SNAP_REVISION === currentRevision ;
206+ c ( process . env . SNAP_REVISION !== currentRevision ) ;
222207 } ) ;
223208 } ) ;
224209 }
210+
211+ isLatestVersion ( ) : TPromise < boolean | undefined > {
212+ return this . isUpdateAvailable ( ) . then ( null , err => {
213+ this . logService . error ( 'update#checkForSnapUpdate(): Could not get realpath of application.' ) ;
214+ return undefined ;
215+ } ) ;
216+ }
225217}
0 commit comments