Skip to content

Commit 44d31ab

Browse files
author
Alberto Iannaccone
committed
move ide updater on backend
1 parent 2061f52 commit 44d31ab

File tree

8 files changed

+343
-94
lines changed

8 files changed

+343
-94
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+24
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ import {
262262
UserFieldsDialogWidget,
263263
} from './dialogs/user-fields/user-fields-dialog';
264264
import { nls } from '@theia/core/lib/common';
265+
import { IDEUpdaterCommands } from './ide-updater/ide-updater-commands';
266+
import {
267+
IDEUpdaterService,
268+
IDEUpdaterServiceClient,
269+
IDEUpdaterServicePath,
270+
} from '../common/protocol/ide-updater-service';
271+
import { IDEUpdaterServiceClientImpl } from './ide-updater/ide-updater-service-client-impl';
265272

266273
const ElementQueries = require('css-element-queries/src/ElementQueries');
267274

@@ -761,4 +768,21 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
761768
bind(UserFieldsDialogProps).toConstantValue({
762769
title: 'UserFields',
763770
});
771+
772+
bind(IDEUpdaterCommands).toSelf().inSingletonScope();
773+
bind(CommandContribution).toService(IDEUpdaterCommands);
774+
775+
// Frontend binding for the IDE Updater service
776+
bind(IDEUpdaterService)
777+
.toDynamicValue((context) => {
778+
const connection = context.container.get(WebSocketConnectionProvider);
779+
const client = context.container.get<IDEUpdaterServiceClient>(
780+
IDEUpdaterServiceClient
781+
);
782+
return connection.createProxy(IDEUpdaterServicePath, client);
783+
})
784+
.inSingletonScope();
785+
bind(IDEUpdaterServiceClient)
786+
.to(IDEUpdaterServiceClientImpl)
787+
.inSingletonScope();
764788
});
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,39 @@
1-
import { Command, CommandContribution, CommandRegistry } from "@theia/core";
2-
import { injectable, inject } from "inversify";
3-
import { CancellationToken } from "electron-updater";
4-
import { IDEUpdater } from "./ide-updater";
1+
import { Command, CommandContribution, CommandRegistry } from '@theia/core';
2+
import { injectable, inject } from 'inversify';
3+
import { IDEUpdaterService } from '../../common/protocol/ide-updater-service';
54

6-
// IDEUpdaterCommands register commands used to verify if there
7-
// are new IDE updates, download them, and install them.
85
@injectable()
96
export class IDEUpdaterCommands implements CommandContribution {
10-
private readonly cancellationToken = new CancellationToken();
11-
127
constructor(
13-
@inject(IDEUpdater) private readonly updater: IDEUpdater
14-
) {
15-
}
8+
@inject(IDEUpdaterService)
9+
private readonly updater: IDEUpdaterService
10+
) {}
1611

1712
registerCommands(registry: CommandRegistry): void {
1813
registry.registerCommand(IDEUpdaterCommands.CHECK_FOR_UPDATES, {
19-
execute: this.checkForUpdates,
14+
execute: this.checkForUpdates.bind(this),
2015
});
2116
registry.registerCommand(IDEUpdaterCommands.DOWNLOAD_UPDATE, {
22-
execute: this.downloadUpdate,
23-
})
17+
execute: this.downloadUpdate.bind(this),
18+
});
2419
registry.registerCommand(IDEUpdaterCommands.STOP_DOWNLOAD, {
25-
execute: this.stopDownload,
26-
})
20+
execute: this.stopDownload.bind(this),
21+
});
2722
registry.registerCommand(IDEUpdaterCommands.INSTALL_UPDATE, {
28-
execute: this.quitAndInstall,
29-
})
23+
execute: this.quitAndInstall.bind(this),
24+
});
3025
}
3126

3227
checkForUpdates() {
3328
this.updater.checkForUpdates();
3429
}
3530

3631
downloadUpdate() {
37-
this.updater.downloadUpdate(this.cancellationToken);
32+
this.updater.downloadUpdate();
3833
}
3934

