mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-09 12:26:34 +00:00
fix IDE updater commands (#872)
* fix IDE updater commands * reinitialise autoupdate when preferences change * fix typo + add i18n strings
This commit is contained in:
parent
a5a6a0b611
commit
96b5edf427
@ -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<void | 'No' | 'Yes' | undefined>
|
||||
| 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<string>(
|
||||
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<string>(
|
||||
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');
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -205,7 +205,6 @@ export const IDEUpdaterComponent = ({
|
||||
) : (
|
||||
<PreDownload />
|
||||
)}
|
||||
{/* {!!error && <div className="error-container">{error}</div>} */}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -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<UpdateInfo> {
|
||||
) {
|
||||
super({
|
||||
title: nls.localize(
|
||||
'arduino/updater/ideUpdaterDialog',
|
||||
'arduino/ide-updater/ideUpdaterDialog',
|
||||
'Software Update'
|
||||
),
|
||||
});
|
||||
|
@ -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<UpdateInfo | void> {
|
||||
return await this.updater.checkForUpdates(initialCheck);
|
||||
}
|
||||
|
||||
async downloadUpdate(): Promise<void> {
|
||||
await this.updater.downloadUpdate();
|
||||
}
|
||||
|
||||
async stopDownload(): Promise<void> {
|
||||
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',
|
||||
};
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ export interface ProgressInfo {
|
||||
export const IDEUpdaterPath = '/services/ide-updater';
|
||||
export const IDEUpdater = Symbol('IDEUpdater');
|
||||
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>;
|
||||
downloadUpdate(): Promise<void>;
|
||||
quitAndInstall(): void;
|
||||
|
@ -17,15 +17,7 @@ export class IDEUpdaterImpl implements IDEUpdater {
|
||||
protected theiaFEClient?: IDEUpdaterClient;
|
||||
protected clients: Array<IDEUpdaterClient> = [];
|
||||
|
||||
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<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 {
|
||||
if (client) this.clients.push(client);
|
||||
}
|
||||
|
32
i18n/en.json
32
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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user