未验证 提交 bfe8ff1d 编写于 作者: J Johannes Rieken 提交者: GitHub

Merge pull request #53226 from Microsoft/joh/isLatest

IUpdateService#isLatestVersion
......@@ -89,4 +89,6 @@ export interface IUpdateService {
downloadUpdate(): TPromise<void>;
applyUpdate(): TPromise<void>;
quitAndInstall(): TPromise<void>;
}
\ No newline at end of file
isLatestVersion(): TPromise<boolean | undefined>;
}
......@@ -17,6 +17,7 @@ export interface IUpdateChannel extends IChannel {
call(command: 'applyUpdate'): TPromise<void>;
call(command: 'quitAndInstall'): TPromise<void>;
call(command: '_getInitialState'): TPromise<State>;
call(command: 'isLatestVersion'): TPromise<boolean>;
call(command: string, arg?: any): TPromise<any>;
}
......@@ -32,6 +33,7 @@ export class UpdateChannel implements IUpdateChannel {
case 'applyUpdate': return this.service.applyUpdate();
case 'quitAndInstall': return this.service.quitAndInstall();
case '_getInitialState': return TPromise.as(this.service.state);
case 'isLatestVersion': return this.service.isLatestVersion();
}
return undefined;
}
......@@ -77,4 +79,8 @@ export class UpdateChannelClient implements IUpdateService {
quitAndInstall(): TPromise<void> {
return this.channel.call('quitAndInstall');
}
}
\ No newline at end of file
isLatestVersion(): TPromise<boolean> {
return this.channel.call('isLatestVersion');
}
}
......@@ -14,6 +14,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { IUpdateService, State, StateType, AvailableForDownload } from 'vs/platform/update/common/update';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
import { IRequestService } from 'vs/platform/request/node/request';
export function createUpdateURL(platform: string, quality: string): string {
return `${product.updateUrl}/api/update/${platform}/${quality}/${product.commit}`;
......@@ -23,6 +24,8 @@ export abstract class AbstractUpdateService implements IUpdateService {
_serviceBrand: any;
protected readonly url: string | undefined;
private _state: State = State.Uninitialized;
private throttler: Throttler = new Throttler();
......@@ -43,7 +46,8 @@ export abstract class AbstractUpdateService implements IUpdateService {
@ILifecycleService private lifecycleService: ILifecycleService,
@IConfigurationService protected configurationService: IConfigurationService,
@IEnvironmentService private environmentService: IEnvironmentService,
@ILogService protected logService: ILogService
@IRequestService protected requestService: IRequestService,
@ILogService protected logService: ILogService,
) {
if (this.environmentService.disableUpdates) {
this.logService.info('update#ctor - updates are disabled');
......@@ -62,7 +66,8 @@ export abstract class AbstractUpdateService implements IUpdateService {
return;
}
if (!this.setUpdateFeedUrl(quality)) {
this.url = this.buildUpdateFeedUrl(quality);
if (!this.url) {
this.logService.info('update#ctor - updates are disabled');
return;
}
......@@ -153,10 +158,25 @@ export abstract class AbstractUpdateService implements IUpdateService {
return TPromise.as(null);
}
isLatestVersion(): TPromise<boolean | undefined> {
if (!this.url) {
return TPromise.as(undefined);
}
return this.requestService.request({ url: this.url }).then(context => {
// The update server replies with 204 (No Content) when no
// update is available - that's all we want to know.
if (context.res.statusCode === 204) {
return true;
} else {
return false;
}
});
}
protected doQuitAndInstall(): void {
// noop
}
protected abstract setUpdateFeedUrl(quality: string): boolean;
protected abstract buildUpdateFeedUrl(quality: string): string | undefined;
protected abstract doCheckForUpdates(context: any): void;
}
......@@ -16,6 +16,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
import { AbstractUpdateService, createUpdateURL } from 'vs/platform/update/electron-main/abstractUpdateService';
import { IRequestService } from 'vs/platform/request/node/request';
export class DarwinUpdateService extends AbstractUpdateService {
......@@ -33,9 +34,10 @@ export class DarwinUpdateService extends AbstractUpdateService {
@IConfigurationService configurationService: IConfigurationService,
@ITelemetryService private telemetryService: ITelemetryService,
@IEnvironmentService environmentService: IEnvironmentService,
@IRequestService requestService: IRequestService,
@ILogService logService: ILogService
) {
super(lifecycleService, configurationService, environmentService, logService);
super(lifecycleService, configurationService, environmentService, requestService, logService);
this.onRawError(this.onError, this, this.disposables);
this.onRawUpdateAvailable(this.onUpdateAvailable, this, this.disposables);
this.onRawUpdateDownloaded(this.onUpdateDownloaded, this, this.disposables);
......@@ -47,16 +49,16 @@ export class DarwinUpdateService extends AbstractUpdateService {
this.setState(State.Idle);
}
protected setUpdateFeedUrl(quality: string): boolean {
protected buildUpdateFeedUrl(quality: string): string | undefined {
const url = createUpdateURL('darwin', quality);
try {
electron.autoUpdater.setFeedURL(createUpdateURL('darwin', quality));
electron.autoUpdater.setFeedURL(url);
} catch (e) {
// application is very likely not signed
this.logService.error('Failed to set update feed URL', e);
return false;
return undefined;
}
return true;
return url;
}
protected doCheckForUpdates(context: any): void {
......
......@@ -22,22 +22,19 @@ export class LinuxUpdateService extends AbstractUpdateService {
_serviceBrand: any;
private url: string | undefined;
constructor(
@ILifecycleService lifecycleService: ILifecycleService,
@IConfigurationService configurationService: IConfigurationService,
@ITelemetryService private telemetryService: ITelemetryService,
@IEnvironmentService environmentService: IEnvironmentService,
@IRequestService private requestService: IRequestService,
@IRequestService requestService: IRequestService,
@ILogService logService: ILogService
) {
super(lifecycleService, configurationService, environmentService, logService);
super(lifecycleService, configurationService, environmentService, requestService, logService);
}
protected setUpdateFeedUrl(quality: string): boolean {
this.url = createUpdateURL(`linux-${process.arch}`, quality);
return true;
protected buildUpdateFeedUrl(quality: string): string {
return createUpdateURL(`linux-${process.arch}`, quality);
}
protected doCheckForUpdates(context: any): void {
......
......@@ -47,7 +47,6 @@ export class Win32UpdateService extends AbstractUpdateService {
_serviceBrand: any;
private url: string | undefined;
private availableUpdate: IAvailableUpdate | undefined;
@memoize
......@@ -61,15 +60,15 @@ export class Win32UpdateService extends AbstractUpdateService {
@IConfigurationService configurationService: IConfigurationService,
@ITelemetryService private telemetryService: ITelemetryService,
@IEnvironmentService environmentService: IEnvironmentService,
@IRequestService private requestService: IRequestService,
@IRequestService requestService: IRequestService,
@ILogService logService: ILogService
) {
super(lifecycleService, configurationService, environmentService, logService);
super(lifecycleService, configurationService, environmentService, requestService, logService);
}
protected setUpdateFeedUrl(quality: string): boolean {
protected buildUpdateFeedUrl(quality: string): string | undefined {
if (!fs.existsSync(path.join(path.dirname(process.execPath), 'unins000.exe'))) {
return false;
return undefined;
}
let platform = 'win32';
......@@ -82,8 +81,7 @@ export class Win32UpdateService extends AbstractUpdateService {
platform += '-user';
}
this.url = createUpdateURL(platform, quality);
return true;
return createUpdateURL(platform, quality);
}
protected doCheckForUpdates(context: any): void {
......
......@@ -21,6 +21,7 @@ import { isCodeEditor } from 'vs/editor/browser/editorBrowser';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import { ILogService } from 'vs/platform/log/common/log';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IUpdateService } from 'vs/platform/update/common/update';
class StartupTimings implements IWorkbenchContribution {
......@@ -34,6 +35,7 @@ class StartupTimings implements IWorkbenchContribution {
@ITelemetryService private readonly _telemetryService: ITelemetryService,
@ILifecycleService private readonly _lifecycleService: ILifecycleService,
@IExtensionService private readonly _extensionService: IExtensionService,
@IUpdateService private readonly _updateService: IUpdateService,
) {
this._reportVariedStartupTimes().then(undefined, onUnexpectedError);
......@@ -87,7 +89,10 @@ class StartupTimings implements IWorkbenchContribution {
this._logService.info('no standard startup: not using cached data');
return;
}
if (!await this._updateService.isLatestVersion()) {
this._logService.info('no standard startup: not running latest version');
return;
}
// wait only know so that can check the restored state as soon as possible
await TPromise.join([
this._extensionService.whenInstalledExtensionsRegistered(),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册