Skip to content

Commit 2061f52

Browse files
committed
Add updates check
1 parent 9a16bd3 commit 2061f52

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

arduino-ide-extension/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"css-element-queries": "^1.2.0",
6464
"dateformat": "^3.0.3",
6565
"deepmerge": "2.0.1",
66+
"electron-updater": "^4.6.1",
6667
"fuzzy": "^0.1.3",
6768
"glob": "^7.1.6",
6869
"google-protobuf": "^3.11.4",
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Command, CommandContribution, CommandRegistry } from "@theia/core";
2+
import { injectable, inject } from "inversify";
3+
import { CancellationToken } from "electron-updater";
4+
import { IDEUpdater } from "./ide-updater";
5+
6+
// IDEUpdaterCommands register commands used to verify if there
7+
// are new IDE updates, download them, and install them.
8+
@injectable()
9+
export class IDEUpdaterCommands implements CommandContribution {
10+
private readonly cancellationToken = new CancellationToken();
11+
12+
constructor(
13+
@inject(IDEUpdater) private readonly updater: IDEUpdater
14+
) {
15+
}
16+
17+
registerCommands(registry: CommandRegistry): void {
18+
registry.registerCommand(IDEUpdaterCommands.CHECK_FOR_UPDATES, {
19+
execute: this.checkForUpdates,
20+
});
21+
registry.registerCommand(IDEUpdaterCommands.DOWNLOAD_UPDATE, {
22+
execute: this.downloadUpdate,
23+
})
24+
registry.registerCommand(IDEUpdaterCommands.STOP_DOWNLOAD, {
25+
execute: this.stopDownload,
26+
})
27+
registry.registerCommand(IDEUpdaterCommands.INSTALL_UPDATE, {
28+
execute: this.quitAndInstall,
29+
})
30+
}
31+
32+
checkForUpdates() {
33+
this.updater.checkForUpdates();
34+
}
35+
36+
downloadUpdate() {
37+
this.updater.downloadUpdate(this.cancellationToken);
38+
}
39+
40+
stopDownload() {
41+
this.cancellationToken.cancel();
42+
}
43+
44+
quitAndInstall() {
45+
this.updater.quitAndInstall();
46+
}
47+
}
48+
export namespace IDEUpdaterCommands {
49+
export const CHECK_FOR_UPDATES: Command = {
50+
id: 'arduino-ide-check-for-updates',
51+
};
52+
export const DOWNLOAD_UPDATE: Command = {
53+
id: 'arduino-ide-download-update',
54+
};
55+
export const STOP_DOWNLOAD: Command = {
56+
id: 'arduino-ide-stop-download',
57+
};
58+
export const INSTALL_UPDATE: Command = {
59+
id: 'arduino-ide-install-update',
60+
};
61+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { injectable } from "@theia/core/shared/inversify";
2+
import { Emitter } from "@theia/core/shared/vscode-languageserver-protocol";
3+
import { AllPublishOptions } from "builder-util-runtime";
4+
import {
5+
AppUpdater,
6+
AppImageUpdater,
7+
MacUpdater,
8+
NsisUpdater,
9+
UpdateInfo,
10+
ProgressInfo,
11+
CancellationToken
12+
} from "electron-updater";
13+
14+
// IDEUpdater TODO docs
15+
@injectable()
16+
export class IDEUpdater {
17+
private updater: AppUpdater;
18+
19+
protected readonly checkingForUpdateEmitter = new Emitter<void>();
20+
protected readonly updateAvailableEmitter = new Emitter<UpdateInfo>();
21+
protected readonly updateNotAvailableEmitter = new Emitter<UpdateInfo>();
22+
protected readonly downloadProgressEmitter = new Emitter<ProgressInfo>();
23+
protected readonly downloadFinishedEmitter = new Emitter<UpdateInfo>();
24+
protected readonly errorEmitter = new Emitter<Error>();
25+
26+
readonly onCheckingForUpdate = this.checkingForUpdateEmitter.event;
27+
readonly onUpdateAvailable = this.updateAvailableEmitter.event;
28+
readonly onUpdateNotAvailable = this.updateNotAvailableEmitter.event;
29+
readonly onDownloadProgressChanged = this.downloadProgressEmitter.event;
30+
readonly onDownloadFinished = this.downloadFinishedEmitter.event;
31+
readonly onError = this.errorEmitter.event;
32+
33+
constructor() {
34+
const options: AllPublishOptions = {
35+
provider: "s3",
36+
bucket: "",
37+
region: "",
38+
acl: "public-read",
39+
endpoint: "https://{service}.{region}.amazonaws.com",
40+
channel: "",
41+
}
42+
// TODO: Search S3 bucket name for the two channels
43+
// https://downloads.arduino.cc/arduino-ide/arduino-ide_2.0.0-rc2_Linux_64bit.zip
44+
// https://downloads.arduino.cc/arduino-ide/nightly/arduino-ide_nightly-latest_Linux_64bit.zip
45+
46+
if (process.platform === "win32") {
47+
this.updater = new NsisUpdater(options)
48+
} else if (process.platform === "darwin") {
49+
this.updater = new MacUpdater(options)
50+
} else {
51+
this.updater = new AppImageUpdater(options)
52+
}
53+
this.updater.autoDownload = false;
54+
55+
this.updater.on("checking-for-update", this.checkingForUpdateEmitter.fire);
56+
this.updater.on("update-available", this.updateAvailableEmitter.fire);
57+
this.updater.on("update-not-available", this.updateNotAvailableEmitter.fire);
58+
this.updater.on("download-progress", this.downloadFinishedEmitter.fire);
59+
this.updater.on("update-downloaded", this.downloadFinishedEmitter.fire);
60+
this.updater.on("error", this.errorEmitter.fire);
61+
}
62+
63+
checkForUpdates() {
64+
this.updater.checkForUpdates();
65+
}
66+
67+
downloadUpdate(cancellationToken?: CancellationToken) {
68+
this.updater.downloadUpdate(cancellationToken);
69+
}
70+
71+
quitAndInstall() {
72+
this.updater.quitAndInstall();
73+
}
74+
}

0 commit comments

Comments
 (0)