diff --git a/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx b/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx index af90e2035..d9e65fd48 100644 --- a/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx +++ b/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx @@ -68,7 +68,6 @@ import { ArduinoPreferences } from './arduino-preferences'; import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl'; import { SaveAsSketch } from './contributions/save-as-sketch'; import { SketchbookWidgetContribution } from './widgets/sketchbook/sketchbook-widget-contribution'; -import { IDEUpdaterCommands } from './ide-updater/ide-updater-commands'; import { IDEUpdaterDialog } from './dialogs/ide-updater/ide-updater-dialog'; import { IDEUpdater } from '../common/protocol/ide-updater'; @@ -160,15 +159,12 @@ export class ArduinoFrontendContribution @inject(LocalStorageService) protected readonly localStorageService: LocalStorageService; - @inject(IDEUpdaterCommands) - protected readonly updater: IDEUpdaterCommands; + @inject(IDEUpdater) + protected readonly updater: IDEUpdater; @inject(IDEUpdaterDialog) protected readonly updaterDialog: IDEUpdaterDialog; - @inject(IDEUpdater) - protected readonly updaterService: IDEUpdater; - protected invalidConfigPopup: | Promise | undefined; @@ -279,18 +275,29 @@ export class ArduinoFrontendContribution } } - this.updaterService.init( - this.arduinoPreferences.get('arduino.ide.updateChannel'), - this.arduinoPreferences.get('arduino.ide.updateBaseUrl') - ); - this.updater.checkForUpdates(true).then(async (updateInfo) => { - if (!updateInfo) return; - const versionToSkip = await this.localStorageService.getData( - SKIP_IDE_VERSION - ); - if (versionToSkip === updateInfo.version) return; - this.updaterDialog.open(updateInfo); - }); + this.updater + .init( + this.arduinoPreferences.get('arduino.ide.updateChannel'), + this.arduinoPreferences.get('arduino.ide.updateBaseUrl') + ) + .then(() => this.updater.checkForUpdates(true)) + .then(async (updateInfo) => { + if (!updateInfo) return; + const versionToSkip = await this.localStorageService.getData( + SKIP_IDE_VERSION + ); + if (versionToSkip === updateInfo.version) return; + this.updaterDialog.open(updateInfo); + }) + .catch((e) => { + this.messageService.error( + nls.localize( + 'arduino/ide-updater/errorCheckingForUpdates', + 'Error while checking for Arduino IDE updates.\n{0}', + e.message + ) + ); + }); const start = async ({ selectedBoard }: BoardsConfig.Config) => { if (selectedBoard) { @@ -302,11 +309,25 @@ export class ArduinoFrontendContribution }; this.boardsServiceClientImpl.onBoardsConfigChanged(start); this.arduinoPreferences.onPreferenceChanged((event) => { - if ( - event.preferenceName === 'arduino.language.log' && - event.newValue !== event.oldValue - ) { - start(this.boardsServiceClientImpl.boardsConfig); + if (event.newValue !== event.oldValue) { + switch (event.preferenceName) { + case 'arduino.language.log': + start(this.boardsServiceClientImpl.boardsConfig); + break; + case 'arduino.window.zoomLevel': + if (typeof event.newValue === 'number') { + const webContents = remote.getCurrentWebContents(); + webContents.setZoomLevel(event.newValue || 0); + } + break; + case 'arduino.ide.updateChannel': + case 'arduino.ide.updateBaseUrl': + this.updater.init( + this.arduinoPreferences.get('arduino.ide.updateChannel'), + this.arduinoPreferences.get('arduino.ide.updateBaseUrl') + ); + break; + } } }); this.arduinoPreferences.ready.then(() => { @@ -314,16 +335,7 @@ export class ArduinoFrontendContribution const zoomLevel = this.arduinoPreferences.get('arduino.window.zoomLevel'); webContents.setZoomLevel(zoomLevel); }); - this.arduinoPreferences.onPreferenceChanged((event) => { - if ( - event.preferenceName === 'arduino.window.zoomLevel' && - typeof event.newValue === 'number' && - event.newValue !== event.oldValue - ) { - const webContents = remote.getCurrentWebContents(); - webContents.setZoomLevel(event.newValue || 0); - } - }); + app.shell.leftPanelHandler.removeBottomMenu('settings-menu'); } diff --git a/arduino-ide-extension/src/browser/contributions/help.ts b/arduino-ide-extension/src/browser/contributions/help.ts index 51cbd4a2a..f25c4ba89 100644 --- a/arduino-ide-extension/src/browser/contributions/help.ts +++ b/arduino-ide-extension/src/browser/contributions/help.ts @@ -13,6 +13,7 @@ import { KeybindingRegistry, } from './contribution'; import { nls } from '@theia/core/lib/common'; +import { IDEUpdaterCommands } from '../ide-updater/ide-updater-commands'; @injectable() export class Help extends Contribution { @@ -115,6 +116,10 @@ export class Help extends Contribution { commandId: Help.Commands.VISIT_ARDUINO.id, order: '6', }); + registry.registerMenuAction(ArduinoMenus.HELP__FIND_GROUP, { + commandId: IDEUpdaterCommands.CHECK_FOR_UPDATES.id, + order: '7', + }); } registerKeybindings(registry: KeybindingRegistry): void { diff --git a/arduino-ide-extension/src/browser/dialogs/ide-updater/ide-updater-component.tsx b/arduino-ide-extension/src/browser/dialogs/ide-updater/ide-updater-component.tsx index 0d2fa3a49..d8b94bd94 100644 --- a/arduino-ide-extension/src/browser/dialogs/ide-updater/ide-updater-component.tsx +++ b/arduino-ide-extension/src/browser/dialogs/ide-updater/ide-updater-component.tsx @@ -205,7 +205,6 @@ export const IDEUpdaterComponent = ({ ) : ( )} - {/* {!!error &&
{error}
} */} ); }; diff --git a/arduino-ide-extension/src/browser/dialogs/ide-updater/ide-updater-dialog.tsx b/arduino-ide-extension/src/browser/dialogs/ide-updater/ide-updater-dialog.tsx index dbba6df96..97642b39d 100644 --- a/arduino-ide-extension/src/browser/dialogs/ide-updater/ide-updater-dialog.tsx +++ b/arduino-ide-extension/src/browser/dialogs/ide-updater/ide-updater-dialog.tsx @@ -7,8 +7,9 @@ import { Message } from '@phosphor/messaging'; import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget'; import { nls } from '@theia/core'; import { IDEUpdaterComponent } from './ide-updater-component'; -import { IDEUpdaterCommands } from '../../ide-updater/ide-updater-commands'; + import { + IDEUpdater, IDEUpdaterClient, ProgressInfo, UpdateInfo, @@ -27,8 +28,8 @@ export class IDEUpdaterDialogWidget extends ReactWidget { downloadStarted: boolean; onClose: () => void; - @inject(IDEUpdaterCommands) - protected readonly updater: IDEUpdaterCommands; + @inject(IDEUpdater) + protected readonly updater: IDEUpdater; @inject(IDEUpdaterClient) protected readonly updaterClient: IDEUpdaterClient; @@ -125,7 +126,7 @@ export class IDEUpdaterDialog extends AbstractDialog { ) { super({ title: nls.localize( - 'arduino/updater/ideUpdaterDialog', + 'arduino/ide-updater/ideUpdaterDialog', 'Software Update' ), }); diff --git a/arduino-ide-extension/src/browser/ide-updater/ide-updater-commands.ts b/arduino-ide-extension/src/browser/ide-updater/ide-updater-commands.ts index 3e67514f0..3a6f0ed45 100644 --- a/arduino-ide-extension/src/browser/ide-updater/ide-updater-commands.ts +++ b/arduino-ide-extension/src/browser/ide-updater/ide-updater-commands.ts @@ -3,9 +3,11 @@ import { CommandContribution, CommandRegistry, MessageService, + nls, } from '@theia/core'; import { injectable, inject } from 'inversify'; import { IDEUpdater, UpdateInfo } from '../../common/protocol/ide-updater'; +import { IDEUpdaterDialog } from '../dialogs/ide-updater/ide-updater-dialog'; @injectable() export class IDEUpdaterCommands implements CommandContribution { @@ -13,38 +15,40 @@ export class IDEUpdaterCommands implements CommandContribution { @inject(IDEUpdater) private readonly updater: IDEUpdater, @inject(MessageService) - protected readonly messageService: MessageService + protected readonly messageService: MessageService, + @inject(IDEUpdaterDialog) + protected readonly updaterDialog: IDEUpdaterDialog ) {} registerCommands(registry: CommandRegistry): void { registry.registerCommand(IDEUpdaterCommands.CHECK_FOR_UPDATES, { execute: this.checkForUpdates.bind(this), }); - registry.registerCommand(IDEUpdaterCommands.DOWNLOAD_UPDATE, { - execute: this.downloadUpdate.bind(this), - }); - registry.registerCommand(IDEUpdaterCommands.STOP_DOWNLOAD, { - execute: this.stopDownload.bind(this), - }); - registry.registerCommand(IDEUpdaterCommands.INSTALL_UPDATE, { - execute: this.quitAndInstall.bind(this), - }); } async checkForUpdates(initialCheck?: boolean): Promise { - return await this.updater.checkForUpdates(initialCheck); - } - - async downloadUpdate(): Promise { - await this.updater.downloadUpdate(); - } - - async stopDownload(): Promise { - await this.updater.stopDownload(); - } - - quitAndInstall(): void { - this.updater.quitAndInstall(); + try { + const updateInfo = await this.updater.checkForUpdates(initialCheck); + if (!!updateInfo) { + this.updaterDialog.open(updateInfo); + } else { + this.messageService.info( + nls.localize( + 'arduino/ide-updater/noUpdatesAvailable', + 'There are no recent updates available for the Arduino IDE' + ) + ); + } + return updateInfo; + } catch (e) { + this.messageService.error( + nls.localize( + 'arduino/ide-updater/errorCheckingForUpdates', + 'Error while checking for Arduino IDE updates.\n{0}', + e.message + ) + ); + } } } export namespace IDEUpdaterCommands { @@ -53,19 +57,4 @@ export namespace IDEUpdaterCommands { category: 'Arduino', label: 'Check for Arduino IDE updates', }; - export const DOWNLOAD_UPDATE: Command = { - id: 'arduino-ide-download-update', - category: 'Arduino', - label: 'Download Arduino IDE updates', - }; - export const STOP_DOWNLOAD: Command = { - id: 'arduino-ide-stop-download', - category: 'Arduino', - label: 'Stop download of Arduino IDE updates', - }; - export const INSTALL_UPDATE: Command = { - id: 'arduino-ide-install-update', - category: 'Arduino', - label: 'Install Arduino IDE updates', - }; } diff --git a/arduino-ide-extension/src/common/protocol/ide-updater.ts b/arduino-ide-extension/src/common/protocol/ide-updater.ts index 92226398c..7af4f7cb7 100644 --- a/arduino-ide-extension/src/common/protocol/ide-updater.ts +++ b/arduino-ide-extension/src/common/protocol/ide-updater.ts @@ -46,7 +46,7 @@ export interface ProgressInfo { export const IDEUpdaterPath = '/services/ide-updater'; export const IDEUpdater = Symbol('IDEUpdater'); export interface IDEUpdater extends JsonRpcServer { - init(channel: UpdateChannel, baseUrl: string): void; + init(channel: UpdateChannel, baseUrl: string): Promise; checkForUpdates(initialCheck?: boolean): Promise; downloadUpdate(): Promise; quitAndInstall(): void; diff --git a/arduino-ide-extension/src/electron-main/ide-updater/ide-updater-impl.ts b/arduino-ide-extension/src/electron-main/ide-updater/ide-updater-impl.ts index 3a0627546..a87536a48 100644 --- a/arduino-ide-extension/src/electron-main/ide-updater/ide-updater-impl.ts +++ b/arduino-ide-extension/src/electron-main/ide-updater/ide-updater-impl.ts @@ -17,15 +17,7 @@ export class IDEUpdaterImpl implements IDEUpdater { protected theiaFEClient?: IDEUpdaterClient; protected clients: Array = []; - init(channel: UpdateChannel, baseUrl: string): void { - this.updater.autoDownload = false; - this.updater.channel = channel; - this.updater.setFeedURL({ - provider: 'generic', - url: `${baseUrl}/${channel === UpdateChannel.Nightly ? 'nightly' : ''}`, - channel, - }); - + constructor() { this.updater.on('checking-for-update', (e) => { this.clients.forEach((c) => c.notifyCheckingForUpdate(e)); }); @@ -46,6 +38,16 @@ export class IDEUpdaterImpl implements IDEUpdater { }); } + async init(channel: UpdateChannel, baseUrl: string): Promise { + this.updater.autoDownload = false; + this.updater.channel = channel; + this.updater.setFeedURL({ + provider: 'generic', + url: `${baseUrl}/${channel === UpdateChannel.Nightly ? 'nightly' : ''}`, + channel, + }); + } + setClient(client: IDEUpdaterClient | undefined): void { if (client) this.clients.push(client); } diff --git a/i18n/en.json b/i18n/en.json index c3c20371f..b122e18d6 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -14,6 +14,22 @@ "saveChangesToSketch": "Do you want to save changes to this sketch before closing?", "loseChanges": "If you don't save, your changes will be lost." }, + "ide-updater": { + "errorCheckingForUpdates": "Error while checking for Arduino IDE updates.\n{0}", + "notNowButton": "Not now", + "versionDownloaded": "Arduino IDE {0} has been downloaded.", + "closeToInstallNotice": "Close the software and install the update on your machine.", + "closeAndInstallButton": "Close and Install", + "downloadingNotice": "Downloading the latest version of the Arduino IDE.", + "updateAvailable": "Update Available", + "newVersionAvailable": "A new version of Arduino IDE ({0}) is available for download.", + "skipVersionButton": "Skip Version", + "downloadButton": "Download", + "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.", + "goToDownloadButton": "Go To Download", + "ideUpdaterDialog": "Software Update", + "noUpdatesAvailable": "There are no recent updates available for the Arduino IDE" + }, "menu": { "sketch": "Sketch", "tools": "Tools" @@ -255,22 +271,6 @@ "dialog": { "dontAskAgain": "Don't ask again" }, - "ide-updater": { - "notNowButton": "Not now", - "versionDownloaded": "Arduino IDE {0} has been downloaded.", - "closeToInstallNotice": "Close the software and install the update on your machine.", - "closeAndInstallButton": "Close and Install", - "downloadingNotice": "Downloading the latest version of the Arduino IDE.", - "updateAvailable": "Update Available", - "newVersionAvailable": "A new version of Arduino IDE ({0}) is available for download.", - "skipVersionButton": "Skip Version", - "downloadButton": "Download", - "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.", - "goToDownloadButton": "Go To Download" - }, - "updater": { - "ideUpdaterDialog": "Software Update" - }, "userFields": { "cancel": "Cancel", "upload": "Upload"