1- import { app , BrowserWindow , Tray , nativeImage , ipcMain , screen } from 'electron'
1+ import { app , BrowserWindow , Tray , nativeImage , ipcMain } from 'electron'
22import * as path from 'path'
33import { execSync } from 'child_process'
44import * as fs from 'fs'
@@ -11,11 +11,10 @@ let mainWindow: BrowserWindow | null = null
1111let socketServer : SocketServer | null = null
1212let sessionManager : SessionManager | null = null
1313
14- const isDev = process . env . NODE_ENV !== 'production' || ! app . isPackaged
15-
1614// Get the path to the menubar icon (Template version for auto dark/light mode)
1715function getTrayIconPath ( ) : string {
18- if ( isDev ) {
16+ // Check app.isPackaged at runtime, not module load time
17+ if ( ! app . isPackaged ) {
1918 // In development, use the assets folder directly
2019 return path . join ( __dirname , '../assets/icons/build/menubar-iconTemplate.png' )
2120 } else {
@@ -24,18 +23,16 @@ function getTrayIconPath(): string {
2423 }
2524}
2625
26+
2727// Create tray icon from file (macOS Template icons auto-adapt to dark/light mode)
2828function createTrayIcon ( ) {
2929 const iconPath = getTrayIconPath ( )
3030 const icon = nativeImage . createFromPath ( iconPath )
31- // Mark as template for macOS dark/light mode support
3231 icon . setTemplateImage ( true )
3332 return icon
3433}
3534
3635function createWindow ( ) {
37- const { width : screenWidth } = screen . getPrimaryDisplay ( ) . workAreaSize
38-
3936 mainWindow = new BrowserWindow ( {
4037 width : 320 ,
4138 height : 400 ,
@@ -52,7 +49,7 @@ function createWindow() {
5249 } ,
5350 } )
5451
55- if ( isDev ) {
52+ if ( ! app . isPackaged ) {
5653 mainWindow . loadURL ( 'http://localhost:5173' )
5754 // mainWindow.webContents.openDevTools({ mode: 'detach' })
5855 } else {
@@ -150,32 +147,40 @@ function getRepoHealth(): {
150147}
151148
152149app . whenReady ( ) . then ( async ( ) => {
153- // Install Claude Code hooks
154- await installHooks ( isDev )
150+ try {
151+ // Install Claude Code hooks (don't block on failure)
152+ try {
153+ await installHooks ( ! app . isPackaged )
154+ } catch ( e ) {
155+ console . error ( 'Hook installation failed:' , e )
156+ }
155157
156- // Create session manager
157- sessionManager = new SessionManager ( )
158- sessionManager . on ( 'update' , ( sessions : Session [ ] ) => {
159- // Send update to renderer
160- mainWindow ?. webContents . send ( 'sessions-updated' , sessions )
158+ // Create session manager
159+ sessionManager = new SessionManager ( )
160+ sessionManager . on ( 'update' , ( sessions : Session [ ] ) => {
161+ // Send update to renderer
162+ mainWindow ?. webContents . send ( 'sessions-updated' , sessions )
161163
162- // Resize window based on session count
163- resizeWindowForSessions ( sessions . length )
164- } )
164+ // Resize window based on session count
165+ resizeWindowForSessions ( sessions . length )
166+ } )
165167
166- // Create socket server and connect to session manager
167- socketServer = new SocketServer ( )
168- socketServer . on ( 'event' , ( event ) => {
169- sessionManager ?. handleEvent ( event )
170- } )
171- socketServer . start ( )
168+ // Create socket server and connect to session manager
169+ socketServer = new SocketServer ( )
170+ socketServer . on ( 'event' , ( event ) => {
171+ sessionManager ?. handleEvent ( event )
172+ } )
173+ socketServer . start ( )
172174
173- // Create tray icon
174- tray = new Tray ( createTrayIcon ( ) )
175- tray . setToolTip ( 'ClaudeGotchi ' )
176- tray . on ( 'click' , toggleWindow )
175+ // Create tray icon
176+ tray = new Tray ( createTrayIcon ( ) )
177+ tray . setToolTip ( 'ClawdGotchi ' )
178+ tray . on ( 'click' , toggleWindow )
177179
178- createWindow ( )
180+ createWindow ( )
181+ } catch ( e ) {
182+ console . error ( 'App initialization failed:' , e )
183+ }
179184
180185 // IPC handlers
181186 ipcMain . handle ( 'get-health' , ( ) => {
@@ -222,7 +227,8 @@ app.on('will-quit', () => {
222227 sessionManager ?. stop ( )
223228} )
224229
225- app . on ( 'activate' , ( ) => {
230+ app . on ( 'activate' , async ( ) => {
231+ await app . whenReady ( )
226232 if ( BrowserWindow . getAllWindows ( ) . length === 0 ) {
227233 createWindow ( )
228234 }
0 commit comments