11import { BrowserWindow , ipcMain } from "electron"
22import path from "path"
3+ import { getCenteredWindowPosition } from "../utils/windowUtils"
34
45const VITE_DEV_SERVER_URL = process . env [ "VITE_DEV_SERVER_URL" ]
56
@@ -74,15 +75,18 @@ function sendInit(graphKey: GraphKey) {
7475 }
7576}
7677
77- export function openGraphWindow ( { graphKey, meta } : OpenArgs ) {
78+ export function openGraphWindow (
79+ { graphKey, meta } : OpenArgs ,
80+ parentWindow ?: BrowserWindow ,
81+ ) {
7882 // Always cache latest meta for this slot (used by ready-handshake)
7983 lastMeta [ graphKey ] = meta
8084
8185 // Reuse existing window if it's alive
8286 let win = getGraphWin ( graphKey )
8387
8488 if ( ! win ) {
85- win = new BrowserWindow ( {
89+ const windowOptions : Electron . BrowserWindowConstructorOptions = {
8690 width : 700 ,
8791 height : 350 ,
8892 frame : true ,
@@ -96,7 +100,20 @@ export function openGraphWindow({ graphKey, meta }: OpenArgs) {
96100 fullscreen : false ,
97101 fullscreenable : false ,
98102 alwaysOnTop : true ,
99- } )
103+ }
104+
105+ // Position window in the center of the parent window
106+ const centeredPosition = getCenteredWindowPosition (
107+ parentWindow ,
108+ windowOptions . width ! ,
109+ windowOptions . height ! ,
110+ )
111+ if ( centeredPosition ) {
112+ windowOptions . x = centeredPosition . x
113+ windowOptions . y = centeredPosition . y
114+ }
115+
116+ win = new BrowserWindow ( windowOptions )
100117
101118 graphWins [ graphKey ] = win
102119 win . setMenuBarVisibility ( false )
@@ -130,7 +147,7 @@ export function openGraphWindow({ graphKey, meta }: OpenArgs) {
130147 } catch ( e ) {
131148 // If it threw, treat it as dead and try again once
132149 graphWins [ graphKey ] = undefined
133- return openGraphWindow ( { graphKey, meta } )
150+ return openGraphWindow ( { graphKey, meta } , parentWindow )
134151 }
135152 }
136153
@@ -180,8 +197,9 @@ export default function registerGraphWindowIPC(appWin?: BrowserWindow) {
180197 sendInit ( graphKey )
181198 } )
182199
183- ipcMain . handle ( "app:open-graph-window" , ( _event , args : OpenArgs ) => {
184- openGraphWindow ( args )
200+ ipcMain . handle ( "app:open-graph-window" , ( event , args : OpenArgs ) => {
201+ const parentWindow = BrowserWindow . fromWebContents ( event . sender )
202+ openGraphWindow ( args , parentWindow || undefined )
185203 } )
186204
187205 ipcMain . handle ( "app:close-graph-window" , ( _event , args : CloseArgs ) => {
0 commit comments