diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 0e63f11600..936a0dd008 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -115,9 +115,6 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) { const appUpdater = new AppUpdater() const notificationService = new NotificationService() - // Initialize Python service with main window - pythonService.setMainWindow(mainWindow) - const checkMainWindow = () => { if (!mainWindow || mainWindow.isDestroyed()) { throw new Error('Main window does not exist or has been destroyed') diff --git a/src/main/services/PythonService.ts b/src/main/services/PythonService.ts index b4b2596831..e9f59fa3be 100644 --- a/src/main/services/PythonService.ts +++ b/src/main/services/PythonService.ts @@ -1,8 +1,9 @@ import { randomUUID } from 'node:crypto' -import type { BrowserWindow } from 'electron' import { ipcMain } from 'electron' +import { windowService } from './WindowService' + interface PythonExecutionRequest { id: string script: string @@ -21,7 +22,6 @@ interface PythonExecutionResponse { */ export class PythonService { private static instance: PythonService | null = null - private mainWindow: BrowserWindow | null = null private pendingRequests = new Map void; reject: (error: Error) => void }>() private constructor() { @@ -51,10 +51,6 @@ export class PythonService { }) } - public setMainWindow(mainWindow: BrowserWindow) { - this.mainWindow = mainWindow - } - /** * Execute Python code by sending request to renderer PyodideService */ @@ -63,8 +59,8 @@ export class PythonService { context: Record = {}, timeout: number = 60000 ): Promise { - if (!this.mainWindow) { - throw new Error('Main window not set in PythonService') + if (!windowService.getMainWindow()) { + throw new Error('Main window not found') } return new Promise((resolve, reject) => { @@ -95,7 +91,7 @@ export class PythonService { // Send request to renderer const request: PythonExecutionRequest = { id: requestId, script, context, timeout } - this.mainWindow?.webContents.send('python-execution-request', request) + windowService.getMainWindow()?.webContents.send('python-execution-request', request) }) } }