Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified build/icon.icns
Binary file not shown.
Binary file modified build/icon.ico
Binary file not shown.
Binary file modified build/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions src/main/config/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AppSettings } from './types'
import { ShortcutAction, type ShortcutConfig } from '../../shared/types'

/**
* 默认设置 - 单一数据源
Expand Down Expand Up @@ -87,3 +88,44 @@ Please generate a mind map structure based on the above content, strictly follow
}
}
}

/**
* 默认快捷键配置
*/
export const defaultShortcuts: ShortcutConfig[] = [
// 笔记本管理
{
action: ShortcutAction.CREATE_NOTEBOOK,
accelerator: 'CommandOrControl+N',
enabled: true,
description: 'shortcuts:createNotebook'
},
{
action: ShortcutAction.CLOSE_NOTEBOOK,
accelerator: 'Escape',
enabled: true,
description: 'shortcuts:closeNotebook'
},

// 面板切换
{
action: ShortcutAction.TOGGLE_KNOWLEDGE_BASE,
accelerator: 'CommandOrControl+K',
enabled: true,
description: 'shortcuts:toggleKnowledgeBase'
},
{
action: ShortcutAction.TOGGLE_CREATIVE_SPACE,
accelerator: 'CommandOrControl+E',
enabled: true,
description: 'shortcuts:toggleCreativeSpace'
},

// 消息/聊天
{
action: ShortcutAction.SEND_MESSAGE,
accelerator: 'CommandOrControl+Enter',
enabled: true,
description: 'shortcuts:sendMessage'
}
]
5 changes: 3 additions & 2 deletions src/main/config/store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Store from 'electron-store'
import type { StoreSchema } from './types'
import { defaultSettings } from './defaults'
import { defaultSettings, defaultShortcuts } from './defaults'

