Skip to content

Commit 96b5edf

Browse files
author
Alberto Iannaccone
authored
fix IDE updater commands (#872)
* fix IDE updater commands * reinitialise autoupdate when preferences change * fix typo + add i18n strings
1 parent a5a6a0b commit 96b5edf

File tree

8 files changed

+110
-102
lines changed

8 files changed

+110
-102
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+45-33
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ import { ArduinoPreferences } from './arduino-preferences';
6868
import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl';
6969
import { SaveAsSketch } from './contributions/save-as-sketch';
7070
import { SketchbookWidgetContribution } from './widgets/sketchbook/sketchbook-widget-contribution';
71-
import { IDEUpdaterCommands } from './ide-updater/ide-updater-commands';
7271
import { IDEUpdaterDialog } from './dialogs/ide-updater/ide-updater-dialog';
7372
import { IDEUpdater } from '../common/protocol/ide-updater';
7473

@@ -160,15 +159,12 @@ export class ArduinoFrontendContribution
160159
@inject(LocalStorageService)
161160
protected readonly localStorageService: LocalStorageService;
162161

163-
@inject(IDEUpdaterCommands)
164-
protected readonly updater: IDEUpdaterCommands;
162+
@inject(IDEUpdater)
163+
protected readonly updater: IDEUpdater;
165164

166165
@inject(IDEUpdaterDialog)
167166
protected readonly updaterDialog: IDEUpdaterDialog;
168167

169-
@inject(IDEUpdater)
170-
protected readonly updaterService: IDEUpdater;
171-
172168
protected invalidConfigPopup:
173169
| Promise<void | 'No' | 'Yes' | undefined>
174170
| undefined;
@@ -279,18 +275,29 @@ export class ArduinoFrontendContribution
279275
}
280276
}
281277

282-
this.updaterService.init(
283-
this.arduinoPreferences.get('arduino.ide.updateChannel'),
284-
this.arduinoPreferences.get('arduino.ide.updateBaseUrl')
285-
);
286-
this.updater.checkForUpdates(true).then(async (updateInfo) => {
287-
if (!updateInfo) return;
288-
const versionToSkip = await this.localStorageService.getData<string>(
289-
SKIP_IDE_VERSION
290-
);
291-
if (versionToSkip === updateInfo.version) return;
292-
this.updaterDialog.open(updateInfo);
293-
});
278+
this.updater
279+
.init(
280+
this.arduinoPreferences.get('arduino.ide.updateChannel'),
281+
this.arduinoPreferences.get('arduino.ide.updateBaseUrl')
282+
)
283+
.then(() => this.updater.checkForUpdates(true))
284+
.then(async (updateInfo) => {
285+
if (!updateInfo) return;
286+
const versionToSkip = await this.localStorageService.getData<string>(
287+
SKIP_IDE_VERSION
288+
);
289+
if (versionToSkip === updateInfo.version) return;
290+
this.updaterDialog.open(updateInfo);
291+
})
292+
.catch((e) => {
293+
this.messageService.error(
294+
nls.localize(
295+
'arduino/ide-updater/errorCheckingForUpdates',
296+
'Error while checking for Arduino IDE updates.\n{0}',
297+
e.message
298+
)
299+
);
300+
});
294301

