1- const { app, Tray, Menu, BrowserWindow, ipcMain, Notification } = require ( 'electron' ) ;
2- const { PARAMS , VALUE , MicaBrowserWindow, IS_WINDOWS_11 , WIN10 } = require ( 'mica-electron' ) ;
3- const path = require ( 'path' ) ;
1+ const {
2+ app,
3+ Tray,
4+ Menu,
5+ BrowserWindow,
6+ ipcMain,
7+ Notification,
8+ } = require ( "electron" ) ;
9+ const {
10+ PARAMS ,
11+ VALUE ,
12+ MicaBrowserWindow,
13+ IS_WINDOWS_11 ,
14+ WIN10 ,
15+ } = require ( "mica-electron" ) ;
16+ const path = require ( "path" ) ;
417
518let mainWindow ;
619let themeEditorWindow = null ;
720let tray = null ;
821
9-
10- app . on ( 'ready' , ( ) => {
22+ app . on ( "ready" , ( ) => {
1123 mainWindow = new MicaBrowserWindow ( {
1224 width : 1200 ,
1325 height : 700 ,
1426 webPreferences : {
1527 contextIsolation : true ,
1628 nodeIntegration : false ,
17- preload : __dirname + ' /preload.js' ,
29+ preload : path . join ( __dirname , " /preload.js" ) ,
1830 } ,
1931 menuBarVisible : false ,
2032 frame : false ,
2133 show : false ,
22- titleBarStyle : ' hidden' ,
23- ...( process . platform !== ' darwin' ? { titleBarOverlay : true } : { } )
34+ titleBarStyle : " hidden" ,
35+ ...( process . platform !== " darwin" ? { titleBarOverlay : true } : { } ) ,
2436 } ) ;
2537
26- if ( require ( ' electron-squirrel-startup' ) ) app . quit ( ) ;
38+ if ( require ( " electron-squirrel-startup" ) ) app . quit ( ) ;
2739
2840 mainWindow . setRoundedCorner ( ) ;
2941 mainWindow . setMicaAcrylicEffect ( ) ;
3042
3143 mainWindow . setTitleBarOverlay ( {
32- color : ' rgba(0, 0, 0, 0)' , // Transparent background
33- symbolColor : ' rgba(255, 255, 255, 1)' , // Symbol color
34- height : 48
44+ color : " rgba(0, 0, 0, 0)" , // Transparent background
45+ symbolColor : " rgba(255, 255, 255, 1)" , // Default to light symbols (for dark themes)
46+ height : 48 ,
3547 } ) ;
3648
3749 mainWindow . setMinimumSize ( 1200 , 700 ) ;
3850
3951 //Menu.setApplicationMenu(null);
4052
41- mainWindow . loadFile ( ' index.html' ) ;
53+ mainWindow . loadFile ( " index.html" ) ;
4254
43- mainWindow . webContents . once ( ' dom-ready' , ( ) => {
55+ mainWindow . webContents . once ( " dom-ready" , ( ) => {
4456 mainWindow . show ( ) ; // Show the window only when DOM is ready
4557 } ) ;
4658
47- mainWindow . on ( 'closed' , ( ) => {
48- app . quit ( ) ;
59+ mainWindow . on ( "closed" , ( ) => {
60+ mainWindow = null ;
61+ if ( themeEditorWindow ) {
62+ themeEditorWindow . close ( ) ; // Close editor if main closes
63+ }
64+ // app.quit()
4965 } ) ;
5066
51- ipcMain . on ( ' show-notification' , ( event , title , body ) => {
67+ ipcMain . on ( " show-notification" , ( event , title , body ) => {
5268 showNotification ( title , body ) ;
5369 } ) ;
5470
55- ipcMain . on ( ' open-dev-tools' , ( ) => {
71+ ipcMain . on ( " open-dev-tools" , ( ) => {
5672 if ( mainWindow ) {
5773 mainWindow . webContents . openDevTools ( ) ;
5874 }
5975 } ) ;
6076
61- tray = new Tray ( path . join ( __dirname , 'assets/icon.png' ) ) ;
77+ ipcMain . on ( "set-titlebar-overlay" , ( event , options ) => {
78+ if ( mainWindow ) {
79+ const symbolColor = options . isLight
80+ ? "rgba(0, 0, 0, 1)"
81+ : "rgba(255, 255, 255, 1)" ;
82+ mainWindow . setTitleBarOverlay ( {
83+ color : "rgba(0, 0, 0, 0)" ,
84+ symbolColor : symbolColor ,
85+ height : 48 ,
86+ } ) ;
87+ }
88+ } ) ;
89+
90+ tray = new Tray ( path . join ( __dirname , "assets/icon.png" ) ) ;
6291 const contextMenu = Menu . buildFromTemplate ( [
6392 {
64- label : 'Check for Updates' , click : ( ) => {
93+ label : "Check for Updates" ,
94+ click : ( ) => {
6595 console . log ( "Check for Updates menu item clicked" ) ;
6696 if ( mainWindow ) {
67- mainWindow . webContents . send ( ' check-for-updates' ) ; // Send to renderer
97+ mainWindow . webContents . send ( " check-for-updates" ) ; // Send to renderer
6898 }
69- }
99+ } ,
70100 } ,
71- { type : ' separator' } ,
72- { label : ' Quit' , click : ( ) => app . quit ( ) }
101+ { type : " separator" } ,
102+ { label : " Quit" , click : ( ) => app . quit ( ) } ,
73103 ] ) ;
74- tray . setToolTip ( ' Iota\ 's Notepad' ) ;
104+ tray . setToolTip ( " Iota's Notepad" ) ;
75105 tray . setContextMenu ( contextMenu ) ;
76106} ) ;
77107
@@ -87,43 +117,43 @@ function createThemeEditorWindow() {
87117 webPreferences : {
88118 contextIsolation : true ,
89119 nodeIntegration : false ,
90- preload : path . join ( __dirname , ' preload.js' ) ,
120+ preload : path . join ( __dirname , " preload.js" ) ,
91121 } ,
92122 title : "Theme Editor" ,
93123 autoHideMenuBar : true ,
94124 } ) ;
95125
96126 themeEditorWindow . maximize ( ) ;
97127
98- themeEditorWindow . loadURL ( ' https://vorlie.pages.dev/theme-editor' ) ;
128+ themeEditorWindow . loadURL ( " https://vorlie.pages.dev/theme-editor" ) ;
99129
100- themeEditorWindow . on ( ' closed' , ( ) => {
130+ themeEditorWindow . on ( " closed" , ( ) => {
101131 themeEditorWindow = null ;
102132 } ) ;
103133}
104134
105135// IPC listener to open the theme editor
106- ipcMain . on ( ' open-theme-editor' , ( ) => {
136+ ipcMain . on ( " open-theme-editor" , ( ) => {
107137 createThemeEditorWindow ( ) ;
108138} ) ;
109139
110- app . on ( ' window-all-closed' , ( ) => {
111- if ( process . platform !== ' darwin' ) app . quit ( ) ;
140+ app . on ( " window-all-closed" , ( ) => {
141+ if ( process . platform !== " darwin" ) app . quit ( ) ;
112142} ) ;
113143
114144function showNotification ( title , body ) {
115145 if ( Notification . isSupported ( ) ) {
116146 let iconPath ;
117- iconPath = path . join ( __dirname , ' assets' , ' icon.png' ) ;
147+ iconPath = path . join ( __dirname , " assets" , " icon.png" ) ;
118148
119149 const notification = new Notification ( {
120150 title : title ,
121151 body : body ,
122152 icon : iconPath ,
123153 } ) ;
124154
125- notification . on ( ' click' , ( ) => {
126- console . log ( ' Notification clicked' ) ;
155+ notification . on ( " click" , ( ) => {
156+ console . log ( " Notification clicked" ) ;
127157 if ( mainWindow ) {
128158 if ( mainWindow . isMinimized ( ) ) mainWindow . restore ( ) ;
129159 mainWindow . focus ( ) ;
@@ -132,6 +162,6 @@ function showNotification(title, body) {
132162
133163 notification . show ( ) ;
134164 } else {
135- console . log ( ' Notifications are not supported on this system.' ) ;
165+ console . log ( " Notifications are not supported on this system." ) ;
136166 }
137- }
167+ }
0 commit comments