Files
bilin/src/main/ipc/register.ts
T

136 lines
6.6 KiB
TypeScript

import { app } from 'electron'
import { GlobalSettingsService } from '../services/global-settings'
import { BookRegistryService } from '../services/book-registry'
import { SnapshotService } from '../services/snapshot.service'
import { ShortcutManager } from '../shortcuts/manager'
import { WritingLogRepository } from '../db/repositories/writing-log.repo'
import { WritingMilestoneRepository } from '../db/repositories/writing-milestone.repo'
import { PomodoroDailyRepository } from '../db/repositories/pomodoro-daily.repo'
import { WritingLogService } from '../services/writing-log.service'
import { GoalNotificationService } from '../services/goal-notification.service'
import { AchievementService } from '../services/achievement.service'
import { PomodoroService } from '../services/pomodoro.service'
import { WritingSessionRepository } from '../db/repositories/writing-session.repo'
import { WritingSessionService } from '../services/writing-session.service'
import { registerSettingsHandlers } from './handlers/settings.handler'
import { registerBookHandlers } from './handlers/book.handler'
import { registerBookPrefsHandlers } from './handlers/book-prefs.handler'
import { registerChapterHandlers } from './handlers/chapter.handler'
import { registerShortcutHandlers } from './handlers/shortcut.handler'
import { registerOutlineHandlers } from './handlers/outline.handler'
import { registerSettingHandlers } from './handlers/setting.handler'
import { registerInspirationHandlers } from './handlers/inspiration.handler'
import { registerSnapshotHandlers } from './handlers/snapshot.handler'
import { registerBookmarkHandlers } from './handlers/bookmark.handler'
import { registerSearchHandlers } from './handlers/search.handler'
import { registerAiHandlers } from './handlers/ai.handler'
import { registerInteractiveHandlers } from './handlers/interactive.handler'
import { registerAutoHandlers } from './handlers/auto.handler'
import { registerWizardHandlers } from './handlers/wizard.handler'
import { registerKnowledgeHandlers } from './handlers/knowledge.handler'
import { registerCockpitHandlers } from './handlers/cockpit.handler'
import { registerWritingHandlers } from './handlers/writing.handler'
import { registerPomodoroHandlers } from './handlers/pomodoro.handler'
import { registerAchievementHandlers } from './handlers/achievement.handler'
import { registerGraphHandlers } from './handlers/graph.handler'
import { registerAnalyticsHandlers } from './handlers/analytics.handler'
import { registerBridgeHandlers } from './handlers/bridge.handler'
import { registerExportHandlers } from './handlers/export.handler'
import { registerTimelineHandlers } from './handlers/timeline.handler'
import { registerArcHandlers } from './handlers/arc.handler'
import { registerComplianceHandlers } from './handlers/compliance.handler'
import { registerUndoHandlers } from './handlers/undo.handler'
import { registerLogHandlers, registerExtensionHandlers } from './handlers/log.handler'
import { registerUpdateHandlers } from './handlers/update.handler'
import { LogService } from '../services/log.service'
import { AiClientService } from '../services/ai-client.service'
import { NetworkMonitorService } from '../services/network-monitor.service'
let shortcutManager: ShortcutManager | null = null
let snapshotService: SnapshotService | null = null
let networkMonitor: NetworkMonitorService | null = null
export function registerIpc(): {
settings: GlobalSettingsService
books: BookRegistryService
shortcuts: ShortcutManager
logs: LogService
} {
const userData = app.getPath('userData')
const settings = new GlobalSettingsService(userData)
const logs = new LogService(userData)
if (!settings.get().onboardingCompleted) {
const locale = app.getLocale().toLowerCase()
const language = locale.startsWith('en') ? 'en' : 'zh-CN'
settings.update({ language })
}
const books = new BookRegistryService(userData)
const writingLogRepo = new WritingLogRepository(userData)
const writingLogs = new WritingLogService(writingLogRepo, settings)
const milestoneRepo = new WritingMilestoneRepository(writingLogRepo.getDb())
const pomodoroDailyRepo = new PomodoroDailyRepository(writingLogRepo.getDb())
const writingSessionRepo = new WritingSessionRepository(writingLogRepo.getDb())
const writingSessions = new WritingSessionService(writingSessionRepo)
const goalNotify = new GoalNotificationService(settings)
const achievementService = new AchievementService(
milestoneRepo,
writingLogs,
settings,
goalNotify
)
writingLogs.setGoalHooks(achievementService, goalNotify)
const pomodoro = new PomodoroService(writingLogs, pomodoroDailyRepo, settings, goalNotify)
shortcutManager = new ShortcutManager(settings)
snapshotService = new SnapshotService(() => settings.get())
networkMonitor = new NetworkMonitorService()
registerSettingsHandlers(settings)
registerBookHandlers(books, writingSessions)
registerBookPrefsHandlers(books)
registerChapterHandlers(books, writingLogs, writingSessions)
registerShortcutHandlers(shortcutManager)
registerOutlineHandlers(books)
registerSettingHandlers(books)
registerInspirationHandlers(books)
registerSnapshotHandlers(books, snapshotService!)
registerBookmarkHandlers(books)
registerSearchHandlers(books, settings)
const aiClient = new AiClientService(() => settings.get().aiConfig)
registerAiHandlers(books, settings, aiClient)
registerInteractiveHandlers(books, settings, aiClient, writingLogs, writingSessions)
registerAutoHandlers(books, settings, aiClient, writingLogs, writingSessions)
registerWizardHandlers(books, settings, aiClient)
registerKnowledgeHandlers(books, settings, aiClient)
registerCockpitHandlers(books, settings, writingLogs, achievementService, pomodoroDailyRepo)
registerWritingHandlers(writingLogs)
registerPomodoroHandlers(pomodoro)
registerAchievementHandlers(achievementService)
registerGraphHandlers(books)
registerAnalyticsHandlers(books, writingLogs, writingSessionRepo, pomodoroDailyRepo)
registerBridgeHandlers(books, aiClient)
registerExportHandlers(books, settings)
registerTimelineHandlers(books)
registerArcHandlers(books)
registerComplianceHandlers(settings)
registerUndoHandlers(books)
registerLogHandlers(logs)
registerExtensionHandlers()
registerUpdateHandlers()
return { settings, books, shortcuts: shortcutManager, logs }
}
export function getShortcutManager(): ShortcutManager | null {
return shortcutManager
}
export function getNetworkMonitor(): NetworkMonitorService | null {
return networkMonitor
}
export function getSnapshotService(): SnapshotService | null {
return snapshotService
}