Merge from master

This commit is contained in:
Raj Musuku
2019-02-21 17:56:04 -08:00
parent 5a146e34fa
commit 666ae11639
11482 changed files with 119352 additions and 255574 deletions

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Event, NodeEventEmitter } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { TPromise } from 'vs/base/common/winjs.base';
@@ -37,7 +35,7 @@ export interface IUpdate {
* Donwloaded: There is an update ready to be installed in the background (win32).
*/
export enum StateType {
export const enum StateType {
Uninitialized = 'uninitialized',
Idle = 'idle',
CheckingForUpdates = 'checking for updates',
@@ -48,13 +46,14 @@ export enum StateType {
Ready = 'ready',
}
export enum UpdateType {
export const enum UpdateType {
Setup,
Archive
Archive,
Snap
}
export type Uninitialized = { type: StateType.Uninitialized };
export type Idle = { type: StateType.Idle, updateType: UpdateType };
export type Idle = { type: StateType.Idle, updateType: UpdateType, error?: string };
export type CheckingForUpdates = { type: StateType.CheckingForUpdates, context: any };
export type AvailableForDownload = { type: StateType.AvailableForDownload, update: IUpdate };
export type Downloading = { type: StateType.Downloading, update: IUpdate };
@@ -66,7 +65,7 @@ export type State = Uninitialized | Idle | CheckingForUpdates | AvailableForDown
export const State = {
Uninitialized: { type: StateType.Uninitialized } as Uninitialized,
Idle: (updateType: UpdateType) => ({ type: StateType.Idle, updateType }) as Idle,
Idle: (updateType: UpdateType, error?: string) => ({ type: StateType.Idle, updateType, error }) as Idle,
CheckingForUpdates: (context: any) => ({ type: StateType.CheckingForUpdates, context } as CheckingForUpdates),
AvailableForDownload: (update: IUpdate) => ({ type: StateType.AvailableForDownload, update } as AvailableForDownload),
Downloading: (update: IUpdate) => ({ type: StateType.Downloading, update } as Downloading),

View File

@@ -3,18 +3,16 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Event, Emitter } from 'vs/base/common/event';
import { Throttler } from 'vs/base/common/async';
import { timeout } from 'vs/base/common/async';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILifecycleService } from 'vs/platform/lifecycle/electron-main/lifecycleMain';
import product from 'vs/platform/node/product';
import { TPromise } from 'vs/base/common/winjs.base';
import { IUpdateService, State, StateType, AvailableForDownload, UpdateType } 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';
import { CancellationToken } from 'vs/base/common/cancellation';
export function createUpdateURL(platform: string, quality: string): string {
return `${product.updateUrl}/api/update/${platform}/${quality}/${product.commit}`;
@@ -27,7 +25,6 @@ export abstract class AbstractUpdateService implements IUpdateService {
protected readonly url: string | undefined;
private _state: State = State.Uninitialized;
private throttler: Throttler = new Throttler();
private _onStateChange = new Emitter<State>();
get onStateChange(): Event<State> { return this._onStateChange.event; }
@@ -75,77 +72,71 @@ export abstract class AbstractUpdateService implements IUpdateService {
this.setState(State.Idle(this.getUpdateType()));
// Start checking for updates after 30 seconds
this.scheduleCheckForUpdates(30 * 1000)
.done(null, err => this.logService.error(err));
this.scheduleCheckForUpdates(30 * 1000).then(undefined, err => this.logService.error(err));
}
private getProductQuality(): string {
private getProductQuality(): string | undefined {
const quality = this.configurationService.getValue<string>('update.channel');
return quality === 'none' ? null : product.quality;
return quality === 'none' ? undefined : product.quality;
}
private scheduleCheckForUpdates(delay = 60 * 60 * 1000): TPromise<void> {
return TPromise.timeout(delay)
private scheduleCheckForUpdates(delay = 60 * 60 * 1000): Thenable<void> {
return timeout(delay)
.then(() => this.checkForUpdates(null))
.then(update => {
if (update) {
// Update found, no need to check more
return TPromise.as(null);
}
.then(() => {
// Check again after 1 hour
return this.scheduleCheckForUpdates(60 * 60 * 1000);
});
}
checkForUpdates(context: any): TPromise<void> {
async checkForUpdates(context: any): Promise<void> {
this.logService.trace('update#checkForUpdates, state = ', this.state.type);
if (this.state.type !== StateType.Idle) {
return TPromise.as(null);
return;
}
return this.throttler.queue(() => TPromise.as(this.doCheckForUpdates(context)));
this.doCheckForUpdates(context);
}
downloadUpdate(): TPromise<void> {
async downloadUpdate(): Promise<void> {
this.logService.trace('update#downloadUpdate, state = ', this.state.type);
if (this.state.type !== StateType.AvailableForDownload) {
return TPromise.as(null);
return;
}
return this.doDownloadUpdate(this.state);
await this.doDownloadUpdate(this.state);
}
protected doDownloadUpdate(state: AvailableForDownload): TPromise<void> {
return TPromise.as(null);
protected async doDownloadUpdate(state: AvailableForDownload): Promise<void> {
// noop
}
applyUpdate(): TPromise<void> {
async applyUpdate(): Promise<void> {
this.logService.trace('update#applyUpdate, state = ', this.state.type);
if (this.state.type !== StateType.Downloaded) {
return TPromise.as(null);
return;
}
return this.doApplyUpdate();
await this.doApplyUpdate();
}
protected doApplyUpdate(): TPromise<void> {
return TPromise.as(null);
protected async doApplyUpdate(): Promise<void> {
// noop
}
quitAndInstall(): TPromise<void> {
quitAndInstall(): Thenable<void> {
this.logService.trace('update#quitAndInstall, state = ', this.state.type);
if (this.state.type !== StateType.Ready) {
return TPromise.as(null);
return Promise.resolve(void 0);
}
this.logService.trace('update#quitAndInstall(): before lifecycle quit()');
this.lifecycleService.quit(true /* from update */).done(vetod => {
this.lifecycleService.quit(true /* from update */).then(vetod => {
this.logService.trace(`update#quitAndInstall(): after lifecycle quit() with veto: ${vetod}`);
if (vetod) {
return;
@@ -155,14 +146,14 @@ export abstract class AbstractUpdateService implements IUpdateService {
this.doQuitAndInstall();
});
return TPromise.as(null);
return Promise.resolve(void 0);
}
isLatestVersion(): TPromise<boolean | undefined> {
isLatestVersion(): Thenable<boolean | undefined> {
if (!this.url) {
return TPromise.as(undefined);
return Promise.resolve(undefined);
}
return this.requestService.request({ url: this.url }).then(context => {
return this.requestService.request({ url: this.url }, CancellationToken.None).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) {

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as electron from 'electron';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Event, fromNodeEventEmitter } from 'vs/base/common/event';
@@ -45,8 +43,12 @@ export class DarwinUpdateService extends AbstractUpdateService {
}
private onError(err: string): void {
this.logService.error('UpdateService error: ', err);
this.setState(State.Idle(UpdateType.Archive));
this.logService.error('UpdateService error:', err);
// only show message when explicitly checking for updates
const shouldShowMessage = this.state.type === StateType.CheckingForUpdates ? !!this.state.context : true;
const message: string | undefined = shouldShowMessage ? err : undefined;
this.setState(State.Idle(UpdateType.Archive, message));
}
protected buildUpdateFeedUrl(quality: string): string | undefined {
@@ -109,7 +111,9 @@ export class DarwinUpdateService extends AbstractUpdateService {
// we workaround this issue by forcing an explicit flush of the storage data.
// see also https://github.com/Microsoft/vscode/issues/172
this.logService.trace('update#quitAndInstall(): calling flushStorageData()');
electron.session.defaultSession.flushStorageData();
if (electron.session.defaultSession) {
electron.session.defaultSession.flushStorageData();
}
this.logService.trace('update#quitAndInstall(): running raw#quitAndInstall()');
electron.autoUpdater.quitAndInstall();

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import product from 'vs/platform/node/product';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILifecycleService } from 'vs/platform/lifecycle/electron-main/lifecycleMain';
@@ -15,8 +13,11 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { ILogService } from 'vs/platform/log/common/log';
import { createUpdateURL, AbstractUpdateService } from 'vs/platform/update/electron-main/abstractUpdateService';
import { asJson } from 'vs/base/node/request';
import { TPromise } from 'vs/base/common/winjs.base';
import { shell } from 'electron';
import { CancellationToken } from 'vs/base/common/cancellation';
import * as path from 'path';
import { spawn } from 'child_process';
import { realpath } from 'fs';
export class LinuxUpdateService extends AbstractUpdateService {
@@ -44,45 +45,89 @@ export class LinuxUpdateService extends AbstractUpdateService {
this.setState(State.CheckingForUpdates(context));
this.requestService.request({ url: this.url })
.then<IUpdate>(asJson)
.then(update => {
if (!update || !update.url || !update.version || !update.productVersion) {
if (process.env.SNAP && process.env.SNAP_REVISION) {
this.checkForSnapUpdate();
} else {
this.requestService.request({ url: this.url }, CancellationToken.None)
.then<IUpdate>(asJson)
.then(update => {
if (!update || !update.url || !update.version || !update.productVersion) {
/* __GDPR__
"update:notAvailable" : {
"explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
}
*/
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
this.setState(State.Idle(UpdateType.Archive));
} else {
this.setState(State.AvailableForDownload(update));
}
})
.then(null, err => {
this.logService.error(err);
/* __GDPR__
"update:notAvailable" : {
"explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
}
"update:notAvailable" : {
"explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
}
*/
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
this.setState(State.Idle(UpdateType.Archive));
} else {
this.setState(State.AvailableForDownload(update));
}
})
.then(null, err => {
this.logService.error(err);
/* __GDPR__
"update:notAvailable" : {
"explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
}
*/
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
this.setState(State.Idle(UpdateType.Archive));
});
// only show message when explicitly checking for updates
const message: string | undefined = !!context ? (err.message || err) : undefined;
this.setState(State.Idle(UpdateType.Archive, message));
});
}
}
protected doDownloadUpdate(state: AvailableForDownload): TPromise<void> {
private checkForSnapUpdate(): void {
// If the application was installed as a snap, updates happen in the
// background automatically, we just need to check to see if an update
// has already happened.
realpath(`${path.dirname(process.env.SNAP!)}/current`, (err, resolvedCurrentSnapPath) => {
if (err) {
this.logService.error('update#checkForSnapUpdate(): Could not get realpath of application.');
return;
}
const currentRevision = path.basename(resolvedCurrentSnapPath);
if (process.env.SNAP_REVISION !== currentRevision) {
// TODO@joao: snap
this.setState(State.Ready({ version: '', productVersion: '' }));
} else {
this.setState(State.Idle(UpdateType.Archive));
}
});
}
protected async doDownloadUpdate(state: AvailableForDownload): Promise<void> {
// Use the download URL if available as we don't currently detect the package type that was
// installed and the website download page is more useful than the tarball generally.
if (product.downloadUrl && product.downloadUrl.length > 0) {
shell.openExternal(product.downloadUrl);
} else {
} else if (state.update.url) {
shell.openExternal(state.update.url);
}
this.setState(State.Idle(UpdateType.Archive));
return TPromise.as(null);
}
protected doQuitAndInstall(): void {
this.logService.trace('update#quitAndInstall(): running raw#quitAndInstall()');
const snap = process.env.SNAP;
// TODO@joao what to do?
if (!snap) {
return;
}
// Allow 3 seconds for VS Code to close
spawn('bash', ['-c', path.join(snap, `usr/share/${product.applicationName}/snapUpdate.sh`)], {
detached: true,
stdio: ['ignore', 'ignore', 'ignore']
});
}
}

View File

@@ -0,0 +1,222 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event, Emitter, fromNodeEventEmitter, filterEvent, debounceEvent } from 'vs/base/common/event';
import { timeout } from 'vs/base/common/async';
import { ILifecycleService } from 'vs/platform/lifecycle/electron-main/lifecycleMain';
import product from 'vs/platform/node/product';
import { IUpdateService, State, StateType, AvailableForDownload, UpdateType } from 'vs/platform/update/common/update';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
import * as path from 'path';
import { realpath, watch } from 'fs';
import { spawn } from 'child_process';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
abstract class AbstractUpdateService2 implements IUpdateService {
_serviceBrand: any;
private _state: State = State.Uninitialized;
private _onStateChange = new Emitter<State>();
get onStateChange(): Event<State> { return this._onStateChange.event; }
get state(): State {
return this._state;
}
protected setState(state: State): void {
this.logService.info('update#setState', state.type);
this._state = state;
this._onStateChange.fire(state);
}
constructor(
@ILifecycleService private lifecycleService: ILifecycleService,
@IEnvironmentService environmentService: IEnvironmentService,
@ILogService protected logService: ILogService,
) {
if (environmentService.disableUpdates) {
this.logService.info('update#ctor - updates are disabled');
return;
}
this.setState(State.Idle(this.getUpdateType()));
// Start checking for updates after 30 seconds
this.scheduleCheckForUpdates(30 * 1000).then(undefined, err => this.logService.error(err));
}
private scheduleCheckForUpdates(delay = 60 * 60 * 1000): Thenable<void> {
return timeout(delay)
.then(() => this.checkForUpdates(null))
.then(() => {
// Check again after 1 hour
return this.scheduleCheckForUpdates(60 * 60 * 1000);
});
}
async checkForUpdates(context: any): Promise<void> {
this.logService.trace('update#checkForUpdates, state = ', this.state.type);
if (this.state.type !== StateType.Idle) {
return;
}
this.doCheckForUpdates(context);
}
async downloadUpdate(): Promise<void> {
this.logService.trace('update#downloadUpdate, state = ', this.state.type);
if (this.state.type !== StateType.AvailableForDownload) {
return;
}
await this.doDownloadUpdate(this.state);
}
protected doDownloadUpdate(state: AvailableForDownload): Promise<void> {
return Promise.resolve(void 0);
}
async applyUpdate(): Promise<void> {
this.logService.trace('update#applyUpdate, state = ', this.state.type);
if (this.state.type !== StateType.Downloaded) {
return;
}
await this.doApplyUpdate();
}
protected doApplyUpdate(): Thenable<void> {
return Promise.resolve(void 0);
}
quitAndInstall(): Thenable<void> {
this.logService.trace('update#quitAndInstall, state = ', this.state.type);
if (this.state.type !== StateType.Ready) {
return Promise.resolve(void 0);
}
this.logService.trace('update#quitAndInstall(): before lifecycle quit()');
this.lifecycleService.quit(true /* from update */).then(vetod => {
this.logService.trace(`update#quitAndInstall(): after lifecycle quit() with veto: ${vetod}`);
if (vetod) {
return;
}
this.logService.trace('update#quitAndInstall(): running raw#quitAndInstall()');
this.doQuitAndInstall();
});
return Promise.resolve(void 0);
}
protected getUpdateType(): UpdateType {
return UpdateType.Snap;
}
protected doQuitAndInstall(): void {
// noop
}
abstract isLatestVersion(): Thenable<boolean | undefined>;
protected abstract doCheckForUpdates(context: any): void;
}
export class SnapUpdateService extends AbstractUpdateService2 {
_serviceBrand: any;
constructor(
@ILifecycleService lifecycleService: ILifecycleService,
@IEnvironmentService environmentService: IEnvironmentService,
@ILogService logService: ILogService,
@ITelemetryService private telemetryService: ITelemetryService
) {
super(lifecycleService, environmentService, logService);
if (typeof process.env.SNAP === 'undefined') {
throw new Error(`'SNAP' environment variable not set`);
}
const watcher = watch(path.dirname(process.env.SNAP));
const onChange = fromNodeEventEmitter(watcher, 'change', (_, fileName: string) => fileName);
const onCurrentChange = filterEvent(onChange, n => n === 'current');
const onDebouncedCurrentChange = debounceEvent(onCurrentChange, (_, e) => e, 2000);
const listener = onDebouncedCurrentChange(this.checkForUpdates, this);
lifecycleService.onWillShutdown(() => {
listener.dispose();
watcher.close();
});
}
protected doCheckForUpdates(context: any): void {
this.setState(State.CheckingForUpdates(context));
this.isUpdateAvailable().then(result => {
if (result) {
this.setState(State.Ready({ version: 'something', productVersion: 'someting' }));
} else {
/* __GDPR__
"update:notAvailable" : {
"explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
}
*/
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
this.setState(State.Idle(UpdateType.Snap));
}
}, err => {
this.logService.error(err);
/* __GDPR__
"update:notAvailable" : {
"explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
}
*/
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
this.setState(State.Idle(UpdateType.Snap, err.message || err));
});
}
protected doQuitAndInstall(): void {
this.logService.trace('update#quitAndInstall(): running raw#quitAndInstall()');
if (typeof process.env.SNAP === 'undefined') {
return;
}
// Allow 3 seconds for VS Code to close
spawn('bash', ['-c', path.join(process.env.SNAP, `usr/share/${product.applicationName}/snapUpdate.sh`)], {
detached: true,
stdio: ['ignore', 'ignore', 'ignore']
});
}
private isUpdateAvailable(): Thenable<boolean> {
return new Promise((c, e) => {
realpath(`/snap/${product.applicationName}/current`, (err, resolvedCurrentSnapPath) => {
if (err) { return e(err); }
const currentRevision = path.basename(resolvedCurrentSnapPath);
c(process.env.SNAP_REVISION !== currentRevision);
});
});
}
isLatestVersion(): Thenable<boolean | undefined> {
return this.isUpdateAvailable().then(undefined, err => {
this.logService.error('update#checkForSnapUpdate(): Could not get realpath of application.');
return undefined;
});
}
}

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as fs from 'fs';
import * as path from 'path';
import * as pfs from 'vs/base/node/pfs';
@@ -13,7 +11,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { ILifecycleService } from 'vs/platform/lifecycle/electron-main/lifecycleMain';
import { IRequestService } from 'vs/platform/request/node/request';
import product from 'vs/platform/node/product';
import { TPromise, Promise } from 'vs/base/common/winjs.base';
import { State, IUpdate, StateType, AvailableForDownload, UpdateType } from 'vs/platform/update/common/update';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
@@ -24,19 +21,13 @@ import { checksum } from 'vs/base/node/crypto';
import { tmpdir } from 'os';
import { spawn } from 'child_process';
import { shell } from 'electron';
import { CancellationToken } from 'vs/base/common/cancellation';
import { timeout } from 'vs/base/common/async';
function pollUntil(fn: () => boolean, timeout = 1000): TPromise<void> {
return new TPromise<void>(c => {
const poll = () => {
if (fn()) {
c(null);
} else {
setTimeout(poll, timeout);
}
};
poll();
});
async function pollUntil(fn: () => boolean, millis = 1000): Promise<void> {
while (!fn()) {
await timeout(millis);
}
}
interface IAvailableUpdate {
@@ -62,7 +53,7 @@ export class Win32UpdateService extends AbstractUpdateService {
private availableUpdate: IAvailableUpdate | undefined;
@memoize
get cachePath(): TPromise<string> {
get cachePath(): Thenable<string> {
// {{SQL CARBON EDIT}}
const result = path.join(tmpdir(), `sqlops-update-${product.target}-${process.arch}`);
return pfs.mkdirp(result, null).then(() => result);
@@ -116,7 +107,7 @@ export class Win32UpdateService extends AbstractUpdateService {
this.setState(State.CheckingForUpdates(context));
this.requestService.request({ url: this.url })
this.requestService.request({ url: this.url }, CancellationToken.None)
.then<IUpdate>(asJson)
.then(update => {
const updateType = getUpdateType();
@@ -130,12 +121,12 @@ export class Win32UpdateService extends AbstractUpdateService {
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
this.setState(State.Idle(updateType));
return TPromise.as(null);
return Promise.resolve(null);
}
if (updateType === UpdateType.Archive) {
this.setState(State.AvailableForDownload(update));
return TPromise.as(null);
return Promise.resolve(null);
}
this.setState(State.Downloading(update));
@@ -144,14 +135,14 @@ export class Win32UpdateService extends AbstractUpdateService {
return this.getUpdatePackagePath(update.version).then(updatePackagePath => {
return pfs.exists(updatePackagePath).then(exists => {
if (exists) {
return TPromise.as(updatePackagePath);
return Promise.resolve(updatePackagePath);
}
const url = update.url;
const hash = update.hash;
const downloadPath = `${updatePackagePath}.tmp`;
return this.requestService.request({ url })
return this.requestService.request({ url }, CancellationToken.None)
.then(context => download(downloadPath, context))
.then(hash ? () => checksum(downloadPath, update.hash) : () => null)
.then(() => pfs.rename(downloadPath, updatePackagePath))
@@ -182,68 +173,75 @@ export class Win32UpdateService extends AbstractUpdateService {
}
*/
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
this.setState(State.Idle(getUpdateType()));
// only show message when explicitly checking for updates
const message: string | undefined = !!context ? (err.message || err) : undefined;
this.setState(State.Idle(getUpdateType(), message));
});
}
protected doDownloadUpdate(state: AvailableForDownload): TPromise<void> {
protected async doDownloadUpdate(state: AvailableForDownload): Promise<void> {
shell.openExternal(state.update.url);
this.setState(State.Idle(getUpdateType()));
return TPromise.as(null);
}
private getUpdatePackagePath(version: string): TPromise<string> {
private async getUpdatePackagePath(version: string): Promise<string> {
const cachePath = await this.cachePath;
// {{SQL CARBON EDIT}}
return this.cachePath.then(cachePath => path.join(cachePath, `AzureDataStudioSetup-${product.quality}-${version}.exe`));
return path.join(cachePath, `AzureDataStudioSetup-${product.quality}-${version}.exe`);
}
private cleanup(exceptVersion: string = null): Promise {
private async cleanup(exceptVersion: string | null = null): Promise<any> {
const filter = exceptVersion ? one => !(new RegExp(`${product.quality}-${exceptVersion}\\.exe$`).test(one)) : () => true;
return this.cachePath
.then(cachePath => pfs.readdir(cachePath)
.then(all => Promise.join(all
.filter(filter)
.map(one => pfs.unlink(path.join(cachePath, one)).then(null, () => null))
))
);
const cachePath = await this.cachePath;
const versions = await pfs.readdir(cachePath);
const promises = versions.filter(filter).map(async one => {
try {
await pfs.unlink(path.join(cachePath, one));
} catch (err) {
// ignore
}
});
await Promise.all(promises);
}
protected doApplyUpdate(): TPromise<void> {
protected async doApplyUpdate(): Promise<void> {
if (this.state.type !== StateType.Downloaded && this.state.type !== StateType.Downloading) {
return TPromise.as(null);
return Promise.resolve(null);
}
if (!this.availableUpdate) {
return TPromise.as(null);
return Promise.resolve(null);
}
const update = this.state.update;
this.setState(State.Updating(update));
return this.cachePath.then(cachePath => {
this.availableUpdate.updateFilePath = path.join(cachePath, `CodeSetup-${product.quality}-${update.version}.flag`);
const cachePath = await this.cachePath;
return pfs.writeFile(this.availableUpdate.updateFilePath, 'flag').then(() => {
const child = spawn(this.availableUpdate.packagePath, ['/verysilent', `/update="${this.availableUpdate.updateFilePath}"`, '/nocloseapplications', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
detached: true,
stdio: ['ignore', 'ignore', 'ignore'],
windowsVerbatimArguments: true
});
this.availableUpdate.updateFilePath = path.join(cachePath, `CodeSetup-${product.quality}-${update.version}.flag`);
child.once('exit', () => {
this.availableUpdate = undefined;
this.setState(State.Idle(getUpdateType()));
});
const readyMutexName = `${product.win32MutexName}-ready`;
const isActive = (require.__$__nodeRequire('windows-mutex') as any).isActive;
// poll for mutex-ready
pollUntil(() => isActive(readyMutexName))
.then(() => this.setState(State.Ready(update)));
});
await pfs.writeFile(this.availableUpdate.updateFilePath, 'flag');
const child = spawn(this.availableUpdate.packagePath, ['/verysilent', `/update="${this.availableUpdate.updateFilePath}"`, '/nocloseapplications', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
detached: true,
stdio: ['ignore', 'ignore', 'ignore'],
windowsVerbatimArguments: true
});
child.once('exit', () => {
this.availableUpdate = undefined;
this.setState(State.Idle(getUpdateType()));
});
const readyMutexName = `${product.win32MutexName}-ready`;
const isActive = (require.__$__nodeRequire('windows-mutex') as any).isActive;
// poll for mutex-ready
pollUntil(() => isActive(readyMutexName))
.then(() => this.setState(State.Ready(update)));
}
protected doQuitAndInstall(): void {

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as nls from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
@@ -21,20 +19,20 @@ configurationRegistry.registerConfiguration({
'enum': ['none', 'default'],
'default': 'default',
'scope': ConfigurationScope.APPLICATION,
'description': nls.localize('updateChannel', "Configure whether you receive automatic updates from an update channel. Requires a restart after change. The updates are fetched from an online service."),
'description': nls.localize('updateChannel', "Configure whether you receive automatic updates from an update channel. Requires a restart after change. The updates are fetched from a Microsoft online service."),
'tags': ['usesOnlineServices']
},
'update.enableWindowsBackgroundUpdates': {
'type': 'boolean',
'default': true,
'scope': ConfigurationScope.APPLICATION,
'description': nls.localize('enableWindowsBackgroundUpdates', "Enables Windows background updates. The updates are fetched from an online service."),
'description': nls.localize('enableWindowsBackgroundUpdates', "Enables Windows background updates. The updates are fetched from a Microsoft online service."),
'tags': ['usesOnlineServices']
},
'update.showReleaseNotes': {
'type': 'boolean',
'default': true,
'description': nls.localize('showReleaseNotes', "Show Release Notes after an update. The Release Notes are fetched from an online service."),
'description': nls.localize('showReleaseNotes', "Show Release Notes after an update. The Release Notes are fetched from a Microsoft online service."),
'tags': ['usesOnlineServices']
}
}

View File

@@ -3,40 +3,24 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/node/ipc';
import { Event, Emitter } from 'vs/base/common/event';
import { onUnexpectedError } from 'vs/base/common/errors';
import { IUpdateService, State } from './update';
import { IUpdateService, State } from 'vs/platform/update/common/update';
export interface IUpdateChannel extends IChannel {
listen(event: 'onStateChange'): Event<State>;
listen<T>(command: string, arg?: any): Event<T>;
call(command: 'checkForUpdates', arg: any): TPromise<void>;
call(command: 'downloadUpdate'): TPromise<void>;
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>;
}
export class UpdateChannel implements IUpdateChannel {
export class UpdateChannel implements IServerChannel {
constructor(private service: IUpdateService) { }
listen<T>(event: string, arg?: any): Event<any> {
listen(_, event: string): Event<any> {
switch (event) {
case 'onStateChange': return this.service.onStateChange;
}
throw new Error('No event found');
throw new Error(`Event not found: ${event}`);
}
call(command: string, arg?: any): TPromise<any> {
call(_, command: string, arg?: any): TPromise<any> {
switch (command) {
case 'checkForUpdates': return this.service.checkForUpdates(arg);
case 'downloadUpdate': return this.service.downloadUpdate();
@@ -45,7 +29,8 @@ export class UpdateChannel implements IUpdateChannel {
case '_getInitialState': return TPromise.as(this.service.state);
case 'isLatestVersion': return this.service.isLatestVersion();
}
return undefined;
throw new Error(`Call not found: ${command}`);
}
}
@@ -59,18 +44,18 @@ export class UpdateChannelClient implements IUpdateService {
private _state: State = State.Uninitialized;
get state(): State { return this._state; }
constructor(private channel: IUpdateChannel) {
constructor(private channel: IChannel) {
// always set this._state as the state changes
this.onStateChange(state => this._state = state);
channel.call('_getInitialState').done(state => {
channel.call<State>('_getInitialState').then(state => {
// fire initial state
this._onStateChange.fire(state);
// fire subsequent states as they come in from remote
this.channel.listen('onStateChange')(state => this._onStateChange.fire(state));
}, onUnexpectedError);
this.channel.listen<State>('onStateChange')(state => this._onStateChange.fire(state));
});
}
checkForUpdates(context: any): TPromise<void> {