/**
* 创建 electron-store 实例(使用动态导入)
Expand All @@ -13,7 +13,8 @@ export async function getStore(): Promise<Store<StoreSchema>> {
store = new Store<StoreSchema>({
defaults: {
settings: defaultSettings,
providers: {}
providers: {},
shortcuts: defaultShortcuts
},
name: 'knownote-config',
// 文件会保存在: ~/Library/Application Support/knownote/knownote-config.json (macOS)
Expand Down
3 changes: 2 additions & 1 deletion src/main/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AppSettings } from '../../shared/types'
import type { AppSettings, ShortcutConfig } from '../../shared/types'

/**
* 提供商配置接口
Expand All @@ -16,6 +16,7 @@ export interface ProviderConfig {
export interface StoreSchema {
settings: AppSettings
providers: Record<string, ProviderConfig>
shortcuts: ShortcutConfig[]
}

// 重新导出 AppSettings 以保持向后兼容
Expand Down
35 changes: 33 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ import { ProviderManager } from './providers/ProviderManager'
import { SessionAutoSwitchService } from './services/SessionAutoSwitchService'
import { KnowledgeService } from './services/KnowledgeService'
import { UpdateService } from './services/UpdateService'
import { ShortcutManager } from './services/ShortcutManager'
import { createMainWindow, createSettingsWindow, destroySettingsWindow } from './windows'
import { registerAllHandlers } from './ipc'
import { getStore } from './config/store'
import Logger from '../shared/utils/logger'

let providerManager: ProviderManager | null = null
let sessionAutoSwitchService: SessionAutoSwitchService | null = null
let knowledgeService: KnowledgeService | null = null
let updateService: UpdateService | null = null
let shortcutManager: ShortcutManager | null = null
let isQuitting = false // Flag to indicate if app is quitting

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
app.whenReady().then(async () => {
// Set app user model id for windows
electronApp.setAppUserModelId('com.knownote.app')

Expand Down Expand Up @@ -62,8 +65,25 @@ app.whenReady().then(() => {
updateService = new UpdateService()
Logger.info('Main', 'Update Service initialized')

// Initialize electron-store
Logger.info('Main', 'Initializing electron-store...')
const store = await getStore()
Logger.info('Main', 'electron-store initialized')

// Initialize Shortcut Manager
Logger.info('Main', 'Initializing Shortcut Manager...')
shortcutManager = new ShortcutManager(store)
Logger.info('Main', 'Shortcut Manager initialized')

// Register all IPC Handlers
registerAllHandlers(providerManager, sessionAutoSwitchService, knowledgeService, updateService)
registerAllHandlers(
providerManager,
sessionAutoSwitchService,
knowledgeService,
updateService,
shortcutManager,
store
)

// IPC test (development only)
if (process.env.NODE_ENV === 'development') {
Expand Down Expand Up @@ -102,6 +122,11 @@ app.whenReady().then(() => {
// Set main window for update service
updateService.setMainWindow(mainWindow)

// Set main window for shortcut manager and register shortcuts
shortcutManager.setMainWindow(mainWindow)
shortcutManager.registerShortcuts()
Logger.info('Main', 'Shortcuts registered')

// Check for updates on startup (after 5 seconds)
updateService.checkForUpdatesOnStartup()

Expand Down Expand Up @@ -138,6 +163,12 @@ app.on('before-quit', () => {
isQuitting = true
destroySettingsWindow()

// Unregister shortcuts
if (shortcutManager) {
shortcutManager.unregisterShortcuts()
Logger.info('Main', 'Shortcuts unregistered')
}

Logger.info('Main', 'Closing database connection...')
closeDatabase()
})
Expand Down
9 changes: 8 additions & 1 deletion src/main/ipc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { SessionAutoSwitchService } from '../services/SessionAutoSwitchService'
import { KnowledgeService } from '../services/KnowledgeService'
import { UpdateService } from '../services/UpdateService'
import { MindMapService } from '../services/MindMapService'
import { ShortcutManager } from '../services/ShortcutManager'
import type Store from 'electron-store'
import type { StoreSchema } from '../config/types'
import { registerChatHandlers } from './chatHandlers'
import { registerProviderHandlers } from './providerHandlers'
import { registerSettingsHandlers } from './settingsHandlers'
Expand All @@ -12,6 +15,7 @@ import { registerKnowledgeHandlers } from './knowledgeHandlers'
import { registerMindMapHandlers } from './mindmapHandlers'
import { registerUpdateHandlers } from './updateHandlers'
import { registerItemHandlers } from './itemHandlers'
import { registerShortcutHandlers } from './shortcutHandlers'

/**
* 注册所有 IPC Handlers
Expand All @@ -20,7 +24,9 @@ export function registerAllHandlers(
providerManager: ProviderManager,
sessionAutoSwitchService: SessionAutoSwitchService,
knowledgeService: KnowledgeService,
updateService: UpdateService
updateService: UpdateService,
shortcutManager: ShortcutManager,
store: Store<StoreSchema>
) {
// 实例化 MindMapService
const mindMapService = new MindMapService(providerManager)
Expand All @@ -34,6 +40,7 @@ export function registerAllHandlers(
registerMindMapHandlers(mindMapService)
registerUpdateHandlers(updateService)
registerItemHandlers()
registerShortcutHandlers(shortcutManager, store)
console.log('[IPC] All handlers registered')
}

Expand Down
40 changes: 40 additions & 0 deletions src/main/ipc/shortcutHandlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ipcMain } from 'electron'
import type Store from 'electron-store'
import { ShortcutConfig, ShortcutAction } from '../../shared/types'
import { ShortcutManager } from '../services/ShortcutManager'
import type { StoreSchema } from '../config/types'

/**
* 注册快捷键相关的 IPC Handlers
*/
export function registerShortcutHandlers(shortcutManager: ShortcutManager, store: Store<StoreSchema>): void {
// 获取所有快捷键
ipcMain.handle('shortcuts:getAll', (): ShortcutConfig[] => {
return (store.get('shortcuts') as ShortcutConfig[]) || []
})

// 更新快捷键
ipcMain.handle(
'shortcuts:update',
(_event, action: ShortcutAction, accelerator: string): void => {
shortcutManager.updateShortcut(action, accelerator)
}
)

// 切换快捷键的启用/禁用状态
ipcMain.handle('shortcuts:toggle', (_event, action: ShortcutAction, enabled: boolean): void => {
shortcutManager.toggleShortcut(action, enabled)
})

// 重置单个快捷键为默认值
ipcMain.handle('shortcuts:resetSingle', (_event, action: ShortcutAction): void => {
shortcutManager.resetSingle(action)
})

// 重置为默认配置
ipcMain.handle('shortcuts:reset', (): void => {
shortcutManager.resetToDefaults()
})

console.log('[IPC] Shortcut handlers registered')
}
Loading