295302
const start = async ({ selectedBoard }: BoardsConfig.Config) => {
296303
if (selectedBoard) {
@@ -302,28 +309,33 @@ export class ArduinoFrontendContribution
302309
};
303310
this.boardsServiceClientImpl.onBoardsConfigChanged(start);
304311
this.arduinoPreferences.onPreferenceChanged((event) => {
305-
if (
306-
event.preferenceName === 'arduino.language.log' &&
307-
event.newValue !== event.oldValue
308-
) {
309-
start(this.boardsServiceClientImpl.boardsConfig);
312+
if (event.newValue !== event.oldValue) {
313+
switch (event.preferenceName) {
314+
case 'arduino.language.log':
315+
start(this.boardsServiceClientImpl.boardsConfig);
316+
break;
317+
case 'arduino.window.zoomLevel':
318+
if (typeof event.newValue === 'number') {
319+
const webContents = remote.getCurrentWebContents();
320+
webContents.setZoomLevel(event.newValue || 0);
321+
}
322+
break;
323+
case 'arduino.ide.updateChannel':
324+
case 'arduino.ide.updateBaseUrl':
325+
this.updater.init(
326+
this.arduinoPreferences.get('arduino.ide.updateChannel'),
327+
this.arduinoPreferences.get('arduino.ide.updateBaseUrl')
328+
);
329+
break;
330+
}
310331
}
311332
});
312333
this.arduinoPreferences.ready.then(() => {
313334
const webContents = remote.getCurrentWebContents();
314335
const zoomLevel = this.arduinoPreferences.get('arduino.window.zoomLevel');
315336
webContents.setZoomLevel(zoomLevel);
316337
});
317-
this.arduinoPreferences.onPreferenceChanged((event) => {
318-
if (
319-
event.preferenceName === 'arduino.window.zoomLevel' &&
320-
typeof event.newValue === 'number' &&
321-
event.newValue !== event.oldValue
322-
) {
323-
const webContents = remote.getCurrentWebContents();
324-
webContents.setZoomLevel(event.newValue || 0);
325-
}
326-
});
338+
327339
app.shell.leftPanelHandler.removeBottomMenu('settings-menu');
328340
}
329341

Diff for: arduino-ide-extension/src/browser/contributions/help.ts

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
KeybindingRegistry,
1414
} from './contribution';
1515
import { nls } from '@theia/core/lib/common';
16+
import { IDEUpdaterCommands } from '../ide-updater/ide-updater-commands';
1617

1718
@injectable()
1819
export class Help extends Contribution {
@@ -115,6 +116,10 @@ export class Help extends Contribution {
115116
commandId: Help.Commands.VISIT_ARDUINO.id,
116117
order: '6',
117118
});
119+
registry.registerMenuAction(ArduinoMenus.HELP__FIND_GROUP, {
120+
commandId: IDEUpdaterCommands.CHECK_FOR_UPDATES.id,
121+
order: '7',
122+
});
118123
}
119124

120125
registerKeybindings(registry: KeybindingRegistry): void {

Diff for: arduino-ide-extension/src/browser/dialogs/ide-updater/ide-updater-component.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ export const IDEUpdaterComponent = ({
205205
) : (
206206
<PreDownload />
207207
)}
208-
{/* {!!error && <div className="error-container">{error}</div>} */}
209208
</div>
210209
);
211210
};

