mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
MISC: Prevent running multiple instances of Electron app (#2095)
This commit is contained in:
@@ -176,7 +176,33 @@ global.app_handlers = {
|
||||
stopProcess: setStopProcessHandler,
|
||||
};
|
||||
|
||||
let window;
|
||||
|
||||
app.on("ready", async () => {
|
||||
const gotTheLock = app.requestSingleInstanceLock();
|
||||
if (!gotTheLock) {
|
||||
await dialog.showMessageBox(undefined, {
|
||||
title: "Bitburner",
|
||||
message: "Failed to launch",
|
||||
detail: "Bitburner is already running. Please do not launch the game multiple times.",
|
||||
type: "error",
|
||||
buttons: ["OK"],
|
||||
});
|
||||
app.quit();
|
||||
return;
|
||||
}
|
||||
app.on("second-instance", (event, commandLine, workingDirectory, additionalData) => {
|
||||
log.error("A second instance is launched", event, commandLine, workingDirectory, additionalData);
|
||||
// The player tried to run a second instance. We should focus the current window.
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
if (window.isMinimized()) {
|
||||
window.restore();
|
||||
}
|
||||
window.focus();
|
||||
});
|
||||
|
||||
// Intercept file protocol requests and only let valid requests through
|
||||
protocol.handle("file", ({ url, method }) => {
|
||||
let filePath;
|
||||
@@ -207,13 +233,13 @@ app.on("ready", async () => {
|
||||
|
||||
log.info("Application is ready!");
|
||||
if (process.argv.includes("--export-save")) {
|
||||
const window = new BrowserWindow({ show: false });
|
||||
window = new BrowserWindow({ show: false });
|
||||
await window.loadFile("export.html");
|
||||
window.show();
|
||||
setStopProcessHandler(window);
|
||||
await utils.exportSave(window);
|
||||
} else {
|
||||
const window = await startWindow(process.argv.includes("--no-scripts"));
|
||||
window = await startWindow(process.argv.includes("--no-scripts"));
|
||||
if (global.steamworksError) {
|
||||
await dialog.showMessageBox(window, {
|
||||
title: "Bitburner",
|
||||
|
||||
Reference in New Issue
Block a user