From 6da51782ad526222c5ec5b1d7e35e3d32bbeb3d4 Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Sat, 15 Jun 2024 11:41:35 +0200 Subject: [PATCH] fix: quit properly in tray --- package.json | 2 +- src/discord/ipc.ts | 3 +++ src/discord/preload/preload.mts | 2 +- src/discord/screenshare/main.ts | 1 + src/discord/window.ts | 6 +++--- src/tray.ts | 6 ++++-- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index dd5e1cb..46653ff 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "build": "tsc && copyfiles -u 1 src/**/*.html src/**/**/*.css src/**/**/*.js ts-out/ && copyfiles package.json ts-out/ && copyfiles assets/**/** ts-out/", "watch": "tsc -w", - "start": "pnpm run build && electron ./ts-out/main.js", + "start": "pnpm run build && electron --trace-warnings ./ts-out/main.js", "startThemeManager": "pnpm run build && electron ./ts-out/main.js themes", "startKeybindManager": "pnpm run build && electron ./ts-out/main.js keybinds", "startWayland": "pnpm run build && electron ./ts-out/main.js --ozone-platform-hint=auto --enable-features=WebRTCPipeWireCapturer,WaylandWindowDecorations --disable-gpu", diff --git a/src/discord/ipc.ts b/src/discord/ipc.ts index 1f524e7..fae7e9f 100644 --- a/src/discord/ipc.ts +++ b/src/discord/ipc.ts @@ -83,6 +83,9 @@ export function registerIpc(passedWindow: BrowserWindow): void { passedWindow.hide(); }); ipcMain.on("win-quit", () => { + app.quit(); + }); + ipcMain.on("win-forceQuit", () => { app.exit(); }); ipcMain.on("get-app-version", (event) => { diff --git a/src/discord/preload/preload.mts b/src/discord/preload/preload.mts index 1ab0498..2553635 100644 --- a/src/discord/preload/preload.mts +++ b/src/discord/preload/preload.mts @@ -112,7 +112,7 @@ setInterval(() => { tManager.onclick = () => ipcRenderer.send("openManagerWindow"); fQuit.textContent = "Force Quit"; fQuit.id = "acForceQuit"; - fQuit.onclick = () => ipcRenderer.send("win-quit"); + fQuit.onclick = () => ipcRenderer.send("win-forceQuit"); advanced.insertAdjacentElement("afterend", acSettings); advanced.insertAdjacentElement("afterend", tManager); advanced.insertAdjacentElement("afterend", fQuit); diff --git a/src/discord/screenshare/main.ts b/src/discord/screenshare/main.ts index 3f1cc79..0876117 100644 --- a/src/discord/screenshare/main.ts +++ b/src/discord/screenshare/main.ts @@ -30,6 +30,7 @@ function registerCustomHandler(): void { types: ["screen", "window"] }) .then((sources) => { + if (!sources) return callback({}); console.log(sources); if (process.platform === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland") { console.log("WebRTC Capturer detected, skipping window creation."); //assume webrtc capturer is used diff --git a/src/discord/window.ts b/src/discord/window.ts index e1375c6..7b1ad2c 100644 --- a/src/discord/window.ts +++ b/src/discord/window.ts @@ -12,13 +12,13 @@ import * as fs from "fs"; import contextMenu from "electron-context-menu"; import os from "os"; import RPCServer from "arrpc"; -import {tray} from "../tray.js"; +import {isQuitting, tray} from "../tray.js"; import {iconPath, init} from "../main.js"; import {getConfig, setConfig, firstRun} from "../common/config.js"; import {getWindowState, setWindowState} from "../common/windowState.js"; export let mainWindows: BrowserWindow[] = []; export let inviteWindow: BrowserWindow; -let forceQuit = false; +export let forceQuit = false; let osType = os.type(); contextMenu({ showSaveImageAs: true, @@ -252,7 +252,7 @@ function doAfterDefiningTheWindow(passedWindow: BrowserWindow): void { x: passedWindow.getPosition()[0], y: passedWindow.getPosition()[1] }); - if (getConfig("minimizeToTray")) { + if (getConfig("minimizeToTray") && !isQuitting) { e.preventDefault(); passedWindow.hide(); } else if (!getConfig("minimizeToTray")) { diff --git a/src/tray.ts b/src/tray.ts index 2424fd2..e5816be 100644 --- a/src/tray.ts +++ b/src/tray.ts @@ -6,6 +6,7 @@ import {createSettingsWindow} from "./settings/main.js"; import {getConfig, getConfigLocation, setConfig} from "./common/config.js"; import {getDisplayVersion} from "./common/version.js"; export let tray: Tray; +export let isQuitting = false; let trayIcon = "ac_plug_colored"; void app.whenReady().then(async () => { // REVIEW - app will hang at startup if line above is awaited. @@ -85,8 +86,9 @@ void app.whenReady().then(async () => { { label: `Quit ${clientName}`, click() { - // NOTE - Temporary fix for app not actually quitting - app.exit(); + //NOTE - It would be better to unify isQuitting with forceQuit in window.ts that's used on macOS + isQuitting = true; + app.quit(); } } ]);