Diff for: arduino-ide-extension/src/browser/dialogs/ide-updater/ide-updater-dialog.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { Message } from '@phosphor/messaging';
77
import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget';
88
import { nls } from '@theia/core';
99
import { IDEUpdaterComponent } from './ide-updater-component';
10-
import { IDEUpdaterCommands } from '../../ide-updater/ide-updater-commands';
10+
1111
import {
12+
IDEUpdater,
1213
IDEUpdaterClient,
1314
ProgressInfo,
1415
UpdateInfo,
@@ -27,8 +28,8 @@ export class IDEUpdaterDialogWidget extends ReactWidget {
2728
downloadStarted: boolean;
2829
onClose: () => void;
2930

30-
@inject(IDEUpdaterCommands)
31-
protected readonly updater: IDEUpdaterCommands;
31+
@inject(IDEUpdater)
32+
protected readonly updater: IDEUpdater;
3233

3334
@inject(IDEUpdaterClient)
3435
protected readonly updaterClient: IDEUpdaterClient;
@@ -125,7 +126,7 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
125126
) {
126127
super({
127128
title: nls.localize(
128-
'arduino/updater/ideUpdaterDialog',
129+
'arduino/ide-updater/ideUpdaterDialog',
129130
'Software Update'
130131
),
131132
});

Diff for: arduino-ide-extension/src/browser/ide-updater/ide-updater-commands.ts

+27-38
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,52 @@ import {
33
CommandContribution,
44
CommandRegistry,
55
MessageService,
6+
nls,
67
} from '@theia/core';
78
import { injectable, inject } from 'inversify';
89
import { IDEUpdater, UpdateInfo } from '../../common/protocol/ide-updater';
10+
import { IDEUpdaterDialog } from '../dialogs/ide-updater/ide-updater-dialog';
911

1012
@injectable()
1113
export class IDEUpdaterCommands implements CommandContribution {
1214
constructor(
1315
@inject(IDEUpdater)
1416
private readonly updater: IDEUpdater,
1517
@inject(MessageService)
16-
protected readonly messageService: MessageService
18+
protected readonly messageService: MessageService,
19+
@inject(IDEUpdaterDialog)
20+
protected readonly updaterDialog: IDEUpdaterDialog
1721
) {}
1822

1923
registerCommands(registry: CommandRegistry): void {
2024
registry.registerCommand(IDEUpdaterCommands.CHECK_FOR_UPDATES, {
2125
execute: this.checkForUpdates.bind(this),
2226
});
23-
registry.registerCommand(IDEUpdaterCommands.DOWNLOAD_UPDATE, {
24-
execute: this.downloadUpdate.bind(this),
25-
});
26-
registry.registerCommand(IDEUpdaterCommands.STOP_DOWNLOAD, {
27-
execute: this.stopDownload.bind(this),
28-
});
29-
registry.registerCommand(IDEUpdaterCommands.INSTALL_UPDATE, {
30-
execute: this.quitAndInstall.bind(this),
31-
});
3227
}
3328

3429
async checkForUpdates(initialCheck?: boolean): Promise<UpdateInfo | void> {
35-
return await this.updater.checkForUpdates(initialCheck);
36-
}
37-
38-
async downloadUpdate(): Promise<void> {
39-
await this.updater.downloadUpdate();
40-
}
41-
42-
async stopDownload(): Promise<void> {
43-
await this.updater.stopDownload();
44-
}
45-
46-
quitAndInstall(): void {
47-
this.updater.quitAndInstall();
30+
try {
31+
const updateInfo = await this.updater.checkForUpdates(initialCheck);
32+
if (!!updateInfo) {
33+
this.updaterDialog.open(updateInfo);
34+
} else {
35+
this.messageService.info(
36+
nls.localize(
37+
'arduino/ide-updater/noUpdatesAvailable',
38+
'There are no recent updates available for the Arduino IDE'
39+
)
40+
);
41+
}
42+
return updateInfo;
43+
} catch (e) {
44+
this.messageService.error(
45+
nls.localize(
46+
'arduino/ide-updater/errorCheckingForUpdates',
47+
'Error while checking for Arduino IDE updates.\n{0}',
48+
e.message
49+
)
50+
);
51+
}
4852
}
4953
}
5054
export namespace IDEUpdaterCommands {
@@ -53,19 +57,4 @@ export namespace IDEUpdaterCommands {
5357
category: 'Arduino',
5458
label: 'Check for Arduino IDE updates',
5559
};
56-
export const DOWNLOAD_UPDATE: Command = {
57-
id: 'arduino-ide-download-update',
58-
category: 'Arduino',
59-
label: 'Download Arduino IDE updates',
60-
};
61-
export const STOP_DOWNLOAD: Command = {
62-
id: 'arduino-ide-stop-download',
63-
category: 'Arduino',
64-
label: 'Stop download of Arduino IDE updates',
65-
};
66-
export const INSTALL_UPDATE: Command = {
67-
id: 'arduino-ide-install-update',
68-
category: 'Arduino',
69-
label: 'Install Arduino IDE updates',
70-
};
7160
}

Diff for: arduino-ide-extension/src/common/protocol/ide-updater.ts

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

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

+11-9
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,7 @@ export class IDEUpdaterImpl implements IDEUpdater {
1717
protected theiaFEClient?: IDEUpdaterClient;
1818
protected clients: Array<IDEUpdaterClient> = [];
1919

20-
init(channel: UpdateChannel, baseUrl: string): void {
21-
this.updater.autoDownload = false;
22-
this.updater.channel = channel;
23-
this.updater.setFeedURL({
24-
provider: 'generic',
25-
url: `${baseUrl}/${channel === UpdateChannel.Nightly ? 'nightly' : ''}`,
26-
channel,
27-
});
28-
20+
constructor() {
2921
this.updater.on('checking-for-update', (e) => {
3022
this.clients.forEach((c) => c.notifyCheckingForUpdate(e));
3123
});
@@ -46,6 +38,16 @@ export class IDEUpdaterImpl implements IDEUpdater {
4638
});
4739
}
4840

41+
async init(channel: UpdateChannel, baseUrl: string): Promise<void> {
42+
this.updater.autoDownload = false;
43+
this.updater.channel = channel;
44+
this.updater.setFeedURL({
45+
provider: 'generic',
46+
url: `${baseUrl}/${channel === UpdateChannel.Nightly ? 'nightly' : ''}`,
47+
channel,
48+
});
49+
}
50+
4951
setClient(client: IDEUpdaterClient | undefined): void {
5052
if (client) this.clients.push(client);
5153
}

Diff for: i18n/en.json

+16-16
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@
1414
"saveChangesToSketch": "Do you want to save changes to this sketch before closing?",
1515
"loseChanges": "If you don't save, your changes will be lost."
1616
},
17+
"ide-updater": {
18+
"errorCheckingForUpdates": "Error while checking for Arduino IDE updates.\n{0}",
19+
"notNowButton": "Not now",
20+
"versionDownloaded": "Arduino IDE {0} has been downloaded.",
21+
"closeToInstallNotice": "Close the software and install the update on your machine.",
22+
"closeAndInstallButton": "Close and Install",
23+
"downloadingNotice": "Downloading the latest version of the Arduino IDE.",
24+
"updateAvailable": "Update Available",
25+
"newVersionAvailable": "A new version of Arduino IDE ({0}) is available for download.",
26+
"skipVersionButton": "Skip Version",
27+
"downloadButton": "Download",
28+
"goToDownloadPage": "An update for the Arduino IDE is available, but we're not able to download and install it automatically. Please go to the download page and download the latest version from there.",
29+
"goToDownloadButton": "Go To Download",
30+
"ideUpdaterDialog": "Software Update",
31+
"noUpdatesAvailable": "There are no recent updates available for the Arduino IDE"
32+
},
1733
"menu": {
1834
"sketch": "Sketch",
1935
"tools": "Tools"
@@ -255,22 +271,6 @@
255271
"dialog": {
256272
"dontAskAgain": "Don't ask again"
257273
},
258-
"ide-updater": {
259-
"notNowButton": "Not now",
260-
"versionDownloaded": "Arduino IDE {0} has been downloaded.",
261-
"closeToInstallNotice": "Close the software and install the update on your machine.",
262-
"closeAndInstallButton": "Close and Install",
263-
"downloadingNotice": "Downloading the latest version of the Arduino IDE.",
264-
"updateAvailable": "Update Available",
265-
"newVersionAvailable": "A new version of Arduino IDE ({0}) is available for download.",
266-
"skipVersionButton": "Skip Version",
267-
"downloadButton": "Download",
268-
"goToDownloadPage": "An update for the Arduino IDE is available, but we're not able to download and install it automatically. Please go to the download page and download the latest version from there.",
269-
"goToDownloadButton": "Go To Download"
270-
},
271-
"updater": {
272-
"ideUpdaterDialog": "Software Update"
273-
},
274274
"userFields": {
275275
"cancel": "Cancel",
276276
"upload": "Upload"

0 commit comments

Comments
 (0)