Skip to content

Commit 04c8f65

Browse files
committed
chore: release aes trust on window close
1 parent 2bbe17c commit 04c8f65

2 files changed

Lines changed: 12 additions & 17 deletions

File tree

src-electron/main-window-ipc.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { ipcMain, BrowserWindow, shell, clipboard } = require('electron');
22
const path = require('path');
33
const { spawn } = require('child_process');
4+
const { cleanupWindowTrust } = require('./main-cred-ipc');
45

56
const PHOENIX_WINDOW_PREFIX = 'phcode-';
67
const PHOENIX_EXTENSION_WINDOW_PREFIX = 'extn-';
@@ -25,13 +26,16 @@ function getNextLabel(prefix) {
2526
const windowCloseHandlers = new Map();
2627

2728
function registerWindow(win, label) {
29+
const webContentsId = win.webContents.id;
2830
windowRegistry.set(label, win);
29-
webContentsToLabel.set(win.webContents.id, label);
31+
webContentsToLabel.set(webContentsId, label);
3032

3133
win.on('closed', () => {
3234
windowRegistry.delete(label);
33-
webContentsToLabel.delete(win.webContents.id);
34-
windowCloseHandlers.delete(win.webContents.id);
35+
webContentsToLabel.delete(webContentsId);
36+
windowCloseHandlers.delete(webContentsId);
37+
// Clean up AES trust for closing window (mirrors Tauri's on_window_event CloseRequested handler)
38+
cleanupWindowTrust(webContentsId);
3539
});
3640
}
3741

src-electron/main.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fs = require('fs');
44

55
const { registerAppIpcHandlers, terminateAllProcesses } = require('./main-app-ipc');
66
const { registerFsIpcHandlers, getAppDataDir } = require('./main-fs-ipc');
7-
const { registerCredIpcHandlers, cleanupWindowTrust } = require('./main-cred-ipc');
7+
const { registerCredIpcHandlers } = require('./main-cred-ipc');
88
const { registerWindowIpcHandlers, registerWindow } = require('./main-window-ipc');
99

1010
// Request single instance lock - only one instance of the app should run at a time
@@ -19,10 +19,8 @@ if (!gotTheLock) {
1919
// Used for multi-window storage synchronization
2020
const sharedStorageMap = new Map();
2121

22-
let mainWindow;
23-
2422
async function createWindow() {
25-
mainWindow = new BrowserWindow({
23+
const win = new BrowserWindow({
2624
width: 1200,
2725
height: 800,
2826
webPreferences: {
@@ -34,18 +32,11 @@ async function createWindow() {
3432
});
3533

3634
// Register main window with label 'main' (mirrors Tauri's window labeling)
37-
registerWindow(mainWindow, 'main');
35+
// Trust cleanup is handled by registerWindow's closed handler
36+
registerWindow(win, 'main');
3837

3938
// Load the test page from the http-server
40-
mainWindow.loadURL('http://localhost:8000/src/');
41-
42-
mainWindow.webContents.on('destroyed', () => {
43-
cleanupWindowTrust(mainWindow.webContents.id);
44-
});
45-
46-
mainWindow.on('closed', () => {
47-
mainWindow = null;
48-
});
39+
win.loadURL('http://localhost:8000/src/');
4940
}
5041

5142
async function gracefulShutdown(exitCode = 0) {

0 commit comments

Comments
 (0)