From 9c8024660373f398506b84f3f52865f6054b093c Mon Sep 17 00:00:00 2001 From: Dave Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Fri, 4 Apr 2025 22:52:55 +0200 Subject: [PATCH 1/3] use class variable to identify custom error --- .../src/electron-main/theia/electron-main-application.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts b/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts index e6f91f5b9..f5fa242ad 100644 --- a/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts +++ b/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts @@ -329,7 +329,10 @@ export class ElectronMainApplication extends TheiaElectronMainApplication { // 2. A short timeout resolves the promise automatically, falling back to the usual app launch await this.openFilePromise.promise; } catch (err) { - if (err instanceof InterruptWorkspaceRestoreError) { + if ( + err && + (err as InterruptWorkspaceRestoreError).isInterruptWorkspaceRestoreError + ) { // Application has received the `open-file` event and will skip the default application launch return; } @@ -804,6 +807,8 @@ export class ElectronMainApplication extends TheiaElectronMainApplication { } class InterruptWorkspaceRestoreError extends Error { + public readonly isInterruptWorkspaceRestoreError = true; + constructor() { super( "Received 'open-file' event. Interrupting the default launch workflow." From 62ca431cba40d2eb21e7e314f52500b226b8ec3e Mon Sep 17 00:00:00 2001 From: Dave Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Fri, 4 Apr 2025 23:20:29 +0200 Subject: [PATCH 2/3] try object instead of error --- .../src/electron-main/theia/electron-main-application.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts b/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts index f5fa242ad..1d9d22fd6 100644 --- a/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts +++ b/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts @@ -291,7 +291,9 @@ export class ElectronMainApplication extends TheiaElectronMainApplication { true ); if (sketchFolderPath) { - this.openFilePromise.reject(new InterruptWorkspaceRestoreError()); + this.openFilePromise.reject({ + name: 'InterruptWorkspaceRestoreError', + }); await this.openSketch(sketchFolderPath); } } @@ -329,10 +331,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication { // 2. A short timeout resolves the promise automatically, falling back to the usual app launch await this.openFilePromise.promise; } catch (err) { - if ( - err && - (err as InterruptWorkspaceRestoreError).isInterruptWorkspaceRestoreError - ) { + if (err && (err as any).name === 'InterruptWorkspaceRestoreError') { // Application has received the `open-file` event and will skip the default application launch return; } From a3b0b28db4cde14d01881dabec064a2d7afc72b1 Mon Sep 17 00:00:00 2001 From: Dave Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Fri, 4 Apr 2025 23:25:43 +0200 Subject: [PATCH 3/3] remove unused class --- .../electron-main/theia/electron-main-application.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts b/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts index 1d9d22fd6..5e3356904 100644 --- a/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts +++ b/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts @@ -805,17 +805,6 @@ export class ElectronMainApplication extends TheiaElectronMainApplication { } } -class InterruptWorkspaceRestoreError extends Error { - public readonly isInterruptWorkspaceRestoreError = true; - - constructor() { - super( - "Received 'open-file' event. Interrupting the default launch workflow." - ); - Object.setPrototypeOf(this, InterruptWorkspaceRestoreError.prototype); - } -} - // This is a workaround for a limitation with the Theia CLI and `electron-builder`. // It is possible to run the `electron-builder` with `-c.extraMetadata.foo.bar=36` option. // On the fly, a `package.json` file will be generated for the final bundled application with the additional `{ "foo": { "bar": 36 } }` metadata.