@@ -15,7 +15,6 @@ import {
1515 PubSubClient ,
1616 ElectronEventService ,
1717 PostHogService ,
18- SentryService ,
1918 registerSSRProtocols ,
2019 GlobalShortcutService ,
2120 registerDeepLinkingProtocol ,
@@ -29,106 +28,130 @@ import log from 'electron-log'
2928
3029import { createAppReady } from '@slide.code/schema/messages'
3130
31+ log . info ( '[MAIN] 🚀 Starting SlideCode main process' )
32+ log . info ( '[MAIN] 📍 Current working directory:' , process . cwd ( ) )
33+ log . info ( '[MAIN] 🔧 Node version:' , process . version )
34+ log . info ( '[MAIN] 🔧 Electron version:' , process . versions . electron )
35+ log . info ( '[MAIN] 📦 App version:' , app . getVersion ( ) )
36+
3237// Global references to prevent garbage collection
3338let eventHandlerFiber : Fiber . RuntimeFiber < any , any > | null = null
3439
3540// Using the generator approach with Effect.gen
3641const program = Effect . gen ( function * ( ) {
3742 try {
43+ log . info ( '[MAIN] 🔄 Starting main program execution' )
44+
3845 // First register SSR protocols before app is ready and any service initialization
46+ log . info ( '[MAIN] 🔗 Registering SSR protocols' )
3947 yield * registerSSRProtocols
48+ log . info ( '[MAIN] ✅ SSR protocols registered' )
4049
4150 // Register custom protocol for deep linking
51+ log . info ( '[MAIN] 🔗 Registering deep linking protocol' )
4252 yield * registerDeepLinkingProtocol
53+ log . info ( '[MAIN] ✅ Deep linking protocol registered' )
4354
4455 // Get services (these are now scoped to the runtime)
56+ log . info ( '[MAIN] 🛠️ Initializing services' )
4557 // const sentry = yield* SentryService
4658 const update = yield * UpdateRef
4759 const menuService = yield * MenuService
4860 const pubsub = yield * PubSubClient
4961 const electronEventService = yield * ElectronEventService // Get the electron event service
5062 const posthog = yield * PostHogService // Get the PostHog service
51- const sentry = yield * SentryService
5263 const userRef = yield * UserRef
5364 const dbService = yield * DatabaseService
65+ log . info ( '[MAIN] ✅ Services initialized' )
5466
5567 // const globalShortcutService = yield* GlobalShortcutService
5668 yield * Effect . logInfo ( 'Initializing ElectronEventService' )
69+ log . info ( '[MAIN] 🔄 Initializing ElectronEventService' )
5770 yield * electronEventService . initialize
71+ log . info ( '[MAIN] ✅ ElectronEventService initialized' )
5872
5973 // Then do other performance optimizations and instance checks
74+ log . info ( '[MAIN] ⚡ Applying performance optimizations and checking single instance' )
6075 yield * Effect . all ( [ configurePerformanceOptimizations , ensureSingleInstance ] )
76+ log . info ( '[MAIN] ✅ Performance optimizations applied and single instance ensured' )
6177
6278 // Create vibe-dir and save path to user ref
79+ log . info ( '[MAIN] 📁 Creating vibe directory' )
6380 const vibeDir = yield * createVibeDir
6481 yield * userRef . updateVibeDirectory ( vibeDir )
82+ log . info ( '[MAIN] ✅ Vibe directory created:' , vibeDir )
6583
6684 // Get configuration using Effect Config
6785 yield * Effect . logInfo ( 'Loading configuration' )
86+ log . info ( '[MAIN] ⚙️ Loading configuration' )
6887 const updateConfig = yield * config . updateConfig
6988 const posthogConfig = yield * config . posthogConfig
7089 const sentryConfig = yield * config . sentryConfig
7190 const dbConfig = yield * config . databaseConfig
72-
73- // Only initialize Sentry if DSN is available
74- if ( sentryConfig . dsn ) {
75- yield * Effect . logInfo ( 'Initializing Sentry with DSN' , sentryConfig . dsn )
76- yield * sentry . initialize ( {
77- ...sentryConfig ,
78- dsn : sentryConfig . dsn
79- } )
80- } else {
81- yield * Effect . logInfo ( 'Skipping Sentry initialization - DSN not provided' )
82- }
91+ log . info ( '[MAIN] ✅ Configuration loaded' )
8392
8493 // Initialize PostHog if API key is available
8594 if ( posthogConfig . apiKey ) {
8695 yield * Effect . logInfo ( 'Initializing PostHog' )
96+ log . info ( '[MAIN] 📊 Initializing PostHog' )
8797 yield * posthog . initialize ( {
8898 ...posthogConfig ,
8999 apiKey : posthogConfig . apiKey
90100 } )
91101
92102 yield * posthog . captureAppLaunched ( )
103+ log . info ( '[MAIN] ✅ PostHog initialized and app launch captured' )
93104 } else {
94105 yield * Effect . logInfo ( 'Skipping PostHog initialization - API key not provided' )
106+ log . info ( '[MAIN] ⚠️ Skipping PostHog initialization - API key not provided' )
95107 }
96108
97109 // Wait for app to be ready before proceeding
110+ log . info ( '[MAIN] ⏳ Waiting for Electron app to be ready' )
98111 yield * Effect . promise ( ( ) => app . whenReady ( ) )
99112 yield * Effect . logInfo ( '📱 App ready, starting up' )
113+ log . info ( '[MAIN] ✅ Electron app is ready, continuing startup' )
100114
101115 // Initialize the update service
102116 if ( updateConfig . updateSiteURL ) {
103117 yield * Effect . logInfo ( 'Initializing UpdateService' , updateConfig )
118+ log . info ( '[MAIN] 🔄 Initializing UpdateService with URL:' , updateConfig . updateSiteURL )
104119 yield * update . initialize ( {
105120 updateSiteURL : updateConfig . updateSiteURL ,
106121 checkInterval : updateConfig . checkInterval ,
107122 automaticChecks : updateConfig . automaticChecks
108123 } )
124+ log . info ( '[MAIN] ✅ UpdateService initialized' )
109125 } else {
110126 yield * Effect . logInfo ( 'Skipping UpdateService initialization - no URL provided' )
127+ log . info ( '[MAIN] ⚠️ Skipping UpdateService initialization - no URL provided' )
111128 }
112129
113130 try {
114131 // Initialize and run migrations in one step
132+ log . info ( '[MAIN] 🗄️ Initializing database and running migrations' , dbConfig )
115133 yield * dbService . initAndMigrate ( dbConfig )
134+ log . info ( '[MAIN] ✅ Database initialized and migrated successfully' )
116135 // logger.info('Database initialized and migrated successfully')
117136 } catch ( error ) {
118137 // logger.error('Database initialization failed:', error)
138+ log . error ( '[MAIN] ❌ Database initialization failed:' , error )
119139 // actions.initFail(`Failed to initialize database. Please restart the application. ${error}`)
120140 return yield * Effect . fail ( error )
121141 }
122142
123143 // Handle app events using the ElectronEventService
144+ log . info ( '[MAIN] 🔄 Setting up event handler stream' )
124145 const eventHandler = electronEventService . stream . pipe (
125146 Stream . tap ( ( event ) => Effect . logInfo ( `🔄 Processing event: ${ event . _tag } ` ) ) ,
126147 Stream . tap ( ( event ) =>
127148 Effect . sync ( ( ) => console . log ( '🔄 Processing event' , JSON . stringify ( event , null , 2 ) ) )
128149 ) ,
150+ Stream . tap ( ( event ) => Effect . sync ( ( ) => log . info ( '[MAIN] 🔄 Processing event:' , event . _tag ) ) ) ,
129151 Stream . runForEach ( ( event ) => {
130152 return Effect . gen ( function * ( ) {
131153 yield * Effect . logInfo ( `Handling electron event: ${ event . _tag } ` , event )
154+ log . info ( '[MAIN] 🔄 Handling electron event:' , event . _tag )
132155
133156 return yield * Match . value ( event . _tag ) . pipe (
134157 Match . when ( 'window-all-closed' , ( ) =>
@@ -171,13 +194,18 @@ const program = Effect.gen(function* () {
171194 // Fork event handler to run in background and save the fiber
172195 eventHandlerFiber = yield * Effect . fork ( eventHandler )
173196 yield * Effect . logInfo ( '🚀 Event handler started' )
197+ log . info ( '[MAIN] ✅ Event handler started and forked' )
174198
175199 // Initialize menu service
200+ log . info ( '[MAIN] 🍔 Creating application menu' )
176201 yield * menuService . createApplicationMenu
202+ log . info ( '[MAIN] ✅ Application menu created' )
177203 // yield* globalShortcutService.initialize
178204
179205 // Send app ready event to trigger SSR demo
206+ log . info ( '[MAIN] 📢 Publishing AppReady event' )
180207 yield * pubsub . publish ( createAppReady ( ) )
208+ log . info ( '[MAIN] ✅ AppReady event published' )
181209
182210 // yield* subscription.openCheckout('price_1RCoB1QQ3xOop9wog1ScGOe1')
183211
@@ -200,6 +228,7 @@ const program = Effect.gen(function* () {
200228 yield * Effect . never
201229 } finally {
202230 yield * Effect . logInfo ( 'Main program exiting' )
231+ log . info ( '[MAIN] 🔚 Main program exiting' )
203232 }
204233} )
205234
0 commit comments