Skip to content

fix: wait for theia initalWindow to be set before opening sketch through open-file event #2693

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

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Changes from all 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
23 changes: 23 additions & 0 deletions arduino-ide-extension/src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -38,3 +38,26 @@ export function uint8ArrayToString(uint8Array: Uint8Array): string {
export function stringToUint8Array(text: string): Uint8Array {
return Uint8Array.from(text, (char) => char.charCodeAt(0));
}

export function poolWhile(
whileCondition: () => boolean,
intervalMs: number,
timeoutMs: number
): Promise<void> {
return new Promise((resolve, reject) => {
if (!whileCondition) {
resolve();
}

const start = Date.now();
const interval = setInterval(() => {
if (!whileCondition()) {
clearInterval(interval);
resolve();
} else if (Date.now() - start > timeoutMs) {
clearInterval(interval);
reject(new Error('Timed out while polling.'));
}
}, intervalMs);
});
}
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ import type { AddressInfo } from 'node:net';
import { isAbsolute, join, resolve } from 'node:path';
import type { Argv } from 'yargs';
import { Sketch } from '../../common/protocol';
import { poolWhile } from '../../common/utils';
import {
AppInfo,
appInfoPropertyLiterals,
@@ -292,6 +293,16 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
);
if (sketchFolderPath) {
this.openFilePromise.reject(new InterruptWorkspaceRestoreError());

// open-file event is triggered before the app is ready and initialWindow is created.
// Wait for initialWindow to be set before opening the sketch on the first instance.
// See https://github.com/arduino/arduino-ide/pull/2693
try {
await app.whenReady();
if (!this.firstWindowId) {
await poolWhile(() => !this.initialWindow, 100, 3000);
}
} catch {}
await this.openSketch(sketchFolderPath);
}
}
@@ -890,7 +901,10 @@ const fallbackFrontendAppConfig: FrontendApplicationConfig = {
defaultIconTheme: 'none',
validatePreferencesSchema: false,
defaultLocale: '',
electron: { showWindowEarly: true, uriScheme: 'custom://arduino-ide' },
electron: {
showWindowEarly: true,
uriScheme: 'arduino-ide',
},
reloadOnReconnect: true,
};

3 changes: 2 additions & 1 deletion electron-app/package.json
Original file line number Diff line number Diff line change
@@ -67,7 +67,8 @@
"defaultIconTheme": "none",
"validatePreferencesSchema": false,
"electron": {
"showWindowEarly": true
"showWindowEarly": true,
"uriScheme": "arduino-ide"
},
"reloadOnReconnect": true,
"preferences": {

Unchanged files with check annotations Beta

'arduino/board/succesfullyUninstalledPlatform',
'Successfully uninstalled platform {0}:{1}',
item.name,
item.installedVersion!

Check warning on line 86 in arduino-ide-extension/src/browser/boards/boards-list-widget.ts

GitHub Actions / check

Forbidden non-null assertion

Check warning on line 86 in arduino-ide-extension/src/browser/boards/boards-list-widget.ts

GitHub Actions / check

Forbidden non-null assertion
),
{ timeout: 3000 }
);
unregisterSubmenu(menuPath, this.menuRegistry)
),
...Array.from(commands.keys()).map((commandId, i) => {
const { label } = commands.get(commandId)!;

Check warning on line 115 in arduino-ide-extension/src/browser/contributions/boards-data-menu-updater.ts

GitHub Actions / check

Forbidden non-null assertion

Check warning on line 115 in arduino-ide-extension/src/browser/contributions/boards-data-menu-updater.ts

GitHub Actions / check

Forbidden non-null assertion
this.menuRegistry.registerMenuAction(menuPath, {
commandId,
order: String(i).padStart(4),
return undefined;
}
protected async run(commandId: string): Promise<any> {

Check warning on line 229 in arduino-ide-extension/src/browser/contributions/edit-contributions.ts

GitHub Actions / check

Unexpected any. Specify a different type

Check warning on line 229 in arduino-ide-extension/src/browser/contributions/edit-contributions.ts

GitHub Actions / check

Unexpected any. Specify a different type
const editor = await this.current();
if (editor) {
const action = editor.getAction(commandId);
fqbn,
});
if (user.length) {
(user as any).unshift(

Check warning on line 329 in arduino-ide-extension/src/browser/contributions/examples.ts

GitHub Actions / check

Unexpected any. Specify a different type

Check warning on line 329 in arduino-ide-extension/src/browser/contributions/examples.ts

GitHub Actions / check

Unexpected any. Specify a different type
nls.localize(
'arduino/examples/customLibrary',
'Examples from Custom Libraries'
);
}
if (name && fqbn && current.length) {
(current as any).unshift(

Check warning on line 337 in arduino-ide-extension/src/browser/contributions/examples.ts

GitHub Actions / check

Unexpected any. Specify a different type

Check warning on line 337 in arduino-ide-extension/src/browser/contributions/examples.ts

GitHub Actions / check

Unexpected any. Specify a different type
nls.localize('arduino/examples/for', 'Examples for {0}', name)
);
}
if (any.length) {
(any as any).unshift(

Check warning on line 342 in arduino-ide-extension/src/browser/contributions/examples.ts

GitHub Actions / check

Unexpected any. Specify a different type

Check warning on line 342 in arduino-ide-extension/src/browser/contributions/examples.ts

GitHub Actions / check

Unexpected any. Specify a different type
nls.localize('arduino/examples/forAny', 'Examples for any board')
);
}
const userMenuPath = [...includeLibMenuPath, '3_contributed'];
const { user, rest } = LibraryPackage.groupByLocation(libraries);
if (rest.length) {
(rest as any).unshift(

Check warning on line 114 in arduino-ide-extension/src/browser/contributions/include-library.ts

GitHub Actions / check

Unexpected any. Specify a different type

Check warning on line 114 in arduino-ide-extension/src/browser/contributions/include-library.ts

GitHub Actions / check

Unexpected any. Specify a different type
nls.localize('arduino/library/arduinoLibraries', 'Arduino libraries')
);
}
if (user.length) {
(user as any).unshift(

Check warning on line 119 in arduino-ide-extension/src/browser/contributions/include-library.ts

GitHub Actions / check

Unexpected any. Specify a different type

Check warning on line 119 in arduino-ide-extension/src/browser/contributions/include-library.ts

GitHub Actions / check

Unexpected any. Specify a different type
nls.localize(
'arduino/library/contributedLibraries',
'Contributed libraries'
});
registry.registerCommand(UploadCertificate.Commands.OPEN_CERT_CONTEXT, {
execute: async (args: any) => {

Check warning on line 86 in arduino-ide-extension/src/browser/contributions/upload-certificate.ts

GitHub Actions / check

Unexpected any. Specify a different type

Check warning on line 86 in arduino-ide-extension/src/browser/contributions/upload-certificate.ts

GitHub Actions / check

Unexpected any. Specify a different type
this.contextMenuRenderer.render({
menuPath: ArduinoMenus.ROOT_CERTIFICATES__CONTEXT,
anchor: {
});
}
watch(uri: URI, opts: WatchOptions): Disposable {

Check warning on line 79 in arduino-ide-extension/src/browser/create/create-fs-provider.ts

GitHub Actions / check

'uri' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 79 in arduino-ide-extension/src/browser/create/create-fs-provider.ts

GitHub Actions / check

'uri' is defined but never used. Allowed unused args must match /^_/u
return Disposable.NULL;
}