Skip to content

Commit 2b74422

Browse files
committed
chore: add electron apis needed by phoenix
1 parent 1362910 commit 2b74422

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src-electron/main-app-ipc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ let processInstanceId = 0;
77
// Map of instanceId -> { process, terminated }
88
const spawnedProcesses = new Map();
99

10+
// In-memory key-value store shared across all windows (mirrors Tauri's put_item/get_all_items)
11+
// Used for multi-window storage synchronization
12+
const sharedStorageMap = new Map();
13+
1014
function waitForTrue(fn, timeout) {
1115
return new Promise((resolve) => {
1216
const startTime = Date.now();
@@ -116,6 +120,20 @@ function registerAppIpcHandlers() {
116120
ipcMain.handle('get-app-name', () => {
117121
return productName;
118122
});
123+
124+
// Set zoom factor on the webview (mirrors Tauri's zoom_window)
125+
ipcMain.handle('zoom-window', (event, scaleFactor) => {
126+
event.sender.setZoomFactor(scaleFactor);
127+
});
128+
129+
// In-memory storage for multi-window sync (mirrors Tauri's put_item/get_all_items)
130+
ipcMain.handle('put-item', (event, key, value) => {
131+
sharedStorageMap.set(key, value);
132+
});
133+
134+
ipcMain.handle('get-all-items', () => {
135+
return Object.fromEntries(sharedStorageMap);
136+
});
119137
}
120138

121139
module.exports = {

src-electron/preload.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,12 @@ contextBridge.exposeInMainWorld('electronAPI', {
6262
// Normalize path separators to forward slashes for URL
6363
const normalizedPath = platformPath.replace(/\\/g, '/');
6464
return `asset://localhost/${encodeURIComponent(normalizedPath)}`;
65-
}
65+
},
66+
67+
// Set zoom factor on the webview (mirrors Tauri's zoom_window)
68+
zoomWindow: (scaleFactor) => ipcRenderer.invoke('zoom-window', scaleFactor),
69+
70+
// In-memory storage for multi-window sync (mirrors Tauri's put_item/get_all_items)
71+
putItem: (key, value) => ipcRenderer.invoke('put-item', key, value),
72+
getAllItems: () => ipcRenderer.invoke('get-all-items')
6673
});

0 commit comments

Comments
 (0)