mirror of
https://github.com/Vencord/Vesktop.git
synced 2025-02-23 05:35:09 +00:00
Add single instance lock
This commit is contained in:
parent
d7020a8501
commit
6885564241
1 changed files with 27 additions and 12 deletions
|
@ -7,36 +7,51 @@ import { join } from "path";
|
||||||
import { DATA_DIR, VENCORD_FILES_DIR } from "./constants";
|
import { DATA_DIR, VENCORD_FILES_DIR } from "./constants";
|
||||||
|
|
||||||
import { once } from "../shared/utils/once";
|
import { once } from "../shared/utils/once";
|
||||||
import "./ipc";
|
|
||||||
import { ensureVencordFiles } from "./utils/vencordLoader";
|
import { ensureVencordFiles } from "./utils/vencordLoader";
|
||||||
|
|
||||||
|
import "./ipc";
|
||||||
|
|
||||||
// Make the Vencord files use our DATA_DIR
|
// Make the Vencord files use our DATA_DIR
|
||||||
process.env.VENCORD_USER_DATA_DIR = DATA_DIR;
|
process.env.VENCORD_USER_DATA_DIR = DATA_DIR;
|
||||||
|
|
||||||
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "main.js")));
|
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() {
|
async function createWindows() {
|
||||||
const splash = createSplashWindow();
|
const splash = createSplashWindow();
|
||||||
|
|
||||||
await ensureVencordFiles();
|
await ensureVencordFiles();
|
||||||
runVencordMain();
|
runVencordMain();
|
||||||
|
|
||||||
const mainWindow = createMainWindow();
|
mainWin = createMainWindow();
|
||||||
|
|
||||||
mainWindow.once("ready-to-show", () => {
|
mainWin.once("ready-to-show", () => {
|
||||||
splash.destroy();
|
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", () => {
|
app.on("window-all-closed", () => {
|
||||||
if (process.platform !== "darwin")
|
if (process.platform !== "darwin")
|
||||||
app.quit();
|
app.quit();
|
||||||
|
|
Loading…
Add table
Reference in a new issue