mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-10 12:56:32 +00:00
fix: wait for theia initalWindow
to be set before opening sketch through open-file
event (#2693)
* chore: use actual app name as `uriScheme` * fix: wait for `initialWindow` to be set before opening sketch from file
This commit is contained in:
parent
56ab874177
commit
a669a43449
@ -38,3 +38,26 @@ export function uint8ArrayToString(uint8Array: Uint8Array): string {
|
|||||||
export function stringToUint8Array(text: string): Uint8Array {
|
export function stringToUint8Array(text: string): Uint8Array {
|
||||||
return Uint8Array.from(text, (char) => char.charCodeAt(0));
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -30,6 +30,7 @@ import type { AddressInfo } from 'node:net';
|
|||||||
import { isAbsolute, join, resolve } from 'node:path';
|
import { isAbsolute, join, resolve } from 'node:path';
|
||||||
import type { Argv } from 'yargs';
|
import type { Argv } from 'yargs';
|
||||||
import { Sketch } from '../../common/protocol';
|
import { Sketch } from '../../common/protocol';
|
||||||
|
import { poolWhile } from '../../common/utils';
|
||||||
import {
|
import {
|
||||||
AppInfo,
|
AppInfo,
|
||||||
appInfoPropertyLiterals,
|
appInfoPropertyLiterals,
|
||||||
@ -292,6 +293,16 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
|
|||||||
);
|
);
|
||||||
if (sketchFolderPath) {
|
if (sketchFolderPath) {
|
||||||
this.openFilePromise.reject(new InterruptWorkspaceRestoreError());
|
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);
|
await this.openSketch(sketchFolderPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -890,7 +901,10 @@ const fallbackFrontendAppConfig: FrontendApplicationConfig = {
|
|||||||
defaultIconTheme: 'none',
|
defaultIconTheme: 'none',
|
||||||
validatePreferencesSchema: false,
|
validatePreferencesSchema: false,
|
||||||
defaultLocale: '',
|
defaultLocale: '',
|
||||||
electron: { showWindowEarly: true, uriScheme: 'custom://arduino-ide' },
|
electron: {
|
||||||
|
showWindowEarly: true,
|
||||||
|
uriScheme: 'arduino-ide',
|
||||||
|
},
|
||||||
reloadOnReconnect: true,
|
reloadOnReconnect: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,7 +67,8 @@
|
|||||||
"defaultIconTheme": "none",
|
"defaultIconTheme": "none",
|
||||||
"validatePreferencesSchema": false,
|
"validatePreferencesSchema": false,
|
||||||
"electron": {
|
"electron": {
|
||||||
"showWindowEarly": true
|
"showWindowEarly": true,
|
||||||
|
"uriScheme": "arduino-ide"
|
||||||
},
|
},
|
||||||
"reloadOnReconnect": true,
|
"reloadOnReconnect": true,
|
||||||
"preferences": {
|
"preferences": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user