Skip to content

Commit f08b6d6

Browse files
committed
add IUpdateService#isLatestVersion
1 parent 405f8be commit f08b6d6

6 files changed

Lines changed: 50 additions & 25 deletions

File tree

src/vs/platform/update/common/update.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,6 @@ export interface IUpdateService {
8989
downloadUpdate(): TPromise<void>;
9090
applyUpdate(): TPromise<void>;
9191
quitAndInstall(): TPromise<void>;
92-
}
92+
93+
isLatestVersion(): TPromise<boolean | undefined>;
94+
}

src/vs/platform/update/common/updateIpc.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface IUpdateChannel extends IChannel {
1717
call(command: 'applyUpdate'): TPromise<void>;
1818
call(command: 'quitAndInstall'): TPromise<void>;
1919
call(command: '_getInitialState'): TPromise<State>;
20+
call(command: 'isLatestVersion'): TPromise<boolean>;
2021
call(command: string, arg?: any): TPromise<any>;
2122
}
2223

@@ -32,6 +33,7 @@ export class UpdateChannel implements IUpdateChannel {
3233
case 'applyUpdate': return this.service.applyUpdate();
3334
case 'quitAndInstall': return this.service.quitAndInstall();
3435
case '_getInitialState': return TPromise.as(this.service.state);
36+
case 'isLatestVersion': return this.service.isLatestVersion();
3537
}
3638
return undefined;
3739
}
@@ -77,4 +79,8 @@ export class UpdateChannelClient implements IUpdateService {
7779
quitAndInstall(): TPromise<void> {
7880
return this.channel.call('quitAndInstall');
7981
}
80-
}
82+
83+
isLatestVersion(): TPromise<boolean> {
84+
return this.channel.call('isLatestVersion');
85+
}
86+
}

src/vs/platform/update/electron-main/abstractUpdateService.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
1414
import { IUpdateService, State, StateType, AvailableForDownload } from 'vs/platform/update/common/update';
1515
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1616
import { ILogService } from 'vs/platform/log/common/log';
17+
import { IRequestService } from 'vs/platform/request/node/request';
1718

