Skip to content

Commit e5789b6

Browse files
author
Alberto Iannaccone
committed
Automatically check for updates only once
1 parent 481497e commit e5789b6

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export class ArduinoFrontendContribution
282282
this.updaterService.init(
283283
this.arduinoPreferences.get('arduino.ide.updateChannel')
284284
);
285-
this.updater.checkForUpdates().then(async (updateInfo) => {
285+
this.updater.checkForUpdates(true).then(async (updateInfo) => {
286286
if (!updateInfo) return;
287287
const versionToSkip = await this.localStorageService.getData<string>(
288288
SKIP_IDE_VERSION

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export class IDEUpdaterCommands implements CommandContribution {
3131
});
3232
}
3333

34-
async checkForUpdates(): Promise<UpdateInfo | void> {
35-
return await this.updater.checkForUpdates();
34+
async checkForUpdates(initialCheck?: boolean): Promise<UpdateInfo | void> {
35+
return await this.updater.checkForUpdates(initialCheck);
3636
}
3737

3838
async downloadUpdate(): Promise<void> {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const IDEUpdaterPath = '/services/ide-updater';
4747
export const IDEUpdater = Symbol('IDEUpdater');
4848
export interface IDEUpdater extends JsonRpcServer<IDEUpdaterClient> {
4949
init(channel: UpdateChannel): void;
50-
checkForUpdates(): Promise<UpdateInfo | void>;
50+
checkForUpdates(initialCheck?: boolean): Promise<UpdateInfo | void>;
5151
downloadUpdate(): Promise<void>;
5252
quitAndInstall(): void;
5353
stopDownload(): void;

arduino-ide-extension/src/electron-main/ide-updater/ide-updater-impl.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ const IDE_DOWNLOAD_BASE_URL = 'https://downloads.arduino.cc/arduino-ide';
1212

1313
@injectable()
1414
export class IDEUpdaterImpl implements IDEUpdater {
15+
private isAlreadyChecked = false;
1516
private updater = autoUpdater;
1617
private cancellationToken?: CancellationToken;
1718
protected theiaFEClient?: IDEUpdaterClient;
1819
protected clients: Array<IDEUpdaterClient> = [];
1920

20-
init(channel: UpdateChannel) {
21+
init(channel: UpdateChannel): void {
2122
this.updater.autoDownload = false;
2223
this.updater.channel = channel;
2324
this.updater.setFeedURL({
@@ -52,9 +53,16 @@ export class IDEUpdaterImpl implements IDEUpdater {
5253
if (client) this.clients.push(client);
5354
}
5455

55-
async checkForUpdates(): Promise<UpdateInfo | void> {
56-
const { updateInfo, cancellationToken } =
57-
await this.updater.checkForUpdates();
56+
async checkForUpdates(initialCheck?: boolean): Promise<UpdateInfo | void> {
57+
if (initialCheck) {
58+
if (this.isAlreadyChecked) return Promise.resolve();
59+
this.isAlreadyChecked = true;
60+
}
61+
62+
const {
63+
updateInfo,
64+
cancellationToken,
65+
} = await this.updater.checkForUpdates();
5866

5967
this.cancellationToken = cancellationToken;
6068
if (this.updater.currentVersion.compare(updateInfo.version) === -1) {

0 commit comments

Comments
 (0)