Add single instance lock

This commit is contained in:
Vendicated 2023-04-04 01:54:03 +02:00
parent d7020a8501
commit 6885564241
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905

View file

@ -7,36 +7,51 @@ import { join } from "path";
import { DATA_DIR, VENCORD_FILES_DIR } from "./constants";
import { once } from "../shared/utils/once";
import "./ipc";
import { ensureVencordFiles } from "./utils/vencordLoader";
import "./ipc";
// Make the Vencord files use our DATA_DIR
process.env.VENCORD_USER_DATA_DIR = DATA_DIR;
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "main.js")));
let mainWin: BrowserWindow | null = null;
if (!app.requestSingleInstanceLock()) {
console.log("Vencord Desktop is already running. Quitting...");
app.quit();
} else {
app.on("second-instance", () => {
if (mainWin) {
if (mainWin.isMinimized()) mainWin.restore();
mainWin.focus();
}
});
app.whenReady().then(async () => {
createWindows();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindows();
});
});
}
async function createWindows() {
const splash = createSplashWindow();
await ensureVencordFiles();
runVencordMain();
const mainWindow = createMainWindow();
mainWin = createMainWindow();
mainWindow.once("ready-to-show", () => {
mainWin.once("ready-to-show", () => {
splash.destroy();
mainWindow.show();
mainWin!.show();
});
}
app.whenReady().then(async () => {
createWindows();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindows();
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin")
app.quit();