Skip to content

Commit 05c7946

Browse files
committed
wip: update 💄
1 parent e2b6527 commit 05c7946

5 files changed

Lines changed: 53 additions & 64 deletions

File tree

src/vs/code/electron-main/auto-updater.linux.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@ export class LinuxAutoUpdaterImpl extends EventEmitter {
6767
})
6868
.then(() => this.currentRequest = null);
6969
}
70+
71+
quitAndInstall(): void {
72+
// noop
73+
}
7074
}

src/vs/code/electron-main/auto-updater.win32.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@ export interface IUpdate {
3030

3131
export class Win32AutoUpdaterImpl extends EventEmitter {
3232

33-
private url: string;
34-
private currentRequest: Promise;
33+
private url: string = null;
34+
private currentRequest: Promise = null;
35+
private updatePackagePath: string = null;
3536

3637
constructor(
3738
@ILifecycleService private lifecycleService: ILifecycleService,
3839
@IRequestService private requestService: IRequestService
3940
) {
4041
super();
41-
42-
this.url = null;
43-
this.currentRequest = null;
4442
}
4543

4644
get cachePath(): TPromise<string> {
@@ -91,13 +89,14 @@ export class Win32AutoUpdaterImpl extends EventEmitter {
9189
.then(() => updatePackagePath);
9290
});
9391
}).then(updatePackagePath => {
92+
this.updatePackagePath = updatePackagePath;
93+
9494
this.emit('update-downloaded',
9595
{},
9696
update.releaseNotes,
9797
update.productVersion,
9898
new Date(),
99-
this.url,
100-
() => this.quitAndUpdate(updatePackagePath)
99+
this.url
101100
);
102101
});
103102
});
@@ -117,19 +116,6 @@ export class Win32AutoUpdaterImpl extends EventEmitter {
117116
return this.cachePath.then(cachePath => path.join(cachePath, `CodeSetup-${product.quality}-${version}.exe`));
118117
}
119118

120-
private quitAndUpdate(updatePackagePath: string): void {
121-
this.lifecycleService.quit().done(vetod => {
122-
if (vetod) {
123-
return;
124-
}
125-
126-
spawn(updatePackagePath, ['/silent', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
127-
detached: true,
128-
stdio: ['ignore', 'ignore', 'ignore']
129-
});
130-
});
131-
}
132-
133119
private cleanup(exceptVersion: string = null): Promise {
134120
const filter = exceptVersion ? one => !(new RegExp(`${product.quality}-${exceptVersion}\\.exe$`).test(one)) : () => true;
135121

@@ -141,4 +127,15 @@ export class Win32AutoUpdaterImpl extends EventEmitter {
141127
))
142128
);
143129
}
130+
131+
quitAndInstall(): void {
132+
if (!this.updatePackagePath) {
133+
return;
134+
}
135+
136+
spawn(this.updatePackagePath, ['/silent', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
137+
detached: true,
138+
stdio: ['ignore', 'ignore', 'ignore']
139+
});
140+
}
144141
}

