|
1 | 1 | /** |
2 | | - * electron-workbench.ts - Electron workbench loading script for Electron |
| 2 | + * Electron workbench loading script (Approach A3) |
3 | 3 | * |
4 | | - * This script loads the Electron VSCode workbench and verifies the initial state |
5 | | - * after the workbench is loaded. |
| 4 | + * The Electron workbench is an async IIFE that: |
| 5 | + * 1. Reads window.vscode (preloadGlobals) for ipcRenderer + process + context |
| 6 | + * 2. Calls context.resolveConfiguration() -> INativeWindowConfiguration |
| 7 | + * 3. Computes baseUrl from configuration.appRoot |
| 8 | + * 4. Imports vs/workbench/workbench.desktop.main.js relative to baseUrl |
| 9 | + * |
| 10 | + * Wind's Install.ts provides all of these via the preload polyfill. |
| 11 | + * The _VSCODE_FILE_ROOT global is set by Base.astro before this script |
| 12 | + * runs, redirecting all VS Code asset loads to /Static/Application/. |
| 13 | + * |
| 14 | + * This path is served from Target/Static/Application/vs/ which is |
| 15 | + * populated by CopyVSCodeAssets in astro.config.ts (astro:build:done hook). |
| 16 | + * The electron-browser files are only available when Electron=true in the |
| 17 | + * build profile (debug-electron), which un-excludes electron-browser paths |
| 18 | + * in Output's ESBuild Exclude/Electron.ts and Exclude/Bootstrap.ts. |
6 | 19 | */ |
7 | 20 |
|
8 | | -interface ElectronPolyfillsWindow extends Window { |
9 | | - __ELECTRON_POLYFILLS_LOADED__?: unknown; |
10 | | - require?: NodeRequire; |
11 | | -} |
12 | | - |
13 | 21 | console.log("[Electron] ===== Loading Electron VSCode workbench ====="); |
14 | 22 | console.log( |
15 | | - "[Electron] Workbench path: vs/code/electron-browser/workbench/workbench.js", |
16 | | -); |
17 | | -console.log( |
18 | | - "[Electron] Note: Electron workbench has more features than browser workbench", |
| 23 | + "[Electron] Workbench: vs/code/electron-browser/workbench/workbench.js", |
19 | 24 | ); |
20 | 25 |
|
21 | 26 | try { |
22 | | - // Import the Electron workbench (NOT browser workbench) |
23 | | - // Electron workbench uses Electron-specific APIs |
24 | | - // @ts-ignore - Dynamic import for side effects, .d.ts file is not a module but the .js file exists at runtime |
25 | | - // electron-browser workbench.js is not compiled in Output — only .d.ts exists. |
26 | | - // When the Electron approach is activated, this path will need to be compiled first. |
27 | | - // await import("/vs/code/electron-browser/workbench/workbench.js"); |
| 27 | + const WorkbenchUrl = |
| 28 | + "/Static/Application/vs/code/electron-browser/workbench/workbench.js"; |
| 29 | + |
| 30 | + console.log("[Electron] Importing:", WorkbenchUrl); |
| 31 | + await import(/* @vite-ignore */ WorkbenchUrl); |
28 | 32 |
|
29 | | - console.log("[Electron] ✓ Electron workbench script loaded successfully"); |
| 33 | + console.log("[Electron] Workbench script loaded successfully"); |
30 | 34 | console.log("[Electron] ===== Workbench load complete ====="); |
| 35 | +} catch (Error: unknown) { |
| 36 | + console.error("[Electron] Failed to load Electron workbench:", Error); |
31 | 37 |
|
32 | | - // Log initial state after workbench load |
33 | | - setTimeout(async () => { |
34 | | - console.log("[Electron] ===== Post-workbench load state ====="); |
35 | | - console.log( |
36 | | - "[Electron] window.vscode available:", |
37 | | - typeof window.vscode !== "undefined", |
| 38 | + if (Error instanceof TypeError && String(Error).includes("MIME")) { |
| 39 | + console.error( |
| 40 | + "[Electron] MIME error: the file may not exist in Target/Static/Application/vs/", |
38 | 41 | ); |
39 | | - console.log( |
40 | | - "[Electron] Monaco editor available:", |
41 | | - typeof window.monaco !== "undefined", |
| 42 | + console.error( |
| 43 | + "[Electron] Ensure Electron=true is set and CopyVSCodeAssets copies electron-browser/", |
42 | 44 | ); |
43 | | - |
44 | | - // Check for Electron polyfills loaded flag (using bracket notation) |
45 | | - const electronPolyfillsLoaded = (window as ElectronPolyfillsWindow)[ |
46 | | - "__ELECTRON_POLYFILLS_LOADED__" |
47 | | - ]; |
48 | | - console.log( |
49 | | - "[Electron] Electron polyfills loaded:", |
50 | | - typeof electronPolyfillsLoaded !== "undefined", |
51 | | - ); |
52 | | - |
53 | | - // Check for Electron-specific globals (using bracket notation) |
54 | | - if (typeof window.require !== "undefined") { |
55 | | - console.log( |
56 | | - "[Electron] ✓ Node.js require() available (via polyfill)", |
57 | | - ); |
58 | | - try { |
59 | | - // eslint-disable-next-line @typescript-eslint/no-unused-vars |
60 | | - void window.require("electron"); |
61 | | - console.log( |
62 | | - "[Electron] ✓ Electron module accessible (polyfill)", |
63 | | - ); |
64 | | - } catch { |
65 | | - console.log( |
66 | | - "[Electron] ℹ Electron module polyfill not fully functional", |
67 | | - ); |
68 | | - } |
69 | | - } |
70 | | - }, 2000); |
71 | | -} catch (error: unknown) { |
72 | | - console.error("[Electron] ✗ Failed to load Electron workbench:", error); |
73 | | - console.error("[Electron] This may be due to:"); |
74 | | - console.error("[Electron] 1. Incomplete or non-functional polyfills"); |
75 | | - console.error("[Electron] 2. CSP errors with vscode-file:// protocol"); |
76 | | - console.error("[Electron] 3. Missing Electron APIs"); |
77 | | - console.error("[Electron] 4. Browser environment limitations"); |
78 | | - console.error( |
79 | | - "[Electron] Consider using Mountain.astro (A2) as recommended approach", |
80 | | - ); |
| 45 | + } |
81 | 46 | } |
82 | 47 |
|
83 | 48 | console.log("[Electron] ===== Workbench load sequence complete ====="); |
|
0 commit comments