2023-06-21 23:13:20 +09:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0
|
2023-07-14 02:03:13 +09:00
|
|
|
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
|
2023-06-21 23:13:20 +09:00
|
|
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { app } from "electron";
|
|
|
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
|
|
|
import { join } from "path";
|
|
|
|
|
2023-06-21 23:15:57 +09:00
|
|
|
interface AutoStart {
|
|
|
|
isEnabled(): boolean;
|
|
|
|
enable(): void;
|
|
|
|
disable(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeAutoStartLinux(): AutoStart {
|
2023-06-22 00:09:04 +09:00
|
|
|
const configDir = process.env.XDG_CONFIG_HOME || join(process.env.HOME!, ".config");
|
|
|
|
const dir = join(configDir, "autostart");
|
2023-06-21 23:13:20 +09:00
|
|
|
const file = join(dir, "vencord.desktop");
|
|
|
|
|
|
|
|
return {
|
|
|
|
isEnabled: () => existsSync(file),
|
|
|
|
enable() {
|
|
|
|
const desktopFile = `
|
|
|
|
[Desktop Entry]
|
|
|
|
Type=Application
|
|
|
|
Version=1.0
|
|
|
|
Name=Vencord
|
|
|
|
Comment=Vencord autostart script
|
|
|
|
Exec=${process.execPath}
|
|
|
|
Terminal=false
|
|
|
|
StartupNotify=false
|
|
|
|
`.trim();
|
|
|
|
|
|
|
|
mkdirSync(dir, { recursive: true });
|
|
|
|
writeFileSync(file, desktopFile);
|
|
|
|
},
|
|
|
|
disable: () => rmSync(file, { force: true })
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-21 23:15:57 +09:00
|
|
|
const autoStartWindowsMac: AutoStart = {
|
2023-06-21 23:13:20 +09:00
|
|
|
isEnabled: () => app.getLoginItemSettings().openAtLogin,
|
|
|
|
enable: () => app.setLoginItemSettings({ openAtLogin: true }),
|
|
|
|
disable: () => app.setLoginItemSettings({ openAtLogin: false })
|
|
|
|
};
|
|
|
|
|
|
|
|
export const autoStart = process.platform === "linux" ? makeAutoStartLinux() : autoStartWindowsMac;
|