From b3e0d2e5b2f2ae94e4253cc1960d6820a9017e42 Mon Sep 17 00:00:00 2001 From: Kylie C Date: Wed, 11 Sep 2024 17:08:46 -0400 Subject: [PATCH] fix mac instance reloading also consolidated restore function --- src/main/index.ts | 9 ++------- src/main/mainWindow.ts | 11 +++++++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 4df2ad7..0666fc1 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -11,7 +11,7 @@ import { autoUpdater } from "electron-updater"; import { DATA_DIR } from "./constants"; import { createFirstLaunchTour } from "./firstLaunch"; -import { createWindows, mainWin } from "./mainWindow"; +import { createWindows, restoreVesktop } from "./mainWindow"; import { registerMediaPermissionsHandler } from "./mediaPermissions"; import { registerScreenShareHandler } from "./screenShare"; import { Settings, State } from "./settings"; @@ -69,12 +69,7 @@ function init() { if (isDeckGameMode) nativeTheme.themeSource = "dark"; app.on("second-instance", (_event, _cmdLine, _cwd, data: any) => { - if (data.IS_DEV) app.quit(); - else if (mainWin) { - if (mainWin.isMinimized()) mainWin.restore(); - if (!mainWin.isVisible()) mainWin.show(); - mainWin.focus(); - } + data.IS_DEV ? app.quit() : restoreVesktop(); }); app.whenReady().then(async () => { diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 4ff7e8c..59ea2c7 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -465,16 +465,23 @@ function createMainWindow() { let uriFiredDarwin = false; app.on("open-url", (_, url) => { + uriFiredDarwin ? restoreVesktop() : loadUrl(url); uriFiredDarwin = true; - loadUrl(url); }); uriFiredDarwin || loadUrl(uri); - return win; } const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js"))); +export function restoreVesktop() { + if (mainWin) { + if (mainWin.isMinimized()) mainWin.restore(); + if (!mainWin.isVisible()) mainWin.show(); + mainWin.focus(); + } +} + export async function createWindows() { const startMinimized = process.argv.includes("--start-minimized"); const splash = createSplashWindow(startMinimized);