fix IDE updater commands (#872)

* fix IDE updater commands

* reinitialise autoupdate when preferences change

* fix typo + add i18n strings
This commit is contained in:
Alberto Iannaccone 2022-03-01 16:34:43 +00:00 committed by GitHub
parent a5a6a0b611
commit 96b5edf427
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 110 additions and 102 deletions

View File

@ -68,7 +68,6 @@ import { ArduinoPreferences } from './arduino-preferences';
import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl'; import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl';
import { SaveAsSketch } from './contributions/save-as-sketch'; import { SaveAsSketch } from './contributions/save-as-sketch';
import { SketchbookWidgetContribution } from './widgets/sketchbook/sketchbook-widget-contribution'; 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 { IDEUpdaterDialog } from './dialogs/ide-updater/ide-updater-dialog';
import { IDEUpdater } from '../common/protocol/ide-updater'; import { IDEUpdater } from '../common/protocol/ide-updater';
@ -160,15 +159,12 @@ export class ArduinoFrontendContribution
@inject(LocalStorageService) @inject(LocalStorageService)
protected readonly localStorageService: LocalStorageService; protected readonly localStorageService: LocalStorageService;
@inject(IDEUpdaterCommands) @inject(IDEUpdater)
protected readonly updater: IDEUpdaterCommands; protected readonly updater: IDEUpdater;
@inject(IDEUpdaterDialog) @inject(IDEUpdaterDialog)
protected readonly updaterDialog: IDEUpdaterDialog; protected readonly updaterDialog: IDEUpdaterDialog;
@inject(IDEUpdater)
protected readonly updaterService: IDEUpdater;
protected invalidConfigPopup: protected invalidConfigPopup:
| Promise<void | 'No' | 'Yes' | undefined> | Promise<void | 'No' | 'Yes' | undefined>
| undefined; | undefined;
@ -279,18 +275,29 @@ export class ArduinoFrontendContribution
} }
} }
this.updaterService.init( this.updater
this.arduinoPreferences.get('arduino.ide.updateChannel'), .init(
this.arduinoPreferences.get('arduino.ide.updateBaseUrl') this.arduinoPreferences.get('arduino.ide.updateChannel'),
); this.arduinoPreferences.get('arduino.ide.updateBaseUrl')
this.updater.checkForUpdates(true).then(async (updateInfo) => { )
if (!updateInfo) return; .then(() => this.updater.checkForUpdates(true))
const versionToSkip = await this.localStorageService.getData<string>( .then(async (updateInfo) => {
SKIP_IDE_VERSION if (!updateInfo) return;
); const versionToSkip = await this.localStorageService.getData<string>(
if (versionToSkip === updateInfo.version) return; SKIP_IDE_VERSION
this.updaterDialog.open(updateInfo); );
}); 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) => { const start = async ({ selectedBoard }: BoardsConfig.Config) => {
if (selectedBoard) { if (selectedBoard) {
@ -302,11 +309,25 @@ export class ArduinoFrontendContribution
}; };
this.boardsServiceClientImpl.onBoardsConfigChanged(start); this.boardsServiceClientImpl.onBoardsConfigChanged(start);
this.arduinoPreferences.onPreferenceChanged((event) => { this.arduinoPreferences.onPreferenceChanged((event) => {
if ( if (event.newValue !== event.oldValue) {
event.preferenceName === 'arduino.language.log' && switch (event.preferenceName) {
event.newValue !== event.oldValue case 'arduino.language.log':
) { start(this.boardsServiceClientImpl.boardsConfig);
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(() => { this.arduinoPreferences.ready.then(() => {
@ -314,16 +335,7 @@ export class ArduinoFrontendContribution
const zoomLevel = this.arduinoPreferences.get('arduino.window.zoomLevel'); const zoomLevel = this.arduinoPreferences.get('arduino.window.zoomLevel');
webContents.setZoomLevel(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'); app.shell.leftPanelHandler.removeBottomMenu('settings-menu');
} }

View File

@ -13,6 +13,7 @@ import {
KeybindingRegistry, KeybindingRegistry,
} from './contribution'; } from './contribution';
import { nls } from '@theia/core/lib/common'; import { nls } from '@theia/core/lib/common';
import { IDEUpdaterCommands } from '../ide-updater/ide-updater-commands';
@injectable() @injectable()
export class Help extends Contribution { export class Help extends Contribution {
@ -115,6 +116,10 @@ export class Help extends Contribution {
commandId: Help.Commands.VISIT_ARDUINO.id, commandId: Help.Commands.VISIT_ARDUINO.id,
order: '6', order: '6',
}); });
registry.registerMenuAction(ArduinoMenus.HELP__FIND_GROUP, {
commandId: IDEUpdaterCommands.CHECK_FOR_UPDATES.id,
order: '7',
});
} }
registerKeybindings(registry: KeybindingRegistry): void { registerKeybindings(registry: KeybindingRegistry): void {

View File

@ -205,7 +205,6 @@ export const IDEUpdaterComponent = ({
) : ( ) : (
<PreDownload /> <PreDownload />
)} )}
{/* {!!error && <div className="error-container">{error}</div>} */}
</div> </div>
); );
}; };

View File

@ -7,8 +7,9 @@ import { Message } from '@phosphor/messaging';
import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget'; import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget';
import { nls } from '@theia/core'; import { nls } from '@theia/core';
import { IDEUpdaterComponent } from './ide-updater-component'; import { IDEUpdaterComponent } from './ide-updater-component';
import { IDEUpdaterCommands } from '../../ide-updater/ide-updater-commands';
import { import {
IDEUpdater,
IDEUpdaterClient, IDEUpdaterClient,
ProgressInfo, ProgressInfo,
UpdateInfo, UpdateInfo,
@ -27,8 +28,8 @@ export class IDEUpdaterDialogWidget extends ReactWidget {
downloadStarted: boolean; downloadStarted: boolean;
onClose: () => void; onClose: () => void;
@inject(IDEUpdaterCommands) @inject(IDEUpdater)
protected readonly updater: IDEUpdaterCommands; protected readonly updater: IDEUpdater;
@inject(IDEUpdaterClient) @inject(IDEUpdaterClient)
protected readonly updaterClient: IDEUpdaterClient; protected readonly updaterClient: IDEUpdaterClient;
@ -125,7 +126,7 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
) { ) {
super({ super({
title: nls.localize( title: nls.localize(
'arduino/updater/ideUpdaterDialog', 'arduino/ide-updater/ideUpdaterDialog',
'Software Update' 'Software Update'
), ),
}); });

View File

@ -3,9 +3,11 @@ import {
CommandContribution, CommandContribution,
CommandRegistry, CommandRegistry,
MessageService, MessageService,
nls,
} from '@theia/core'; } from '@theia/core';
import { injectable, inject } from 'inversify'; import { injectable, inject } from 'inversify';
import { IDEUpdater, UpdateInfo } from '../../common/protocol/ide-updater'; import { IDEUpdater, UpdateInfo } from '../../common/protocol/ide-updater';
import { IDEUpdaterDialog } from '../dialogs/ide-updater/ide-updater-dialog';
@injectable() @injectable()
export class IDEUpdaterCommands implements CommandContribution { export class IDEUpdaterCommands implements CommandContribution {
@ -13,38 +15,40 @@ export class IDEUpdaterCommands implements CommandContribution {
@inject(IDEUpdater) @inject(IDEUpdater)
private readonly updater: IDEUpdater, private readonly updater: IDEUpdater,
@inject(MessageService) @inject(MessageService)
protected readonly messageService: MessageService protected readonly messageService: MessageService,
@inject(IDEUpdaterDialog)
protected readonly updaterDialog: IDEUpdaterDialog
) {} ) {}
registerCommands(registry: CommandRegistry): void { registerCommands(registry: CommandRegistry): void {
registry.registerCommand(IDEUpdaterCommands.CHECK_FOR_UPDATES, { registry.registerCommand(IDEUpdaterCommands.CHECK_FOR_UPDATES, {
execute: this.checkForUpdates.bind(this), 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<UpdateInfo | void> { async checkForUpdates(initialCheck?: boolean): Promise<UpdateInfo | void> {
return await this.updater.checkForUpdates(initialCheck); try {
} const updateInfo = await this.updater.checkForUpdates(initialCheck);
if (!!updateInfo) {
async downloadUpdate(): Promise<void> { this.updaterDialog.open(updateInfo);
await this.updater.downloadUpdate(); } else {
} this.messageService.info(
nls.localize(
async stopDownload(): Promise<void> { 'arduino/ide-updater/noUpdatesAvailable',
await this.updater.stopDownload(); 'There are no recent updates available for the Arduino IDE'
} )
);
quitAndInstall(): void { }
this.updater.quitAndInstall(); 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 { export namespace IDEUpdaterCommands {
@ -53,19 +57,4 @@ export namespace IDEUpdaterCommands {
category: 'Arduino', category: 'Arduino',
label: 'Check for Arduino IDE updates', 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',
};
} }

View File

@ -46,7 +46,7 @@ export interface ProgressInfo {
export const IDEUpdaterPath = '/services/ide-updater'; export const IDEUpdaterPath = '/services/ide-updater';
export const IDEUpdater = Symbol('IDEUpdater'); export const IDEUpdater = Symbol('IDEUpdater');
export interface IDEUpdater extends JsonRpcServer<IDEUpdaterClient> { export interface IDEUpdater extends JsonRpcServer<IDEUpdaterClient> {
init(channel: UpdateChannel, baseUrl: string): void; init(channel: UpdateChannel, baseUrl: string): Promise<void>;
checkForUpdates(initialCheck?: boolean): Promise<UpdateInfo | void>; checkForUpdates(initialCheck?: boolean): Promise<UpdateInfo | void>;
downloadUpdate(): Promise<void>; downloadUpdate(): Promise<void>;
quitAndInstall(): void; quitAndInstall(): void;

View File

@ -17,15 +17,7 @@ export class IDEUpdaterImpl implements IDEUpdater {
protected theiaFEClient?: IDEUpdaterClient; protected theiaFEClient?: IDEUpdaterClient;
protected clients: Array<IDEUpdaterClient> = []; protected clients: Array<IDEUpdaterClient> = [];
init(channel: UpdateChannel, baseUrl: string): void { constructor() {
this.updater.autoDownload = false;
this.updater.channel = channel;
this.updater.setFeedURL({
provider: 'generic',
url: `${baseUrl}/${channel === UpdateChannel.Nightly ? 'nightly' : ''}`,
channel,
});
this.updater.on('checking-for-update', (e) => { this.updater.on('checking-for-update', (e) => {
this.clients.forEach((c) => c.notifyCheckingForUpdate(e)); this.clients.forEach((c) => c.notifyCheckingForUpdate(e));
}); });
@ -46,6 +38,16 @@ export class IDEUpdaterImpl implements IDEUpdater {
}); });
} }
async init(channel: UpdateChannel, baseUrl: string): Promise<void> {
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 { setClient(client: IDEUpdaterClient | undefined): void {
if (client) this.clients.push(client); if (client) this.clients.push(client);
} }

View File

@ -14,6 +14,22 @@
"saveChangesToSketch": "Do you want to save changes to this sketch before closing?", "saveChangesToSketch": "Do you want to save changes to this sketch before closing?",
"loseChanges": "If you don't save, your changes will be lost." "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": { "menu": {
"sketch": "Sketch", "sketch": "Sketch",
"tools": "Tools" "tools": "Tools"
@ -255,22 +271,6 @@
"dialog": { "dialog": {
"dontAskAgain": "Don't ask again" "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": { "userFields": {
"cancel": "Cancel", "cancel": "Cancel",
"upload": "Upload" "upload": "Upload"