Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix IDE updater commands #872

Merged
merged 3 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 41 additions & 33 deletions arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -279,18 +275,25 @@ 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(
`Error while checking for Arduino IDE updates. ${e}`
);
});

const start = async ({ selectedBoard }: BoardsConfig.Config) => {
if (selectedBoard) {
Expand All @@ -302,28 +305,33 @@ 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(() => {
const webContents = remote.getCurrentWebContents();
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');
}

Expand Down
5 changes: 5 additions & 0 deletions arduino-ide-extension/src/browser/contributions/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ export const IDEUpdaterComponent = ({
) : (
<PreDownload />
)}
{/* {!!error && <div className="error-container">{error}</div>} */}
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,41 @@ import {
} 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 {
constructor(
@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(
`There are no recent updates available the Arduino IDE`
AlbyIanna marked this conversation as resolved.
Show resolved Hide resolved
);
}
return updateInfo;
} catch (e) {
this.messageService.error(
`Error while checking for Arduino IDE updates. ${e.message}`
);
}
}
}
export namespace IDEUpdaterCommands {
Expand All @@ -53,19 +49,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',
};
}
2 changes: 1 addition & 1 deletion arduino-ide-extension/src/common/protocol/ide-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand All @@ -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);
}
Expand Down