- Electron + React + TypeScript 桌面宠物外壳 - xterm.js + node-pty 直接对接 Claude CLI 进程 - 宠物 orb(80x80)可拖拽,点击展开终端面板 - CRT 复古终端主题(扫描线、文字发光) - 全局快捷键 Cmd+Shift+C 显隐 - 窗口位置自动保存 - 中华田园犬吉祥物 icon(AI 生成) - Makefile 新增 `make app` 打包命令
41 lines
970 B
TypeScript
41 lines
970 B
TypeScript
import * as fs from 'fs'
|
|
import * as path from 'path'
|
|
import { app } from 'electron'
|
|
|
|
interface AppConfig {
|
|
windowPosition?: { x: number; y: number }
|
|
autoStart?: boolean
|
|
collapsed?: boolean
|
|
}
|
|
|
|
const DEFAULT_CONFIG: AppConfig = {
|
|
autoStart: false,
|
|
collapsed: true,
|
|
}
|
|
|
|
function getConfigPath(): string {
|
|
return path.join(app.getPath('userData'), 'config.json')
|
|
}
|
|
|
|
export function loadConfig(): AppConfig {
|
|
try {
|
|
const configPath = getConfigPath()
|
|
if (fs.existsSync(configPath)) {
|
|
const data = fs.readFileSync(configPath, 'utf8')
|
|
return { ...DEFAULT_CONFIG, ...JSON.parse(data) }
|
|
}
|
|
} catch (err) {
|
|
console.error('Failed to load config:', err)
|
|
}
|
|
return { ...DEFAULT_CONFIG }
|
|
}
|
|
|
|
export function saveConfig(config: AppConfig): void {
|
|
try {
|
|
const configPath = getConfigPath()
|
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf8')
|
|
} catch (err) {
|
|
console.error('Failed to save config:', err)
|
|
}
|
|
}
|