1- import { app , shell , BrowserWindow } from ' electron'
2- import { join } from ' path'
3- import { electronApp , optimizer , is } from ' @electron-toolkit/utils'
4- import icon from ' ../../resources/icon.png?asset'
1+ import { app , shell , BrowserWindow , ipcMain } from " electron" ;
2+ import { join } from " path" ;
3+ import { electronApp , optimizer , is } from " @electron-toolkit/utils" ;
4+ import icon from " ../../resources/icon.png?asset" ;
55
66function createWindow ( ) : void {
77 // Create the browser window.
@@ -10,28 +10,28 @@ function createWindow(): void {
1010 height : 670 ,
1111 show : false ,
1212 autoHideMenuBar : true ,
13- ...( process . platform === ' linux' ? { icon } : { } ) ,
13+ ...( process . platform === " linux" ? { icon } : { } ) ,
1414 webPreferences : {
15- preload : join ( __dirname , ' ../preload/index.js' ) ,
16- sandbox : false
17- }
18- } )
15+ preload : join ( __dirname , " ../preload/index.js" ) ,
16+ sandbox : false ,
17+ } ,
18+ } ) ;
1919
20- mainWindow . on ( ' ready-to-show' , ( ) => {
21- mainWindow . show ( )
22- } )
20+ mainWindow . on ( " ready-to-show" , ( ) => {
21+ mainWindow . show ( ) ;
22+ } ) ;
2323
2424 mainWindow . webContents . setWindowOpenHandler ( ( details ) => {
25- shell . openExternal ( details . url )
26- return { action : ' deny' }
27- } )
25+ shell . openExternal ( details . url ) ;
26+ return { action : " deny" } ;
27+ } ) ;
2828
2929 // HMR for renderer base on electron-vite cli.
3030 // Load the remote URL for development or the local html file for production.
31- if ( is . dev && process . env [ ' ELECTRON_RENDERER_URL' ] ) {
32- mainWindow . loadURL ( process . env [ ' ELECTRON_RENDERER_URL' ] )
31+ if ( is . dev && process . env [ " ELECTRON_RENDERER_URL" ] ) {
32+ mainWindow . loadURL ( process . env [ " ELECTRON_RENDERER_URL" ] ) ;
3333 } else {
34- mainWindow . loadFile ( join ( __dirname , ' ../renderer/index.html' ) )
34+ mainWindow . loadFile ( join ( __dirname , " ../renderer/index.html" ) ) ;
3535 }
3636}
3737
@@ -40,32 +40,37 @@ function createWindow(): void {
4040// Some APIs can only be used after this event occurs.
4141app . whenReady ( ) . then ( ( ) => {
4242 // Set app user model id for windows
43- electronApp . setAppUserModelId ( ' com.electron' )
43+ electronApp . setAppUserModelId ( " com.electron" ) ;
4444
4545 // Default open or close DevTools by F12 in development
4646 // and ignore CommandOrControl + R in production.
4747 // see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
48- app . on ( ' browser-window-created' , ( _ , window ) => {
49- optimizer . watchWindowShortcuts ( window )
50- } )
48+ app . on ( " browser-window-created" , ( _ , window ) => {
49+ optimizer . watchWindowShortcuts ( window ) ;
50+ } ) ;
5151
52- createWindow ( )
52+ createWindow ( ) ;
5353
54- app . on ( ' activate' , function ( ) {
54+ app . on ( " activate" , function ( ) {
5555 // On macOS it's common to re-create a window in the app when the
5656 // dock icon is clicked and there are no other windows open.
57- if ( BrowserWindow . getAllWindows ( ) . length === 0 ) createWindow ( )
58- } )
59- } )
57+ if ( BrowserWindow . getAllWindows ( ) . length === 0 ) createWindow ( ) ;
58+ } ) ;
59+ } ) ;
6060
6161// Quit when all windows are closed, except on macOS. There, it's common
6262// for applications and their menu bar to stay active until the user quits
6363// explicitly with Cmd + Q.
64- app . on ( ' window-all-closed' , ( ) => {
65- if ( process . platform !== ' darwin' ) {
66- app . quit ( )
64+ app . on ( " window-all-closed" , ( ) => {
65+ if ( process . platform !== " darwin" ) {
66+ app . quit ( ) ;
6767 }
68- } )
68+ } ) ;
6969
7070// In this file you can include the rest of your app"s specific main process
7171// code. You can also put them in separate files and require them here.
72+
73+ // "server-side API"
74+ ipcMain . handle ( "ping" , ( ) => {
75+ return "pong" ;
76+ } ) ;
0 commit comments