mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
cleanup snap update service
This commit is contained in:
parent
9069fdcfc6
commit
71fbf3dbe0
|
@ -204,7 +204,6 @@ function prepareSnapPackage(arch) {
|
|||
.pipe(rename('snap/snapcraft.yaml'));
|
||||
|
||||
const snapUpdate = gulp.src('resources/linux/snap/snapUpdate.sh', { base: '.' })
|
||||
.pipe(replace('@@NAME@@', product.applicationName))
|
||||
.pipe(rename(`usr/share/${product.applicationName}/snapUpdate.sh`));
|
||||
|
||||
const electronLaunch = gulp.src('resources/linux/snap/electron-launch', { base: '.' })
|
||||
|
|
|
@ -512,7 +512,7 @@ export class CodeApplication extends Disposable {
|
|||
services.set(IUpdateService, new SyncDescriptor(Win32UpdateService));
|
||||
} else if (process.platform === 'linux') {
|
||||
if (process.env.SNAP && process.env.SNAP_REVISION) {
|
||||
services.set(IUpdateService, new SyncDescriptor(SnapUpdateService));
|
||||
services.set(IUpdateService, new SyncDescriptor(SnapUpdateService, [process.env.SNAP, process.env.SNAP_REVISION]));
|
||||
} else {
|
||||
services.set(IUpdateService, new SyncDescriptor(LinuxUpdateService));
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import * as path from 'path';
|
|||
import { realpath, watch } from 'fs';
|
||||
import { spawn } from 'child_process';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { stat } from 'vs/base/node/pfs';
|
||||
|
||||
abstract class AbstractUpdateService2 implements IUpdateService {
|
||||
|
||||
|
@ -136,7 +137,11 @@ export class SnapUpdateService extends AbstractUpdateService2 {
|
|||
|
||||
_serviceBrand: any;
|
||||
|
||||
private snapUpdatePath: string;
|
||||
|
||||
constructor(
|
||||
private snap: string,
|
||||
private snapRevision: string,
|
||||
@ILifecycleService lifecycleService: ILifecycleService,
|
||||
@IEnvironmentService environmentService: IEnvironmentService,
|
||||
@ILogService logService: ILogService,
|
||||
|
@ -144,10 +149,9 @@ export class SnapUpdateService extends AbstractUpdateService2 {
|
|||
) {
|
||||
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));
|
||||
this.snapUpdatePath = path.join(this.snap, `usr/share/${product.applicationName}/snapUpdate.sh`);
|
||||
|
||||
const watcher = watch(path.dirname(this.snap));
|
||||
const onChange = Event.fromNodeEventEmitter(watcher, 'change', (_, fileName: string) => fileName);
|
||||
const onCurrentChange = Event.filter(onChange, n => n === 'current');
|
||||
const onDebouncedCurrentChange = Event.debounce(onCurrentChange, (_, e) => e, 2000);
|
||||
|
@ -192,21 +196,22 @@ export class SnapUpdateService extends AbstractUpdateService2 {
|
|||
this.logService.trace('update#quitAndInstall(): running raw#quitAndInstall()');
|
||||
|
||||
// Allow 3 seconds for VS Code to close
|
||||
spawn('bash', ['-c', path.join(process.env.SNAP!, `usr/share/${product.applicationName}/snapUpdate.sh`)], {
|
||||
spawn('bash', ['-c', this.snapUpdatePath], {
|
||||
detached: true,
|
||||
stdio: ['ignore', 'ignore', 'ignore']
|
||||
});
|
||||
}
|
||||
|
||||
private isUpdateAvailable(): Promise<boolean> {
|
||||
return new Promise((c, e) => {
|
||||
realpath(`${path.dirname(process.env.SNAP!)}/current`, (err, resolvedCurrentSnapPath) => {
|
||||
if (err) { return e(err); }
|
||||
private async isUpdateAvailable(): Promise<boolean> {
|
||||
try {
|
||||
await stat(this.snapUpdatePath);
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const currentRevision = path.basename(resolvedCurrentSnapPath);
|
||||
c(process.env.SNAP_REVISION !== currentRevision);
|
||||
});
|
||||
});
|
||||
const resolvedCurrentSnapPath = await new Promise<string>((c, e) => realpath(`${path.dirname(this.snap)}/current`, (err, r) => err ? e(err) : c(r)));
|
||||
const currentRevision = path.basename(resolvedCurrentSnapPath);
|
||||
return this.snapRevision !== currentRevision;
|
||||
}
|
||||
|
||||
isLatestVersion(): Promise<boolean | undefined> {
|
||||
|
|
Loading…
Reference in a new issue