Add updates check

This commit is contained in:
Silvano Cerza
2021-12-15 17:51:21 +01:00
parent 9a16bd37ff
commit 2061f52045
3 changed files with 136 additions and 0 deletions

View File

@@ -63,6 +63,7 @@
"css-element-queries": "^1.2.0",
"dateformat": "^3.0.3",
"deepmerge": "2.0.1",
"electron-updater": "^4.6.1",
"fuzzy": "^0.1.3",
"glob": "^7.1.6",
"google-protobuf": "^3.11.4",

View File

@@ -0,0 +1,61 @@
import { Command, CommandContribution, CommandRegistry } from "@theia/core";
import { injectable, inject } from "inversify";
import { CancellationToken } from "electron-updater";
import { IDEUpdater } from "./ide-updater";
// IDEUpdaterCommands register commands used to verify if there
// are new IDE updates, download them, and install them.
@injectable()
export class IDEUpdaterCommands implements CommandContribution {
private readonly cancellationToken = new CancellationToken();
constructor(
@inject(IDEUpdater) private readonly updater: IDEUpdater
) {
}
registerCommands(registry: CommandRegistry): void {
registry.registerCommand(IDEUpdaterCommands.CHECK_FOR_UPDATES, {
execute: this.checkForUpdates,
});
registry.registerCommand(IDEUpdaterCommands.DOWNLOAD_UPDATE, {
execute: this.downloadUpdate,
})
registry.registerCommand(IDEUpdaterCommands.STOP_DOWNLOAD, {
execute: this.stopDownload,
})
registry.registerCommand(IDEUpdaterCommands.INSTALL_UPDATE, {
execute: this.quitAndInstall,
})
}
checkForUpdates() {
this.updater.checkForUpdates();
}
downloadUpdate() {
this.updater.downloadUpdate(this.cancellationToken);
}
stopDownload() {
this.cancellationToken.cancel();
}
quitAndInstall() {
this.updater.quitAndInstall();
}
}
export namespace IDEUpdaterCommands {
export const CHECK_FOR_UPDATES: Command = {
id: 'arduino-ide-check-for-updates',
};
export const DOWNLOAD_UPDATE: Command = {
id: 'arduino-ide-download-update',
};
export const STOP_DOWNLOAD: Command = {
id: 'arduino-ide-stop-download',
};
export const INSTALL_UPDATE: Command = {
id: 'arduino-ide-install-update',
};
}

View File

@@ -0,0 +1,74 @@
import { injectable } from "@theia/core/shared/inversify";
import { Emitter } from "@theia/core/shared/vscode-languageserver-protocol";
import { AllPublishOptions } from "builder-util-runtime";
import {
AppUpdater,
AppImageUpdater,
MacUpdater,
NsisUpdater,
UpdateInfo,
ProgressInfo,
CancellationToken
} from "electron-updater";
// IDEUpdater TODO docs
@injectable()
export class IDEUpdater {
private updater: AppUpdater;
protected readonly checkingForUpdateEmitter = new Emitter<void>();
protected readonly updateAvailableEmitter = new Emitter<UpdateInfo>();
protected readonly updateNotAvailableEmitter = new Emitter<UpdateInfo>();
protected readonly downloadProgressEmitter = new Emitter<ProgressInfo>();
protected readonly downloadFinishedEmitter = new Emitter<UpdateInfo>();
protected readonly errorEmitter = new Emitter<Error>();
readonly onCheckingForUpdate = this.checkingForUpdateEmitter.event;
readonly onUpdateAvailable = this.updateAvailableEmitter.event;
readonly onUpdateNotAvailable = this.updateNotAvailableEmitter.event;
readonly onDownloadProgressChanged = this.downloadProgressEmitter.event;
readonly onDownloadFinished = this.downloadFinishedEmitter.event;
readonly onError = this.errorEmitter.event;
constructor() {
const options: AllPublishOptions = {
provider: "s3",
bucket: "",
region: "",
acl: "public-read",
endpoint: "https://{service}.{region}.amazonaws.com",
channel: "",
}
// TODO: Search S3 bucket name for the two channels
// https://downloads.arduino.cc/arduino-ide/arduino-ide_2.0.0-rc2_Linux_64bit.zip
// https://downloads.arduino.cc/arduino-ide/nightly/arduino-ide_nightly-latest_Linux_64bit.zip
if (process.platform === "win32") {
this.updater = new NsisUpdater(options)
} else if (process.platform === "darwin") {
this.updater = new MacUpdater(options)
} else {
this.updater = new AppImageUpdater(options)
}
this.updater.autoDownload = false;
this.updater.on("checking-for-update", this.checkingForUpdateEmitter.fire);
this.updater.on("update-available", this.updateAvailableEmitter.fire);
this.updater.on("update-not-available", this.updateNotAvailableEmitter.fire);
this.updater.on("download-progress", this.downloadFinishedEmitter.fire);
this.updater.on("update-downloaded", this.downloadFinishedEmitter.fire);
this.updater.on("error", this.errorEmitter.fire);
}
checkForUpdates() {
this.updater.checkForUpdates();
}
downloadUpdate(cancellationToken?: CancellationToken) {
this.updater.downloadUpdate(cancellationToken);
}
quitAndInstall() {
this.updater.quitAndInstall();
}
}