4035
stopDownload() {
41-
this.cancellationToken.cancel();
36+
this.updater.stopDownload();
4237
}
4338

4439
quitAndInstall() {
@@ -48,14 +43,22 @@ export class IDEUpdaterCommands implements CommandContribution {
4843
export namespace IDEUpdaterCommands {
4944
export const CHECK_FOR_UPDATES: Command = {
5045
id: 'arduino-ide-check-for-updates',
46+
category: 'Arduino',
47+
label: 'Check for Arduino IDE updates',
5148
};
5249
export const DOWNLOAD_UPDATE: Command = {
5350
id: 'arduino-ide-download-update',
51+
category: 'Arduino',
52+
label: 'Download Arduino IDE updates',
5453
};
5554
export const STOP_DOWNLOAD: Command = {
5655
id: 'arduino-ide-stop-download',
56+
category: 'Arduino',
57+
label: 'Stop download of Arduino IDE updates',
5758
};
5859
export const INSTALL_UPDATE: Command = {
5960
id: 'arduino-ide-install-update',
61+
category: 'Arduino',
62+
label: 'Install Arduino IDE updates',
6063
};
6164
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Emitter } from '@theia/core';
2+
import { injectable } from '@theia/core/shared/inversify';
3+
import { UpdateInfo, ProgressInfo } from 'electron-updater';
4+
import { IDEUpdaterServiceClient } from '../../common/protocol/ide-updater-service';
5+
6+
@injectable()
7+
export class IDEUpdaterServiceClientImpl implements IDEUpdaterServiceClient {
8+
protected readonly onErrorEmitter = new Emitter<Error>();
9+
protected readonly onCheckingForUpdateEmitter = new Emitter<void>();
10+
protected readonly onUpdateAvailableEmitter = new Emitter<UpdateInfo>();
11+
protected readonly onUpdateNotAvailableEmitter = new Emitter<UpdateInfo>();
12+
protected readonly onDownloadProgressEmitter = new Emitter<ProgressInfo>();
13+
protected readonly onDownloadFinishedEmitter = new Emitter<UpdateInfo>();
14+
15+
readonly onError = this.onErrorEmitter.event;
16+
readonly onCheckingForUpdate = this.onCheckingForUpdateEmitter.event;
17+
readonly onUpdateAvailable = this.onUpdateAvailableEmitter.event;
18+
readonly onUpdateNotAvailable = this.onUpdateNotAvailableEmitter.event;
19+
readonly onDownloadProgressChanged = this.onDownloadProgressEmitter.event;
20+
readonly onDownloadFinished = this.onDownloadFinishedEmitter.event;
21+
22+
notifyError(message: Error): void {
23+
this.onErrorEmitter.fire(message);
24+
}
25+
notifyCheckingForUpdate(message: void): void {
26+
this.onCheckingForUpdateEmitter.fire(message);
27+
}
28+
notifyUpdateAvailable(message: UpdateInfo): void {
29+
this.onUpdateAvailableEmitter.fire(message);
30+
}
31+
notifyUpdateNotAvailable(message: UpdateInfo): void {
32+
this.onUpdateNotAvailableEmitter.fire(message);
33+
}
34+
notifyDownloadProgressChanged(message: ProgressInfo): void {
35+
this.onDownloadProgressEmitter.fire(message);
36+
}
37+
notifyDownloadFinished(message: UpdateInfo): void {
38+
this.onDownloadFinishedEmitter.fire(message);
39+
}
40+
}

arduino-ide-extension/src/browser/ide-updater/ide-updater.ts

-74
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { JsonRpcServer } from '@theia/core/lib/common/messaging/proxy-factory';
2+
import { Event } from '@theia/core/lib/common/event';
3+
4+
export interface ProgressInfo {
5+
total: number;
6+
delta: number;
7+
transferred: number;
8+
percent: number;
9+
bytesPerSecond: number;
10+
}
11+
12+
export interface ReleaseNoteInfo {
13+
readonly version: string;
14+
readonly note: string | null;
15+
}
16+
17+
export interface BlockMapDataHolder {
18+
size?: number;
19+
blockMapSize?: number;
20+
readonly sha512: string;
21+
readonly isAdminRightsRequired?: boolean;
22+
}
23+
24+
export interface UpdateFileInfo extends BlockMapDataHolder {
25+
url: string;
26+
}
27+
28+
export type UpdateInfo = {
29+
readonly version: string;
30+
readonly files: Array<UpdateFileInfo>;
31+
releaseName?: string | null;
32+
releaseNotes?: string | Array<ReleaseNoteInfo> | null;
33+
releaseDate: string;
34+
readonly stagingPercentage?: number;
35+
};
36+
37+
export const IDEUpdaterServicePath = '/services/ide-updater';
38+
export const IDEUpdaterService = Symbol('IDEUpdaterService');
39+
export interface IDEUpdaterService
40+
extends JsonRpcServer<IDEUpdaterServiceClient> {
41+
checkForUpdates(): Promise<UpdateInfo>;
42+
downloadUpdate(): Promise<void>;
43+
quitAndInstall(): void;
44+
stopDownload(): void;
45+
}
46+
47+
export const IDEUpdaterServiceClient = Symbol('IDEUpdaterServiceClient');
48+
export interface IDEUpdaterServiceClient {
49+
onError: Event<Error>;
50+
onCheckingForUpdate: Event<void>;
51+
onUpdateAvailable: Event<UpdateInfo>;
52+
onUpdateNotAvailable: Event<UpdateInfo>;
53+
onDownloadProgressChanged: Event<ProgressInfo>;
54+
onDownloadFinished: Event<UpdateInfo>;
55+
notifyError(message: Error): void;
56+
notifyCheckingForUpdate(message: void): void;
57+
notifyUpdateAvailable(message: UpdateInfo): void;
58+
notifyUpdateNotAvailable(message: UpdateInfo): void;
59+
notifyDownloadProgressChanged(message: ProgressInfo): void;
60+
notifyDownloadFinished(message: UpdateInfo): void;
61+
}

arduino-ide-extension/src/node/arduino-ide-backend-module.ts

+23
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ import { ArduinoFirmwareUploaderImpl } from './arduino-firmware-uploader-impl';
9292
import { PlotterBackendContribution } from './plotter/plotter-backend-contribution';
9393
import WebSocketServiceImpl from './web-socket/web-socket-service-impl';
9494
import { WebSocketService } from './web-socket/web-socket-service';
95+
import { IDEUpdaterServiceImpl } from './ide-updater/ide-updater-service-impl';
96+
import {
97+
IDEUpdaterService,
98+
IDEUpdaterServiceClient,
99+
IDEUpdaterServicePath,
100+
} from '../common/protocol/ide-updater-service';
95101

96102
export default new ContainerModule((bind, unbind, isBound, rebind) => {
97103
bind(BackendApplication).toSelf().inSingletonScope();
@@ -343,4 +349,21 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
343349

344350
bind(PlotterBackendContribution).toSelf().inSingletonScope();
345351
bind(BackendApplicationContribution).toService(PlotterBackendContribution);
352+
353+
// IDE updater bindings
354+
bind(ConnectionContainerModule).toConstantValue(
355+
ConnectionContainerModule.create(({ bind, bindBackendService }) => {
356+
bind(IDEUpdaterServiceImpl).toSelf().inSingletonScope();
357+
bind(IDEUpdaterService).toService(IDEUpdaterServiceImpl);
358+
bindBackendService<IDEUpdaterService, IDEUpdaterServiceClient>(
359+
IDEUpdaterServicePath,
360+
IDEUpdaterService,
361+
(service, client) => {
362+
service.setClient(client);
363+
client.onDidCloseConnection(() => service.dispose());
364+
return service;
365+
}
366+
);
367+
})
368+
);
346369
});

0 commit comments

Comments
 (0)