Skip to content

Commit fcb8f6e

Browse files
author
Alberto Iannaccone
committed
TMP check updates on start and download
1 parent 343925c commit fcb8f6e

File tree

6 files changed

+46
-20
lines changed

6 files changed

+46
-20
lines changed

arduino-ide-extension/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +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",
66+
"electron-updater": "^4.6.2",
6767
"fuzzy": "^0.1.3",
6868
"glob": "^7.1.6",
6969
"google-protobuf": "^3.11.4",

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import { ArduinoPreferences } from './arduino-preferences';
6969
import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl';
7070
import { SaveAsSketch } from './contributions/save-as-sketch';
7171
import { SketchbookWidgetContribution } from './widgets/sketchbook/sketchbook-widget-contribution';
72+
import { IDEUpdaterCommands } from './ide-updater/ide-updater-commands';
7273

7374
const INIT_LIBS_AND_PACKAGES = 'initializedLibsAndPackages';
7475

@@ -158,6 +159,9 @@ export class ArduinoFrontendContribution
158159
@inject(LocalStorageService)
159160
protected readonly localStorageService: LocalStorageService;
160161

162+
@inject(IDEUpdaterCommands)
163+
protected readonly updater: IDEUpdaterCommands;
164+
161165
protected invalidConfigPopup:
162166
| Promise<void | 'No' | 'Yes' | undefined>
163167
| undefined;
@@ -267,6 +271,22 @@ export class ArduinoFrontendContribution
267271
viewContribution.initializeLayout(app);
268272
}
269273
}
274+
275+
this.updater.checkForUpdates().then((updateInfo) => {
276+
if (!updateInfo) return;
277+
this.messageService
278+
.info(
279+
`new version available: ${updateInfo.version}`,
280+
'ok install it',
281+
'nope, thanks'
282+
)
283+
.then((result) => {
284+
if (result === 'ok install it') {
285+
this.updater.downloadUpdate();
286+
}
287+
});
288+
});
289+
270290
const start = async ({ selectedBoard }: BoardsConfig.Config) => {
271291
if (selectedBoard) {
272292
const { name, fqbn } = selectedBoard;

arduino-ide-extension/src/browser/ide-updater/ide-updater-commands.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import {
55
MessageService,
66
} from '@theia/core';
77
import { injectable, inject } from 'inversify';
8-
import { IDEUpdaterService } from '../../common/protocol/ide-updater-service';
8+
import {
9+
IDEUpdaterService,
10+
UpdateInfo,
11+
} from '../../common/protocol/ide-updater-service';
912

1013
@injectable()
1114
export class IDEUpdaterCommands implements CommandContribution {
@@ -31,9 +34,8 @@ export class IDEUpdaterCommands implements CommandContribution {
3134
});
3235
}
3336

34-
async checkForUpdates() {
35-
const info = await this.updater.checkForUpdates();
36-
this.messageService.info(`version ${info.version} available`);
37+
async checkForUpdates(): Promise<UpdateInfo | void> {
38+
return await this.updater.checkForUpdates();
3739
}
3840

3941
downloadUpdate() {

arduino-ide-extension/src/common/protocol/ide-updater-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const IDEUpdaterServicePath = '/services/ide-updater';
3838
export const IDEUpdaterService = Symbol('IDEUpdaterService');
3939
export interface IDEUpdaterService
4040
extends JsonRpcServer<IDEUpdaterServiceClient> {
41-
checkForUpdates(): Promise<UpdateInfo>;
41+
checkForUpdates(): Promise<UpdateInfo | void>;
4242
downloadUpdate(): Promise<void>;
4343
quitAndInstall(): void;
4444
stopDownload(): void;

arduino-ide-extension/src/node/ide-updater/ide-updater-service-impl.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export class IDEUpdaterServiceImpl implements IDEUpdaterService {
2727
channel: 'beta',
2828
};
2929

30-
this.cancellationToken = new CancellationToken();
3130
if (process.platform === 'win32') {
3231
this.updater = new NsisUpdater(options);
3332
} else if (process.platform === 'darwin') {
@@ -63,13 +62,18 @@ export class IDEUpdaterServiceImpl implements IDEUpdaterService {
6362
throw new Error('Method not implemented.');
6463
}
6564

66-
async checkForUpdates(): Promise<UpdateInfo> {
67-
const { updateInfo } = await this.updater.checkForUpdates();
68-
return updateInfo;
65+
async checkForUpdates(): Promise<UpdateInfo | void> {
66+
const { updateInfo, cancellationToken } =
67+
await this.updater.checkForUpdates();
68+
this.cancellationToken = cancellationToken;
69+
if (this.updater.currentVersion.compare(updateInfo.version) === -1) {
70+
return updateInfo;
71+
}
6972
}
7073

7174
async downloadUpdate(): Promise<void> {
72-
await this.updater.downloadUpdate(this.cancellationToken);
75+
const result = await this.updater.downloadUpdate(this.cancellationToken);
76+
return result;
7377
}
7478

7579
stopDownload(): void {

yarn.lock

+9-9
Original file line numberDiff line numberDiff line change
@@ -4656,10 +4656,10 @@ buffers@~0.1.1:
46564656
resolved "https://registry.yarnpkg.com/buffers/-/buffers-0.1.1.tgz#b24579c3bed4d6d396aeee6d9a8ae7f5482ab7bb"
46574657
integrity sha1-skV5w77U1tOWru5tmorn9Ugqt7s=
46584658

4659-
4660-
version "8.9.1"
4661-
resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-8.9.1.tgz#25f066b3fbc20b3e6236a9b956b1ebb0e33ff66a"
4662-
integrity sha512-c8a8J3wK6BIVLW7ls+7TRK9igspTbzWmUqxFbgK0m40Ggm6efUbxtWVCGIjc+dtchyr5qAMAUL6iEGRdS/6vwg==
4659+
4660+
version "8.9.2"
4661+
resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-8.9.2.tgz#a9669ae5b5dcabfe411ded26678e7ae997246c28"
4662+
integrity sha512-rhuKm5vh7E0aAmT6i8aoSfEjxzdYEFX7zDApK+eNgOhjofnWb74d9SRJv0H/8nsgOkos0TZ4zxW0P8J4N7xQ2A==
46634663
dependencies:
46644664
debug "^4.3.2"
46654665
sax "^1.2.4"
@@ -6309,13 +6309,13 @@ electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.649:
63096309
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.695.tgz#955f419cf99137226180cc4cca2e59015a4e248d"
63106310
integrity sha512-lz66RliUqLHU1Ojxx1A4QUxKydjiQ79Y4dZyPobs2Dmxj5aVL2TM3KoQ2Gs7HS703Bfny+ukI3KOxwAB0xceHQ==
63116311

6312-
electron-updater@^4.6.1:
6313-
version "4.6.1"
6314-
resolved "https://registry.yarnpkg.com/electron-updater/-/electron-updater-4.6.1.tgz#80ca805c4f51b2e682aac29d18fed75d6a533d32"
6315-
integrity sha512-YsU1mHqXLrXXmBMsxhxy24PrbaB8rnpZDPmFa2gOkTYk/Ch13+R0fjsRSpPYvqtskVVY0ux8fu+HnUkVkqc7og==
6312+
electron-updater@^4.6.2:
6313+
version "4.6.5"
6314+
resolved "https://registry.yarnpkg.com/electron-updater/-/electron-updater-4.6.5.tgz#e9a75458bbfd6bb41a58a829839e150ad2eb2d3d"
6315+
integrity sha512-kdTly8O9mSZfm9fslc1mnCY+mYOeaYRy7ERa2Fed240u01BKll3aiupzkd07qKw69KvhBSzuHroIW3mF0D8DWA==
63166316
dependencies:
63176317
"@types/semver" "^7.3.6"
6318-
builder-util-runtime "8.9.1"
6318+
builder-util-runtime "8.9.2"
63196319
fs-extra "^10.0.0"
63206320
js-yaml "^4.1.0"
63216321
lazy-val "^1.0.5"

0 commit comments

Comments
 (0)