src/vs/code/electron-main/menus.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,10 @@ export class VSCodeMenu {
748748
return [];
749749

750750
case UpdateState.UpdateDownloaded:
751-
const update = this.updateService.availableUpdate;
752751
return [new MenuItem({
753752
label: nls.localize('miRestartToUpdate', "Restart To Update..."), click: () => {
754753
this.reportMenuActionTelemetry('RestartToUpdate');
755-
update.quitAndUpdate();
754+
this.updateService.quitAndInstall();
756755
}
757756
})];
758757

@@ -761,10 +760,9 @@ export class VSCodeMenu {
761760

762761
case UpdateState.UpdateAvailable:
763762
if (platform.isLinux) {
764-
const update = this.updateService.availableUpdate;
765763
return [new MenuItem({
766764
label: nls.localize('miDownloadUpdate', "Download Available Update"), click: () => {
767-
update.quitAndUpdate();
765+
this.updateService.quitAndInstall();
768766
}
769767
})];
770768
}

src/vs/code/electron-main/update-manager.ts

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,19 @@ export interface IRawUpdate {
3939
releaseNotes: string;
4040
version: string;
4141
date: Date;
42-
quitAndUpdate: () => void;
43-
}
44-
45-
export interface IRawAvailableUpdate {
46-
url: string;
47-
version: string;
4842
}
4943

5044
export interface IUpdate {
5145
version: string;
52-
url?: string;
53-
releaseNotes?: string;
5446
date?: Date;
55-
}
56-
57-
interface IRawUpdate2 extends IUpdate {
58-
quitAndUpdate?: () => void;
47+
releaseNotes?: string;
48+
url?: string;
5949
}
6050

6151
interface IRawAutoUpdater extends NodeJS.EventEmitter {
6252
setFeedURL(url: string): void;
6353
checkForUpdates(): void;
54+
quitAndInstall(): void;
6455
}
6556

6657
export const IUpdateService = createDecorator<IUpdateService>('updateService');
@@ -75,16 +66,16 @@ export interface IUpdateService {
7566
readonly onStateChange: Event<void>;
7667

7768
readonly state: State;
78-
readonly availableUpdate: IRawUpdate;
7969
checkForUpdates(explicit: boolean): TPromise<IUpdate>;
70+
quitAndInstall(): void;
8071
}
8172

8273
export class UpdateManager implements IUpdateService {
8374

8475
_serviceBrand: any;
8576

8677
private _state: State = State.Uninitialized;
87-
private _availableUpdate: IRawUpdate = null;
78+
private _availableUpdate: IUpdate = null;
8879
private raw: IRawAutoUpdater;
8980
private throttler: Throttler = new Throttler();
9081

@@ -100,15 +91,15 @@ export class UpdateManager implements IUpdateService {
10091
private _onUpdateNotAvailable = new Emitter<boolean>();
10192
get onUpdateNotAvailable(): Event<boolean> { return this._onUpdateNotAvailable.event; }
10293

103-
private _onUpdateReady = new Emitter<IRawUpdate>();
104-
get onUpdateReady(): Event<IRawUpdate> { return this._onUpdateReady.event; }
94+
private _onUpdateReady = new Emitter<IUpdate>();
95+
get onUpdateReady(): Event<IUpdate> { return this._onUpdateReady.event; }
10596

10697
private _onStateChange = new Emitter<void>();
10798
get onStateChange(): Event<void> { return this._onStateChange.event; }
10899

109100
@memoize
110101
private get onRawError(): Event<string> {
111-
return fromEventEmitter<string>(this.raw, 'error', (_, message) => message);
102+
return fromEventEmitter(this.raw, 'error', (_, message) => message);
112103
}
113104

114105
@memoize
@@ -117,18 +108,13 @@ export class UpdateManager implements IUpdateService {
117108
}
118109

119110
@memoize
120-
private get onRawUpdateAvailable(): Event<IRawAvailableUpdate> {
121-
return fromEventEmitter<IRawAvailableUpdate>(this.raw, 'update-available', (_, url, version) => ({ url, version }));
111+
private get onRawUpdateAvailable(): Event<{ url: string; version: string; }> {
112+
return fromEventEmitter(this.raw, 'update-available', (_, url, version) => ({ url, version }));
122113
}
123114

124115
@memoize
125116
private get onRawUpdateDownloaded(): Event<IRawUpdate> {
126-
return fromEventEmitter<IRawUpdate>(this.raw, 'update-not-available', (_, releaseNotes, version, date, url, rawQuitAndUpdate) => ({
127-
releaseNotes,
128-
version,
129-
date,
130-
quitAndUpdate: () => this.quitAndUpdate(rawQuitAndUpdate)
131-
}));
117+
return fromEventEmitter(this.raw, 'update-downloaded', (_, releaseNotes, version, date, url) => ({ releaseNotes, version, date }));
132118
}
133119

134120
get state(): State {
@@ -140,7 +126,7 @@ export class UpdateManager implements IUpdateService {
140126
this._onStateChange.fire();
141127
}
142128

143-
get availableUpdate(): IRawUpdate {
129+
get availableUpdate(): IUpdate {
144130
return this._availableUpdate;
145131
}
146132

@@ -203,11 +189,11 @@ export class UpdateManager implements IUpdateService {
203189
this.state = State.CheckingForUpdate;
204190

205191
const listeners: IDisposable[] = [];
206-
const result = new TPromise<IRawUpdate2>((c, e) => {
192+
const result = new TPromise<IUpdate>((c, e) => {
207193
once(this.onRawError)(e, null, listeners);
208194
once(this.onRawUpdateNotAvailable)(() => c(null), null, listeners);
209195
once(this.onRawUpdateAvailable)(({ url, version }) => url && c({ url, version }), null, listeners);
210-
once(this.onRawUpdateDownloaded)(({ version, date, releaseNotes, quitAndUpdate }) => c({ version, date, releaseNotes, quitAndUpdate }), null, listeners);
196+
once(this.onRawUpdateDownloaded)(({ version, date, releaseNotes }) => c({ version, date, releaseNotes }), null, listeners);
211197

212198
this.raw.checkForUpdates();
213199
}).then(update => {
@@ -216,23 +202,21 @@ export class UpdateManager implements IUpdateService {
216202
this.state = State.Idle;
217203

218204
} else if (update.url) {
219-
const data: IRawUpdate = {
205+
const data: IUpdate = {
220206
releaseNotes: '',
221207
version: '',
222-
date: new Date(),
223-
quitAndUpdate: () => electron.shell.openExternal(update.url)
208+
date: new Date()
224209
};
225210

226211
this._availableUpdate = data;
227212
this._onUpdateAvailable.fire({ url: update.url, version: update.version });
228213
this.state = State.UpdateAvailable;
229214

230215
} else {
231-
const data: IRawUpdate = {
216+
const data: IUpdate = {
232217
releaseNotes: update.releaseNotes,
233218
version: update.version,
234-
date: update.date,
235-
quitAndUpdate: () => this.quitAndUpdate(update.quitAndUpdate)
219+
date: update.date
236220
};
237221

238222
this._availableUpdate = data;
@@ -271,7 +255,16 @@ export class UpdateManager implements IUpdateService {
271255
return `${product.updateUrl}/api/update/${platform}/${channel}/${product.commit}`;
272256
}
273257

274-
private quitAndUpdate(rawQuitAndUpdate: () => void): void {
258+
quitAndInstall(): void {
259+
if (!this._availableUpdate) {
260+
return;
261+
}
262+
263+
if (this._availableUpdate.url) {
264+
electron.shell.openExternal(this._availableUpdate.url);
265+
return;
266+
}
267+
275268
this.lifecycleService.quit(true /* from update */).done(vetod => {
276269
if (vetod) {
277270
return;
@@ -284,7 +277,7 @@ export class UpdateManager implements IUpdateService {
284277
electron.session.defaultSession.flushStorageData();
285278
}
286279

287-
rawQuitAndUpdate();
280+
this.raw.quitAndInstall();
288281
});
289282
}
290283
}

src/vs/code/electron-main/windows.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,7 @@ export class WindowsManager implements IWindowsMainService, IWindowEventService
261261

262262
ipc.on('vscode:update-apply', () => {
263263
this.logService.log('IPC#vscode:update-apply');
264-
265-
if (this.updateService.availableUpdate) {
266-
this.updateService.availableUpdate.quitAndUpdate();
267-
}
264+
this.updateService.quitAndInstall();
268265
});
269266

270267
this.updateService.onUpdateNotAvailable(explicit => {

0 commit comments

Comments
 (0)