mirror of
https://github.com/Melorise/TamaASR.git
synced 2026-11-07 14:39:32 +00:00
实现隐藏启动、就绪状态托盘、登录提醒、后端切换、快捷键与自启动设置、九宫格和坐标微调,以及常驻悬浮球点击录音。 AI-assisted-by: Codex AI-model: gpt-5.6-sol AI-reasoning-effort: medium Co-authored-by: Codex <codex@openai.com>
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { app } from 'electron';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
|
|
function desktopEscape(value: string): string {
|
|
return `"${value.replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('`', '\\`').replaceAll('$', '\\$')}"`;
|
|
}
|
|
|
|
export class AutoStartService {
|
|
private readonly filePath = path.join(os.homedir(), '.config', 'autostart', 'meloasr.desktop');
|
|
|
|
apply(enabled: boolean): void {
|
|
if (!enabled) {
|
|
fs.mkdirSync(path.dirname(this.filePath), { recursive: true });
|
|
fs.writeFileSync(this.filePath, [
|
|
'[Desktop Entry]',
|
|
'Type=Application',
|
|
'Name=MeloASR',
|
|
'Hidden=true',
|
|
''
|
|
].join('\n'), { mode: 0o644 });
|
|
return;
|
|
}
|
|
const args = app.isPackaged ? [] : [app.getAppPath()];
|
|
const command = [process.execPath, ...args].map(desktopEscape).join(' ');
|
|
const contents = [
|
|
'[Desktop Entry]',
|
|
'Type=Application',
|
|
'Name=MeloASR',
|
|
`Exec=${command}`,
|
|
'Terminal=false',
|
|
'X-GNOME-Autostart-enabled=true',
|
|
'Comment=MeloASR',
|
|
''
|
|
].join('\n');
|
|
fs.mkdirSync(path.dirname(this.filePath), { recursive: true });
|
|
fs.writeFileSync(this.filePath, contents, { mode: 0o644 });
|
|
}
|
|
}
|