Files
dream_pep 3653e26a09 feat: 发布 v1.2.0 版本,新增多项核心功能
- 引入 electron-updater 实现自动更新功能
- 新增 Java 环境扫描与校验的 IPC 处理逻辑
- 实现离线账号登录功能
- 新增配置变更跨进程广播机制
- 重构游戏启动逻辑,使用主进程内存配置作为唯一权威来源
- 新增界面显示与语言设置的配置页面
- 添加 Windows 平台自动发布 CI 流水线
- 迁移旧版配置/认证文件到用户数据目录
- 修复崩溃日志路径、表单控件等多项 bug
- 重构设置页组件系统统一界面样式
2026-08-28 02:08:12 +08:00

50 lines
1.3 KiB
TypeScript

import * as fs from 'fs';
import * as path from 'path';
import electron from 'electron';
const { app } = electron;
export interface AuthData {
username: string;
uuid: string;
accessToken: string;
refreshToken: string;
xboxProfile: string;
}
/**
* 认证文件路径(与配置一致):
* - 打包后 → 系统用户数据目录(userData)
* - 开发模式 → 项目根目录
*/
export function authPath(): string {
if (app.isPackaged) {
return path.join(app.getPath('userData'), 'koring-auth.json');
}
return path.join(__dirname, '..', 'koring-auth.json');
}
export function readAuth(): AuthData {
const filePath = authPath();
if (!fs.existsSync(filePath)) {
return { username: '', uuid: '', accessToken: '', refreshToken: '', xboxProfile: '' };
}
try {
const raw = fs.readFileSync(filePath, 'utf-8');
return JSON.parse(raw) as AuthData;
} catch {
return { username: '', uuid: '', accessToken: '', refreshToken: '', xboxProfile: '' };
}
}
export function writeAuth(auth: AuthData): void {
const filePath = authPath();
fs.writeFileSync(filePath, JSON.stringify(auth, null, 2), 'utf-8');
}
export function deleteAuth(): void {
const filePath = authPath();
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
}
}