@@ -59,14 +59,17 @@ export function createTray(mainWindow: BrowserWindow): Tray {
5959 // Set tooltip
6060 tray . setToolTip ( 'ClawX - AI Assistant' ) ;
6161
62+ const showWindow = ( ) => {
63+ if ( mainWindow . isDestroyed ( ) ) return ;
64+ mainWindow . show ( ) ;
65+ mainWindow . focus ( ) ;
66+ } ;
67+
6268 // Create context menu
6369 const contextMenu = Menu . buildFromTemplate ( [
6470 {
6571 label : 'Show ClawX' ,
66- click : ( ) => {
67- mainWindow . show ( ) ;
68- mainWindow . focus ( ) ;
69- } ,
72+ click : showWindow ,
7073 } ,
7174 {
7275 type : 'separator' ,
@@ -90,20 +93,23 @@ export function createTray(mainWindow: BrowserWindow): Tray {
9093 {
9194 label : 'Open Dashboard' ,
9295 click : ( ) => {
96+ if ( mainWindow . isDestroyed ( ) ) return ;
9397 mainWindow . show ( ) ;
9498 mainWindow . webContents . send ( 'navigate' , '/' ) ;
9599 } ,
96100 } ,
97101 {
98102 label : 'Open Chat' ,
99103 click : ( ) => {
104+ if ( mainWindow . isDestroyed ( ) ) return ;
100105 mainWindow . show ( ) ;
101106 mainWindow . webContents . send ( 'navigate' , '/chat' ) ;
102107 } ,
103108 } ,
104109 {
105110 label : 'Open Settings' ,
106111 click : ( ) => {
112+ if ( mainWindow . isDestroyed ( ) ) return ;
107113 mainWindow . show ( ) ;
108114 mainWindow . webContents . send ( 'navigate' , '/settings' ) ;
109115 } ,
@@ -116,6 +122,7 @@ export function createTray(mainWindow: BrowserWindow): Tray {
116122 {
117123 label : 'Check for Updates...' ,
118124 click : ( ) => {
125+ if ( mainWindow . isDestroyed ( ) ) return ;
119126 mainWindow . webContents . send ( 'update:check' ) ;
120127 } ,
121128 } ,
@@ -134,6 +141,7 @@ export function createTray(mainWindow: BrowserWindow): Tray {
134141
135142 // Click to show window (Windows/Linux)
136143 tray . on ( 'click' , ( ) => {
144+ if ( mainWindow . isDestroyed ( ) ) return ;
137145 if ( mainWindow . isVisible ( ) ) {
138146 mainWindow . hide ( ) ;
139147 } else {
@@ -144,6 +152,7 @@ export function createTray(mainWindow: BrowserWindow): Tray {
144152
145153 // Double-click to show window (Windows)
146154 tray . on ( 'double-click' , ( ) => {
155+ if ( mainWindow . isDestroyed ( ) ) return ;
147156 mainWindow . show ( ) ;
148157 mainWindow . focus ( ) ;
149158 } ) ;
0 commit comments