Skip to content

Commit 241baca

Browse files
author
Akos Kitta
committed
fix: better typing for the startup handlers
- added missing `super#init` call, - no `MaybePromise` return type for the plotter handler, - corrected outdated dev comments Signed-off-by: Akos Kitta <[email protected]>
1 parent 7ff070c commit 241baca

File tree

6 files changed

+20
-23
lines changed

6 files changed

+20
-23
lines changed

Diff for: arduino-ide-extension/src/browser/app-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { Disposable } from '@theia/core/lib/common/disposable';
2-
import type { MaybePromise } from '@theia/core/lib/common/types';
2+
import type { StartupTasks } from '../electron-common/startup-task';
33
import type { Sketch } from './contributions/contribution';
44

55
export const AppService = Symbol('AppService');
66
export interface AppService {
77
quit(): void;
88
version(): Promise<string>;
99
registerStartupTasksHandler(
10-
handler: (args: unknown) => MaybePromise<void>
10+
handler: (tasks: StartupTasks) => void
1111
): Disposable;
1212
scheduleDeletion(sketch: Sketch): void; // TODO: find a better place
1313
}

Diff for: arduino-ide-extension/src/browser/contributions/startup-tasks-executor.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import {
44
injectable,
55
postConstruct,
66
} from '@theia/core/shared/inversify';
7-
import { hasStartupTasks } from '../../electron-common/startup-task';
7+
import {
8+
hasStartupTasks,
9+
StartupTasks,
10+
} from '../../electron-common/startup-task';
811
import { AppService } from '../app-service';
912
import { Contribution } from './contribution';
1013

