(options?: { chatId?: string; subChatId?: string })
| 612 | * @param options.subChatId Open this sub-chat in the new window |
| 613 | */ |
| 614 | export function createWindow(options?: { chatId?: string; subChatId?: string }): BrowserWindow { |
| 615 | // Register IPC handlers before creating first window |
| 616 | registerIpcHandlers() |
| 617 | |
| 618 | // Read Windows frame preference |
| 619 | const useNativeFrame = getUseNativeFramePreference() |
| 620 | |
| 621 | const window = new BrowserWindow({ |
| 622 | width: 1400, |
| 623 | height: 900, |
| 624 | minWidth: 500, // Allow narrow mobile-like mode |
| 625 | minHeight: 600, |
| 626 | show: false, |
| 627 | title: "1Code", |
| 628 | backgroundColor: nativeTheme.shouldUseDarkColors ? "#09090b" : "#ffffff", |
| 629 | // hiddenInset shows native traffic lights inset in the window |
| 630 | // hiddenInset hides the native title bar but keeps traffic lights visible |
| 631 | titleBarStyle: process.platform === "darwin" ? "hiddenInset" : "default", |
| 632 | trafficLightPosition: |
| 633 | process.platform === "darwin" ? { x: 15, y: 12 } : undefined, |
| 634 | // Windows: Use native frame or frameless based on user preference |
| 635 | ...(process.platform === "win32" && { |
| 636 | frame: useNativeFrame, |
| 637 | autoHideMenuBar: true, |
| 638 | }), |
| 639 | webPreferences: { |
| 640 | preload: join(__dirname, "../preload/index.js"), |
| 641 | nodeIntegration: false, |
| 642 | contextIsolation: true, |
| 643 | sandbox: false, // Required for electron-trpc |
| 644 | webSecurity: true, |
| 645 | partition: "persist:main", // Use persistent session for cookies |
| 646 | }, |
| 647 | }) |
| 648 | |
| 649 | // Register window with manager and get stable ID for localStorage namespacing |
| 650 | const stableWindowId = windowManager.register(window) |
| 651 | console.log( |
| 652 | `[Main] Created window ${window.id} with stable ID "${stableWindowId}" (total: ${windowManager.count()})`, |
| 653 | ) |
| 654 | |
| 655 | // Setup tRPC IPC handler (singleton pattern) |
| 656 | if (ipcHandler) { |
| 657 | // Reuse existing handler, just attach new window |
| 658 | ipcHandler.attachWindow(window) |
| 659 | } else { |
| 660 | // Create new handler with context |
| 661 | ipcHandler = createIPCHandler({ |
| 662 | router: createAppRouter(getWindow), |
| 663 | windows: [window], |
| 664 | createContext: async () => ({ |
| 665 | getWindow, |
| 666 | }), |
| 667 | }) |
| 668 | } |
| 669 | |
| 670 | // Show window when ready |
| 671 | window.on("ready-to-show", () => { |
no test coverage detected