- 添加项目图标文件(app-icon.png、各平台图标) - 配置开发环境文件(.env、.nvmrc、.npmrc) - 添加静态资源文件(背景图片、字体、音频) - 初始化Tauri后端结构(build.rs、main.rs、模块文件) - 配置前端项目结构(TypeScript、Vue组件、样式) - 添加Node.js API服务基础结构 - 配置构建和开发工具(vite、prettier、gitignore)
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { isObject } from '../src/utils/verify';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import machineId from 'node-machine-id';
|
|
|
|
interface PrivateConfig {
|
|
/** 是否注册VueDevTools组件 */
|
|
isUseVueDevTools?: boolean;
|
|
/** 设备id */
|
|
deviceID?: string;
|
|
}
|
|
|
|
/**
|
|
* 获取或创建设备标识
|
|
*/
|
|
export function getPrivateConfig(): PrivateConfig {
|
|
const CONFIG_FILE = path.resolve(process.cwd(), '.MyPrivateConfig');
|
|
|
|
try {
|
|
const config: PrivateConfig = { isUseVueDevTools: true };
|
|
// 2. 尝试读取本地存储
|
|
if (fs.existsSync(CONFIG_FILE)) {
|
|
const content = fs.readFileSync(CONFIG_FILE, 'utf-8');
|
|
try {
|
|
let json: PrivateConfig = JSON.parse(content);
|
|
json = isObject(json) ? json : {};
|
|
config.isUseVueDevTools = json.isUseVueDevTools ?? true;
|
|
config.deviceID = json.deviceID ?? machineId.machineIdSync(true) ?? `${Date.now()}${Math.floor(Math.random() * 10000000000)}`;
|
|
|
|
// oxlint-disable-next-line no-unused-vars
|
|
} catch (error: any) {}
|
|
}
|
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf-8');
|
|
return config;
|
|
} catch (error: any) {
|
|
console.error('Device ID management error:', error);
|
|
return {};
|
|
}
|
|
}
|