1- const { app, BrowserWindow, protocol } = require ( 'electron' ) ;
1+ const { app, BrowserWindow, protocol, Menu , ipcMain } = require ( 'electron' ) ;
22const path = require ( 'path' ) ;
3+ const fs = require ( 'fs' ) ;
34
45const { registerAppIpcHandlers, terminateAllProcesses } = require ( './main-app-ipc' ) ;
56const { registerFsIpcHandlers, getAppDataDir } = require ( './main-fs-ipc' ) ;
67
8+ // In-memory key-value store shared across all windows (mirrors Tauri's put_item/get_all_items)
9+ // Used for multi-window storage synchronization
10+ const sharedStorageMap = new Map ( ) ;
11+
712let mainWindow ;
813
914async function createWindow ( ) {
@@ -21,9 +26,6 @@ async function createWindow() {
2126 // Load the test page from the http-server
2227 mainWindow . loadURL ( 'http://localhost:8000/src/' ) ;
2328
24- // Open DevTools for debugging
25- mainWindow . webContents . openDevTools ( ) ;
26-
2729 mainWindow . on ( 'closed' , ( ) => {
2830 mainWindow = null ;
2931 } ) ;
@@ -39,12 +41,57 @@ async function gracefulShutdown(exitCode = 0) {
3941registerAppIpcHandlers ( ) ;
4042registerFsIpcHandlers ( ) ;
4143
44+ /**
45+ * IPC handlers for electronAPI
46+ * Preload location: contextBridge.exposeInMainWorld('electronAPI', { ... })
47+ */
48+
49+ // Set zoom factor on the webview (mirrors Tauri's zoom_window)
50+ ipcMain . handle ( 'zoom-window' , ( event , scaleFactor ) => {
51+ event . sender . setZoomFactor ( scaleFactor ) ;
52+ } ) ;
53+
54+ // In-memory storage for multi-window sync (mirrors Tauri's put_item/get_all_items)
55+ ipcMain . handle ( 'put-item' , ( event , key , value ) => {
56+ sharedStorageMap . set ( key , value ) ;
57+ } ) ;
58+
59+ ipcMain . handle ( 'get-all-items' , ( ) => {
60+ return Object . fromEntries ( sharedStorageMap ) ;
61+ } ) ;
62+
63+ // Toggle DevTools
64+ ipcMain . handle ( 'toggle-dev-tools' , ( event ) => {
65+ event . sender . toggleDevTools ( ) ;
66+ } ) ;
67+
68+ // Get path to phnode binary
69+ ipcMain . handle ( 'get-phnode-path' , ( ) => {
70+ const phNodePath = path . resolve ( __dirname , 'bin' , 'phnode' ) ;
71+ if ( ! fs . existsSync ( phNodePath ) ) {
72+ throw new Error ( `phnode binary does not exist: ${ phNodePath } ` ) ;
73+ }
74+ return phNodePath ;
75+ } ) ;
76+
77+ // Get path to src-node (for development)
78+ ipcMain . handle ( 'get-src-node-path' , ( ) => {
79+ const srcNodePath = path . resolve ( __dirname , '..' , '..' , 'phoenix' , 'src-node' ) ;
80+ if ( ! fs . existsSync ( srcNodePath ) ) {
81+ throw new Error ( `src-node path does not exist: ${ srcNodePath } ` ) ;
82+ }
83+ return srcNodePath ;
84+ } ) ;
85+
4286// Handle quit request from renderer
4387app . on ( 'quit-requested' , ( exitCode ) => {
4488 gracefulShutdown ( exitCode ) ;
4589} ) ;
4690
4791app . whenReady ( ) . then ( async ( ) => {
92+ // Remove default menu bar
93+ Menu . setApplicationMenu ( null ) ;
94+
4895 // Register asset:// protocol for serving local files from appLocalData/assets/
4996 const appDataDir = getAppDataDir ( ) ;
5097 const assetsDir = path . join ( appDataDir , 'assets' ) ;
0 commit comments