From 9674d9e4839baad4517543f14bd12baaa18bb116 Mon Sep 17 00:00:00 2001 From: Oj Date: Sat, 11 Dec 2021 10:37:43 +0000 Subject: [PATCH] [Bootstrap] Add multi-instance handling --- README.md | 1 + src/bootstrap.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 62a98c2..4580b1a 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ You can configure OpenAsar via `settings.json` (found in your Discord app data / - `quickstart` (bool, default false) - whether to use Quickstart (experimental) - `skipStartupUpdateChecks` (bool, default false) - skips startup update checking (Linux-only) - `autoupdate` (bool, default true) - whether to autoupdate OpenAsar after Discord startup +- `multiInstance` (bool, default false) - whether to enable multi-instance An example of a settings.json with OpenAsar config: ```json diff --git a/src/bootstrap.js b/src/bootstrap.js index f945470..05404d4 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -68,6 +68,8 @@ const startUpdate = () => { }); }; +const hasArgvFlag = (flag) => (process.argv || []).slice(1).includes(flag); + module.exports = () => { // Paths logging log('Paths', `Init! Returns: @@ -77,6 +79,14 @@ getResources: ${paths.getResources()} getModuleDataPath: ${paths.getModuleDataPath()} getInstallPath: ${paths.getInstallPath()}`); + const instanceLock = app.requestSingleInstanceLock(); + const allowMultiInstance = hasArgvFlag('--multi-instance') || oaConfig.multiInstance; // argv flag or config + + if (!instanceLock && !allowMultiInstance) { + log('Bootstrap', 'Non-first instance, quitting (multi-instance disabled)'); + return app.quit(); + } + if (app.isReady()) { startUpdate(); } else {