1+ import { app , BrowserWindow } from 'electron/main' ;
2+ import path from 'node:path' ;
3+ import { readFileSync } from "node:fs" ;
4+ import { fileURLToPath } from "url" ;
5+
6+ const isDev = process . env . NODE_ENV === 'development' ;
7+ const __filename = fileURLToPath ( import . meta. url ) ;
8+ const __dirname = path . dirname ( __filename ) ;
9+
10+ function createWindow ( ) {
11+ const win = new BrowserWindow ( {
12+ width : 800 ,
13+ height : 600 ,
14+ title : "florr.io - AyuScript"
15+ } ) ;
16+
17+ win . loadURL ( 'https://florr.io/' ) . then ( ( ) => {
18+ win . webContents . executeJavaScript ( `
19+ window.electron = true
20+ ` ) ;
21+ if ( isDev ) {
22+ win . webContents . executeJavaScript ( `
23+ import('http://localhost:5173/__vite-plugin-monkey.install.user.js')
24+ ` ) ;
25+ win . webContents . openDevTools ( ) ;
26+ } else {
27+ const jsPath = path . join ( __dirname , '../dist/ayuscript.user.js' ) ;
28+ const code = readFileSync ( jsPath , 'utf-8' ) ;
29+ win . webContents . executeJavaScript ( code ) ;
30+ }
31+ } ) ;
32+ win . on ( 'page-title-updated' , ( event ) => {
33+ event . preventDefault ( ) ;
34+ } ) ;
35+ win . on ( 'close' , ( event ) => {
36+ event . preventDefault ( )
37+ win . destroy ( ) ;
38+ } ) ;
39+ }
40+
41+ app . whenReady ( ) . then ( ( ) => {
42+ createWindow ( ) ;
43+
44+ app . on ( 'activate' , ( ) => {
45+ if ( BrowserWindow . getAllWindows ( ) . length === 0 ) {
46+ createWindow ( ) ;
47+ }
48+ } ) ;
49+ } ) ;
50+
51+ app . on ( 'window-all-closed' , ( ) => {
52+ app . quit ( ) ;
53+ } ) ;
0 commit comments