@@ -3,6 +3,9 @@ import { join } from "path";
33import { electronApp , optimizer , is } from "@electron-toolkit/utils" ;
44import icon from "../../resources/icon.png?asset" ;
55import { existsSync , readFileSync } from "fs" ;
6+ import dotenv from "dotenv" ;
7+ import { handleExecuteCode } from "./lib/execute-code" ;
8+ dotenv . config ( ) ;
69
710function createWindow ( ) : void {
811 // Create the browser window.
@@ -34,8 +37,6 @@ function createWindow(): void {
3437 return { action : "deny" } ;
3538 } ) ;
3639
37- // HMR for renderer base on electron-vite cli.
38- // Load the remote URL for development or the local html file for production.
3940 if ( is . dev && process . env [ "ELECTRON_RENDERER_URL" ] ) {
4041 mainWindow . webContents . openDevTools ( ) ;
4142 mainWindow . loadURL ( process . env [ "ELECTRON_RENDERER_URL" ] ) ;
@@ -44,51 +45,33 @@ function createWindow(): void {
4445 }
4546}
4647
47- // This method will be called when Electron has finished
48- // initialization and is ready to create browser windows.
49- // Some APIs can only be used after this event occurs.
5048app . whenReady ( ) . then ( ( ) => {
5149 is . dev && app . commandLine . appendSwitch ( "ignore-certificate-errors" ) ;
52-
5350 // Register the custom protocol to serve Monaco Editor worker files locally
51+ ipcMain . handle ( "executecode:post" , handleExecuteCode ) ;
5452 protocol . handle ( "monaco-editor" , ( request ) => {
5553 const url = request . url . substr ( "monaco-editor://" . length ) ;
5654
5755 let monacoBasePath ;
5856 if ( is . dev ) {
59- // Adjust this path based on your dev setup relative to dist-electron/main/index.js
6057 monacoBasePath = join ( __dirname , "../../node_modules/monaco-editor/min" ) ;
6158 } else {
62- // Adjust this path based on where 'monaco-editor/min' is copied in your packaged app.
63- // Common paths:
64- // If monaco-editor/min is copied to the root of your packaged app:
6559 monacoBasePath = join ( app . getAppPath ( ) , "node_modules/monaco-editor/min" ) ;
66- // If it's copied to a specific asset folder like 'assets/monaco':
67- // monacoBasePath = join(app.getAppPath(), 'assets', 'monaco');
6860 }
69-
7061 const filePath = join ( monacoBasePath , url ) ;
71- console . log ( "Serving monaco-editor:// file:" , filePath ) ; // Keep this for debugging!
72-
7362 if ( existsSync ( filePath ) ) {
7463 return new Response ( readFileSync ( filePath ) ) ;
7564 } else {
7665 console . error ( "Monaco Editor file not found:" , filePath ) ;
77- // It's crucial to return a proper 404 or an empty response for missing files.
78- // Returning a null or undefined can cause issues.
7966 return new Response ( "File not found" , { status : 404 } ) ;
8067 }
8168 } ) ;
82- // Set app user model id for windows
83- electronApp . setAppUserModelId ( "com.executeme" ) ;
8469
70+ electronApp . setAppUserModelId ( "com.executeme" ) ;
8571 app . on ( "browser-window-created" , ( _ , window ) => {
8672 optimizer . watchWindowShortcuts ( window ) ;
8773 } ) ;
8874
89- // IPC test
90- ipcMain . on ( "ping" , ( ) => console . log ( "pong" ) ) ;
91-
9275 createWindow ( ) ;
9376
9477 app . on ( "activate" , function ( ) {
@@ -101,6 +84,3 @@ app.on("window-all-closed", () => {
10184 app . quit ( ) ;
10285 }
10386} ) ;
104-
105- // In this file you can include the rest of your app's specific main process
106- // code. You can also put them in separate files and require them here.
0 commit comments