feat:项目打包成Electron
This commit is contained in:
49
desktop/main/config.ts
Normal file
49
desktop/main/config.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
// ============================================================
|
||||
// 配置管理 — 后端地址持久化
|
||||
// 职责:存储和读取用户配置的后端 WebSocket 地址
|
||||
// ============================================================
|
||||
|
||||
import Store from 'electron-store'
|
||||
|
||||
// 配置结构
|
||||
interface AppConfig {
|
||||
backendUrl: string
|
||||
windowBounds?: {
|
||||
width: number
|
||||
height: number
|
||||
x?: number
|
||||
y?: number
|
||||
}
|
||||
}
|
||||
|
||||
// 默认配置
|
||||
const DEFAULT_BACKEND_URL = 'ws://localhost:8080/ws'
|
||||
|
||||
// 初始化配置存储
|
||||
const store = new Store<AppConfig>({
|
||||
name: 'camtalk-config',
|
||||
defaults: {
|
||||
backendUrl: DEFAULT_BACKEND_URL,
|
||||
},
|
||||
})
|
||||
|
||||
/**
|
||||
* 获取后端 WebSocket 地址
|
||||
*/
|
||||
export function getBackendUrl(): string {
|
||||
return store.get('backendUrl', DEFAULT_BACKEND_URL)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置后端 WebSocket 地址
|
||||
*/
|
||||
export function setBackendUrl(url: string): void {
|
||||
store.set('backendUrl', url)
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置为默认配置
|
||||
*/
|
||||
export function resetConfig(): void {
|
||||
store.set('backendUrl', DEFAULT_BACKEND_URL)
|
||||
}
|
||||
Reference in New Issue
Block a user