1819
export function createUpdateURL(platform: string, quality: string): string {
1920
return `${product.updateUrl}/api/update/${platform}/${quality}/${product.commit}`;
@@ -23,6 +24,8 @@ export abstract class AbstractUpdateService implements IUpdateService {
2324

2425
_serviceBrand: any;
2526

27+
protected readonly url: string | undefined;
28+
2629
private _state: State = State.Uninitialized;
2730
private throttler: Throttler = new Throttler();
2831

@@ -43,7 +46,8 @@ export abstract class AbstractUpdateService implements IUpdateService {
4346
@ILifecycleService private lifecycleService: ILifecycleService,
4447
@IConfigurationService protected configurationService: IConfigurationService,
4548
@IEnvironmentService private environmentService: IEnvironmentService,
46-
@ILogService protected logService: ILogService
49+
@IRequestService protected requestService: IRequestService,
50+
@ILogService protected logService: ILogService,
4751
) {
4852
if (this.environmentService.disableUpdates) {
4953
this.logService.info('update#ctor - updates are disabled');
@@ -62,7 +66,8 @@ export abstract class AbstractUpdateService implements IUpdateService {
6266
return;
6367
}
6468

65-
if (!this.setUpdateFeedUrl(quality)) {
69+
this.url = this.buildUpdateFeedUrl(quality);
70+
if (!this.url) {
6671
this.logService.info('update#ctor - updates are disabled');
6772
return;
6873
}
@@ -153,10 +158,25 @@ export abstract class AbstractUpdateService implements IUpdateService {
153158
return TPromise.as(null);
154159
}
155160

161+
isLatestVersion(): TPromise<boolean | undefined> {
162+
if (!this.url) {
163+
return TPromise.as(undefined);
164+
}
165+
return this.requestService.request({ url: this.url }).then(context => {
166+
// The update server replies with 204 (No Content) when no
167+
// update is available - that's all we want to know.
168+
if (context.res.statusCode === 204) {
169+
return true;
170+
} else {
171+
return false;
172+
}
173+
});
174+
}
175+
156176
protected doQuitAndInstall(): void {
157177
// noop
158178
}
159179

160-
protected abstract setUpdateFeedUrl(quality: string): boolean;
180+
protected abstract buildUpdateFeedUrl(quality: string): string;
161181
protected abstract doCheckForUpdates(context: any): void;
162182
}

src/vs/platform/update/electron-main/updateService.darwin.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1616
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1717
import { ILogService } from 'vs/platform/log/common/log';
1818
import { AbstractUpdateService, createUpdateURL } from 'vs/platform/update/electron-main/abstractUpdateService';
19+
import { IRequestService } from 'vs/platform/request/node/request';
1920

2021
export class DarwinUpdateService extends AbstractUpdateService {
2122

@@ -33,9 +34,10 @@ export class DarwinUpdateService extends AbstractUpdateService {
3334
@IConfigurationService configurationService: IConfigurationService,
3435
@ITelemetryService private telemetryService: ITelemetryService,
3536
@IEnvironmentService environmentService: IEnvironmentService,
37+
@IRequestService requestService: IRequestService,
3638
@ILogService logService: ILogService
3739
) {
38-
super(lifecycleService, configurationService, environmentService, logService);
40+
super(lifecycleService, configurationService, environmentService, requestService, logService);
3941
this.onRawError(this.onError, this, this.disposables);
4042
this.onRawUpdateAvailable(this.onUpdateAvailable, this, this.disposables);
4143
this.onRawUpdateDownloaded(this.onUpdateDownloaded, this, this.disposables);
@@ -47,16 +49,16 @@ export class DarwinUpdateService extends AbstractUpdateService {
4749
this.setState(State.Idle);
4850
}
4951

50-
protected setUpdateFeedUrl(quality: string): boolean {
52+
protected buildUpdateFeedUrl(quality: string): string | undefined {
53+
const url = createUpdateURL('darwin', quality);
5154
try {
52-
electron.autoUpdater.setFeedURL(createUpdateURL('darwin', quality));
55+
electron.autoUpdater.setFeedURL(url);
5356
} catch (e) {
5457
// application is very likely not signed
5558
this.logService.error('Failed to set update feed URL', e);
56-
return false;
59+
return undefined;
5760
}
58-
59-
return true;
61+
return url;
6062
}
6163

6264
protected doCheckForUpdates(context: any): void {

src/vs/platform/update/electron-main/updateService.linux.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,19 @@ export class LinuxUpdateService extends AbstractUpdateService {
2222

2323
_serviceBrand: any;
2424

25-
private url: string | undefined;
26-
2725
constructor(
2826
@ILifecycleService lifecycleService: ILifecycleService,
2927
@IConfigurationService configurationService: IConfigurationService,
3028
@ITelemetryService private telemetryService: ITelemetryService,
3129
@IEnvironmentService environmentService: IEnvironmentService,
32-
@IRequestService private requestService: IRequestService,
30+
@IRequestService requestService: IRequestService,
3331
@ILogService logService: ILogService
3432
) {
35-
super(lifecycleService, configurationService, environmentService, logService);
33+
super(lifecycleService, configurationService, environmentService, requestService, logService);
3634
}
3735

38-
protected setUpdateFeedUrl(quality: string): boolean {
39-
this.url = createUpdateURL(`linux-${process.arch}`, quality);
40-
return true;
36+
protected buildUpdateFeedUrl(quality: string): string {
37+
return createUpdateURL(`linux-${process.arch}`, quality);
4138
}
4239

4340
protected doCheckForUpdates(context: any): void {

src/vs/platform/update/electron-main/updateService.win32.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export class Win32UpdateService extends AbstractUpdateService {
4747

4848
_serviceBrand: any;
4949

50-
private url: string | undefined;
5150
private availableUpdate: IAvailableUpdate | undefined;
5251

5352
@memoize
@@ -61,15 +60,15 @@ export class Win32UpdateService extends AbstractUpdateService {
6160
@IConfigurationService configurationService: IConfigurationService,
6261
@ITelemetryService private telemetryService: ITelemetryService,
6362
@IEnvironmentService environmentService: IEnvironmentService,
64-
@IRequestService private requestService: IRequestService,
63+
@IRequestService requestService: IRequestService,
6564
@ILogService logService: ILogService
6665
) {
67-
super(lifecycleService, configurationService, environmentService, logService);
66+
super(lifecycleService, configurationService, environmentService, requestService, logService);
6867
}
6968

70-
protected setUpdateFeedUrl(quality: string): boolean {
69+
protected buildUpdateFeedUrl(quality: string): string | undefined {
7170
if (!fs.existsSync(path.join(path.dirname(process.execPath), 'unins000.exe'))) {
72-
return false;
71+
return undefined;
7372
}
7473

7574
let platform = 'win32';
@@ -82,8 +81,7 @@ export class Win32UpdateService extends AbstractUpdateService {
8281
platform += '-user';
8382
}
8483

85-
this.url = createUpdateURL(platform, quality);
86-
return true;
84+
return createUpdateURL(platform, quality);
8785
}
8886

8987
protected doCheckForUpdates(context: any): void {

0 commit comments

Comments
 (0)