1+ const { app, BrowserWindow, shell } = require ( 'electron' ) ;
2+ const path = require ( 'path' ) ;
3+
4+ const isDev = ! app . isPackaged ;
5+ const RENDERER_URL = process . env . RENDERER_URL || 'http://localhost:5173' ;
6+
7+ let win ;
8+
9+ function createWindow ( ) {
10+ console . log ( '[main] isDev =' , isDev , 'RENDERER_URL =' , RENDERER_URL ) ;
11+
12+ win = new BrowserWindow ( {
13+ width : 1280 ,
14+ height : 800 ,
15+ webPreferences : {
16+ contextIsolation : true ,
17+ nodeIntegration : false ,
18+ preload : path . join ( __dirname , 'preload.cjs' ) ,
19+ sandbox : false
20+ }
21+ } ) ;
22+
23+ // 로드 상태 전부 찍기
24+ win . webContents . on ( 'did-start-loading' , ( ) => console . log ( '[main] did-start-loading' ) ) ;
25+ win . webContents . on ( 'did-stop-loading' , ( ) => console . log ( '[main] did-stop-loading' ) ) ;
26+ win . webContents . on ( 'did-finish-load' , ( ) => console . log ( '[main] did-finish-load' ) ) ;
27+ win . webContents . on ( 'did-fail-load' , ( e , code , desc , url ) => {
28+ console . error ( '[main] did-fail-load' , { code, desc, url } ) ;
29+ } ) ;
30+ win . webContents . on ( 'console-message' , ( e , level , message ) => {
31+ console . log ( '[renderer]' , level , message ) ;
32+ } ) ;
33+
34+ if ( isDev ) {
35+ win . loadURL ( RENDERER_URL ) ; // Vite dev 서버
36+ win . webContents . openDevTools ( { mode : 'detach' } ) ;
37+ } else {
38+ const indexPath = path . join ( process . resourcesPath , 'app' , 'dist' , 'index.html' ) ;
39+ win . loadFile ( indexPath ) ;
40+ }
41+
42+ win . webContents . setWindowOpenHandler ( ( { url } ) => { shell . openExternal ( url ) ; return { action : 'deny' } ; } ) ;
43+ }
44+
45+ app . whenReady ( ) . then ( createWindow ) ;
46+ app . on ( 'window-all-closed' , ( ) => { if ( process . platform !== 'darwin' ) app . quit ( ) ; } ) ;
47+ app . on ( 'activate' , ( ) => { if ( BrowserWindow . getAllWindows ( ) . length === 0 ) createWindow ( ) ; } ) ;
0 commit comments