返回 AiToEarn
index.ts
1 /*
2 * @Author: nevin
3 * @Date: 2025-01-18 20:28:01
4 * @LastEditTime: 2025-02-19 02:11:04
5 * @LastEditors: nevin
6 * @Description:
7 */
8 import { app } from 'electron';
9 import path from 'path';
10 import { fileURLToPath } from 'url';
11
12 const __filename = fileURLToPath(import.meta.url);
13 const __dirname = path.dirname(__filename);
14
15 export const isDev = !app.isPackaged || process.env.ELECTRON_DEBUG === 'true';
16
17 import os from 'os';
18
19 const platform = os.platform();
20 const arch = os.arch();
21
22 // 检查平台支持
23 if (platform !== 'darwin' && platform !== 'linux' && platform !== 'win32') {
24 console.error('ffprobe unsupported platform.');
25 // process.exit(1);
26 }
27
28 // 检查 macOS 架构支持
29 if (platform === 'darwin' && arch !== 'x64' && arch !== 'arm64') {
30 console.error('ffprobe unsupported architecture.');
31 // process.exit(1);
32 }
33
34 /**
35 * 获取静态文件目录
36 * @param paths
37 * @returns
38 */
39 export const getAssetPath = (...paths: string[]): string => {
40 const RESOURCES_PATH = app.isPackaged
41 ? path.join(process.resourcesPath, 'assets')
42 : path.join(__dirname, '../../public/assets');
43
44 return path.join(RESOURCES_PATH, ...paths);
45 };
46
47 // json转 a=1&b=2 格式
48 export function jsonToQueryString(json: Record<string, any>): string {
49 return Object.keys(json)
50 .map((key) => encodeURIComponent(key) + '=' + encodeURIComponent(json[key]))
51 .join('&');
52 }
53
53 lines TYPESCRIPT