* launch/tray feature enhance stashed * feature: Issue #2754. launch on boot(win&mac, linux not supported now), min to tray when launch(not only boot), min to tray when close bug-fix: Issue #2576. In Mac, if tray-on-close is set, MainWindow will not show on the dock when closed bug-fix: MiniWindow will hide MainWindow when it shows first time and won't hide MainWindow later. The user will not open the MainWindow again if the tray is set to not show. The bug fixed by not hiding the MainWindow anytime the MiniWindow showed. * migration version fix * fix: enable universal shortcuts when launch to tray * ✨ feat: add Model Context Protocol (MCP) support (#2809) * ✨ feat: add Model Context Protocol (MCP) server configuration (main) - Added `@modelcontextprotocol/sdk` dependency for MCP integration. - Introduced MCP server configuration UI in settings with add, edit, delete, and activation functionalities. - Created `useMCPServers` hook to manage MCP server state and actions. - Added i18n support for MCP settings with translation keys. - Integrated MCP settings into the application's settings navigation and routing. - Implemented Redux state management for MCP servers. - Updated `yarn.lock` with new dependencies and their resolutions. * 🌟 feat: implement mcp service and integrate with ipc handlers - Added `MCPService` class to manage Model Context Protocol servers. - Implemented various handlers in `ipc.ts` for managing MCP servers including listing, adding, updating, deleting, and activating/deactivating servers. - Integrated MCP related types into existing type declarations for consistency across the application. - Updated `preload` to expose new MCP related APIs to the renderer process. - Enhanced `MCPSettings` component to interact directly with the new MCP service for adding, updating, deleting servers and setting their active states. - Introduced selectors in the MCP Redux slice for fetching active and all servers from the store. - Moved MCP types to a centralized location in `@renderer/types` for reuse across different parts of the application. * feat: enhance MCPService initialization to prevent recursive calls and improve error handling * feat: enhance MCP integration by adding MCPTool type and updating related methods * feat: implement streaming support for tool calls in OpenAIProvider and enhance message processing * fix: finish_reason undefined --------- Co-authored-by: LiuVaayne <10231735+vaayne@users.noreply.github.com> Co-authored-by: kangfenmao <kangfenmao@qq.com>
129 lines
3.1 KiB
TypeScript
129 lines
3.1 KiB
TypeScript
import { ZOOM_SHORTCUTS } from '@shared/config/constant'
|
|
import { LanguageVarious, Shortcut, ThemeMode } from '@types'
|
|
import { app } from 'electron'
|
|
import Store from 'electron-store'
|
|
|
|
import { locales } from '../utils/locales'
|
|
|
|
export class ConfigManager {
|
|
private store: Store
|
|
private subscribers: Map<string, Array<(newValue: any) => void>> = new Map()
|
|
|
|
constructor() {
|
|
this.store = new Store()
|
|
}
|
|
|
|
getLanguage(): LanguageVarious {
|
|
const locale = Object.keys(locales).includes(app.getLocale()) ? app.getLocale() : 'en-US'
|
|
return this.store.get('language', locale) as LanguageVarious
|
|
}
|
|
|
|
setLanguage(theme: LanguageVarious) {
|
|
this.store.set('language', theme)
|
|
}
|
|
|
|
getTheme(): ThemeMode {
|
|
return this.store.get('theme', ThemeMode.light) as ThemeMode
|
|
}
|
|
|
|
setTheme(theme: ThemeMode) {
|
|
this.store.set('theme', theme)
|
|
}
|
|
|
|
getLaunchToTray(): boolean {
|
|
return !!this.store.get('launchToTray', false)
|
|
}
|
|
|
|
setLaunchToTray(value: boolean) {
|
|
this.store.set('launchToTray', value)
|
|
}
|
|
|
|
getTray(): boolean {
|
|
return !!this.store.get('tray', true)
|
|
}
|
|
|
|
setTray(value: boolean) {
|
|
this.store.set('tray', value)
|
|
this.notifySubscribers('tray', value)
|
|
}
|
|
|
|
getTrayOnClose(): boolean {
|
|
return !!this.store.get('trayOnClose', true)
|
|
}
|
|
|
|
setTrayOnClose(value: boolean) {
|
|
this.store.set('trayOnClose', value)
|
|
}
|
|
|
|
getZoomFactor(): number {
|
|
return this.store.get('zoomFactor', 1) as number
|
|
}
|
|
|
|
setZoomFactor(factor: number) {
|
|
this.store.set('zoomFactor', factor)
|
|
this.notifySubscribers('zoomFactor', factor)
|
|
}
|
|
|
|
subscribe<T>(key: string, callback: (newValue: T) => void) {
|
|
if (!this.subscribers.has(key)) {
|
|
this.subscribers.set(key, [])
|
|
}
|
|
this.subscribers.get(key)!.push(callback)
|
|
}
|
|
|
|
unsubscribe<T>(key: string, callback: (newValue: T) => void) {
|
|
const subscribers = this.subscribers.get(key)
|
|
if (subscribers) {
|
|
this.subscribers.set(
|
|
key,
|
|
subscribers.filter((subscriber) => subscriber !== callback)
|
|
)
|
|
}
|
|
}
|
|
|
|
private notifySubscribers<T>(key: string, newValue: T) {
|
|
const subscribers = this.subscribers.get(key)
|
|
if (subscribers) {
|
|
subscribers.forEach((subscriber) => subscriber(newValue))
|
|
}
|
|
}
|
|
|
|
getShortcuts() {
|
|
return this.store.get('shortcuts', ZOOM_SHORTCUTS) as Shortcut[] | []
|
|
}
|
|
|
|
setShortcuts(shortcuts: Shortcut[]) {
|
|
this.store.set(
|
|
'shortcuts',
|
|
shortcuts.filter((shortcut) => shortcut.system)
|
|
)
|
|
this.notifySubscribers('shortcuts', shortcuts)
|
|
}
|
|
|
|
getClickTrayToShowQuickAssistant(): boolean {
|
|
return this.store.get('clickTrayToShowQuickAssistant', false) as boolean
|
|
}
|
|
|
|
setClickTrayToShowQuickAssistant(value: boolean) {
|
|
this.store.set('clickTrayToShowQuickAssistant', value)
|
|
}
|
|
|
|
getEnableQuickAssistant(): boolean {
|
|
return this.store.get('enableQuickAssistant', false) as boolean
|
|
}
|
|
|
|
setEnableQuickAssistant(value: boolean) {
|
|
this.store.set('enableQuickAssistant', value)
|
|
}
|
|
|
|
set(key: string, value: any) {
|
|
this.store.set(key, value)
|
|
}
|
|
|
|
get(key: string) {
|
|
return this.store.get(key)
|
|
}
|
|
}
|
|
|
|
export const configManager = new ConfigManager()
|