Skip to content

Commit 5c3e3ec

Browse files
committed
snap updates
1 parent e1f56ee commit 5c3e3ec

3 files changed

Lines changed: 39 additions & 51 deletions

File tree

resources/linux/snap/snapUpdate.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
sleep 5
2-
code-insiders /Users/daimms/dev/Microsoft/vscode/OSSREADME.json
1+
#!/bin/sh
2+
sleep 2
3+
@@NAME@@

resources/linux/snap/snapcraft.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,8 @@ parts:
3737
# - libgtk2.0-bin
3838
prime:
3939
- -usr/share/dh-python
40-
electron-launch:
41-
plugin: dump
42-
source: .
43-
organize:
44-
electron-launch: bin/electron-launch
4540

4641
apps:
4742
@@NAME@@:
48-
command: bin/electron-launch ${SNAP}/usr/share/@@NAME@@/bin/@@NAME@@
43+
command: electron-launch ${SNAP}/usr/share/@@NAME@@/bin/@@NAME@@
4944
desktop: usr/share/applications/@@NAME@@.desktop

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

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
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';
77
import { Throttler, timeout } from 'vs/base/common/async';
8-
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
98
import { ILifecycleService } from 'vs/platform/lifecycle/electron-main/lifecycleMain';
109
import product from 'vs/platform/node/product';
1110
import { TPromise } from 'vs/base/common/winjs.base';
1211
import { IUpdateService, State, StateType, AvailableForDownload, UpdateType } from 'vs/platform/update/common/update';
1312
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1413
import { ILogService } from 'vs/platform/log/common/log';
15-
import { IRequestService } from 'vs/platform/request/node/request';
1614
import * as path from 'path';
17-
import { realpath } from 'fs';
15+
import { realpath, watch } from 'fs';
1816
import { spawn } from 'child_process';
1917
import { 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

Comments
 (0)