@@ -17,9 +20,10 @@ export class StartupTasksExecutor extends Contribution {
1720

1821
@postConstruct()
1922
protected override init(): void {
23+
super.init();
2024
this.toDispose.push(
21-
this.appService.registerStartupTasksHandler((args) =>
22-
this.handleStartupTasks(args)
25+
this.appService.registerStartupTasksHandler((tasks) =>
26+
this.handleStartupTasks(tasks)
2327
)
2428
);
2529
}
@@ -28,20 +32,19 @@ export class StartupTasksExecutor extends Contribution {
2832
this.toDispose.dispose();
2933
}
3034

31-
private async handleStartupTasks(args: unknown): Promise<void> {
35+
private async handleStartupTasks(tasks: StartupTasks): Promise<void> {
3236
console.debug(
3337
`Received the startup tasks from the electron main process. Args: ${JSON.stringify(
34-
args
38+
tasks
3539
)}`
3640
);
37-
if (!hasStartupTasks(args)) {
41+
if (!hasStartupTasks(tasks)) {
3842
console.warn(`Could not detect 'tasks' from the signal. Skipping.`);
3943
return;
4044
}
41-
const { tasks } = args;
4245
await this.appStateService.reachedState('ready');
4346
console.log(`Executing startup tasks:`);
44-
tasks.forEach(({ command, args = [] }) => {
47+
tasks.tasks.forEach(({ command, args = [] }) => {
4548
console.log(
4649
` - '${command}' ${
4750
args.length ? `, args: ${JSON.stringify(args)}` : ''

Diff for: arduino-ide-extension/src/browser/theia/core/theming.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ interface ThemeProvider {
102102
/**
103103
* Returns with a list of built-in themes officially supported by IDE2 (https://github.com/arduino/arduino-ide/issues/1283).
104104
* The themes in the array follow the following order:
105-
* - built-in themes first (in `Light`, `Dark`, `High Contrast (Light)`, and `High Contrast (Dark)`), // TODO -> High Contrast will be split up to HC Dark and HC Light after the Theia version uplift
105+
* - built-in themes first (in `Light`, `Dark`, `Light High Contrast`, and `Dark High Contrast`),
106106
* - followed by user installed (VSIX) themes grouped by theme type, then alphabetical order,
107107
* - if the `currentTheme` is either Light (Theia) or Dark (Theia), the last item of the array will be the selected theme with `(deprecated)` suffix.
108108
*/

Diff for: arduino-ide-extension/src/electron-browser/electron-app-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Disposable } from '@theia/core/lib/common/disposable';
2-
import type { MaybePromise } from '@theia/core/lib/common/types';
32
import { injectable } from '@theia/core/shared/inversify';
43
import type { AppService } from '../browser/app-service';
54
import type { Sketch } from '../common/protocol/sketches-service';
5+
import type { StartupTasks } from '../electron-common/startup-task';
66

77
@injectable()
88
export class ElectronAppService implements AppService {
@@ -15,7 +15,7 @@ export class ElectronAppService implements AppService {
1515
}
1616

1717
registerStartupTasksHandler(
18-
handler: (args: unknown) => MaybePromise<void>
18+
handler: (tasks: StartupTasks) => void
1919
): Disposable {
2020
return window.electronArduino.registerStartupTasksHandler(handler);
2121
}

Diff for: arduino-ide-extension/src/electron-browser/preload.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
ipcRenderer,
44
} from '@theia/core/electron-shared/electron';
55
import { Disposable } from '@theia/core/lib/common/disposable';
6-
import type { MaybePromise } from '@theia/core/lib/common/types';
76
import { CHANNEL_REQUEST_RELOAD } from '@theia/core/lib/electron-common/electron-api';
87
import type { Sketch } from '../common/protocol/sketches-service';
98
import {
@@ -37,9 +36,7 @@ const api: ElectronArduino = {
3736
isFirstWindow: () => ipcRenderer.invoke(CHANNEL_IS_FIRST_WINDOW),
3837
requestReload: (options: StartupTasks) =>
3938
ipcRenderer.send(CHANNEL_REQUEST_RELOAD, options),
40-
registerStartupTasksHandler: (
41-
handler: (tasks: StartupTasks) => MaybePromise<void>
42-
) => {
39+
registerStartupTasksHandler: (handler: (tasks: StartupTasks) => void) => {
4340
const listener = (_: Electron.IpcRendererEvent, args: unknown) => {
4441
if (hasStartupTasks(args)) {
4542
handler(args);
@@ -62,7 +59,7 @@ const api: ElectronArduino = {
6259
ipcRenderer.send(CHANNEL_SET_REPRESENTED_FILENAME, fsPath),
6360
showPlotterWindow: (params: { url: string; forceReload?: boolean }) =>
6461
ipcRenderer.send(CHANNEL_SHOW_PLOTTER_WINDOW, params),
65-
registerPlotterWindowCloseHandler: (handler: () => MaybePromise<void>) => {
62+
registerPlotterWindowCloseHandler: (handler: () => void) => {
6663
const listener = () => handler();
6764
ipcRenderer.on(CHANNEL_PLOTTER_WINDOW_DID_CLOSE, listener);
6865
return Disposable.create(() =>

Diff for: arduino-ide-extension/src/electron-common/electron-arduino.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
SaveDialogReturnValue as ElectronSaveDialogReturnValue,
88
} from '@theia/core/electron-shared/electron';
99
import type { Disposable } from '@theia/core/lib/common/disposable';
10-
import type { MaybePromise } from '@theia/core/lib/common/types';
1110
import type { Sketch } from '../common/protocol/sketches-service';
1211
import type { StartupTasks } from './startup-task';
1312

@@ -45,14 +44,12 @@ export interface ElectronArduino {
4544
isFirstWindow(): Promise<boolean>;
4645
requestReload(tasks: StartupTasks): void;
4746
registerStartupTasksHandler(
48-
handler: (tasks: StartupTasks) => MaybePromise<void>
47+
handler: (tasks: StartupTasks) => void
4948
): Disposable;
5049
scheduleDeletion(sketch: Sketch): void;
5150
setRepresentedFilename(fsPath: string): void;
5251
showPlotterWindow(params: { url: string; forceReload?: boolean }): void;
53-
registerPlotterWindowCloseHandler(
54-
handler: () => MaybePromise<void>
55-
): Disposable;
52+
registerPlotterWindowCloseHandler(handler: () => void): Disposable;
5653
}
5754

5855
declare global {

0 commit comments

Comments
 (0)