mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
feat: rewrite minimize to tray
This commit is contained in:
parent
a50f4ca297
commit
ac1d090ead
4 changed files with 30 additions and 33 deletions
5
src/common/forceQuit.ts
Normal file
5
src/common/forceQuit.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
export let forceQuit = false;
|
||||
|
||||
export function setForceQuit(e: boolean): void {
|
||||
forceQuit = e;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import {BrowserWindow, Menu, app} from "electron";
|
||||
import {mainWindows} from "./window.js";
|
||||
import {createSettingsWindow} from "../settings/main.js";
|
||||
import {setForceQuit} from "../common/forceQuit.js";
|
||||
|
||||
export function setMenu(): void {
|
||||
const template: Electron.MenuItemConstructorOptions[] = [
|
||||
|
@ -48,6 +49,7 @@ export function setMenu(): void {
|
|||
label: "Quit",
|
||||
accelerator: "CmdOrCtrl+Q",
|
||||
click() {
|
||||
setForceQuit(true);
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,14 @@ import * as fs from "fs";
|
|||
import contextMenu from "electron-context-menu";
|
||||
import os from "os";
|
||||
import RPCServer from "arrpc";
|
||||
import {isQuitting, tray} from "../tray.js";
|
||||
import {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";
|
||||
import {forceQuit, setForceQuit} from "../common/forceQuit.js";
|
||||
export let mainWindows: BrowserWindow[] = [];
|
||||
export let inviteWindow: BrowserWindow;
|
||||
export let forceQuit = false;
|
||||
|
||||
let osType = os.type();
|
||||
contextMenu({
|
||||
showSaveImageAs: true,
|
||||
|
@ -238,12 +239,18 @@ function doAfterDefiningTheWindow(passedWindow: BrowserWindow): void {
|
|||
});
|
||||
setMenu();
|
||||
passedWindow.on("close", (e) => {
|
||||
if (process.platform === "darwin" && forceQuit) {
|
||||
passedWindow.close();
|
||||
} else if (mainWindows.length > 1) {
|
||||
if (mainWindows.length > 1) {
|
||||
mainWindows = mainWindows.filter((mainWindow) => mainWindow.id != passedWindow.id);
|
||||
passedWindow.destroy();
|
||||
} else {
|
||||
}
|
||||
if (getConfig("minimizeToTray") && !forceQuit) {
|
||||
e.preventDefault();
|
||||
passedWindow.hide();
|
||||
} else if (!getConfig("minimizeToTray")) {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
app.on("before-quit", () => {
|
||||
const [width, height] = passedWindow.getSize();
|
||||
setWindowState({
|
||||
width,
|
||||
|
@ -252,25 +259,8 @@ function doAfterDefiningTheWindow(passedWindow: BrowserWindow): void {
|
|||
x: passedWindow.getPosition()[0],
|
||||
y: passedWindow.getPosition()[1]
|
||||
});
|
||||
if (getConfig("minimizeToTray") && !isQuitting) {
|
||||
e.preventDefault();
|
||||
passedWindow.hide();
|
||||
} else if (!getConfig("minimizeToTray")) {
|
||||
e.preventDefault();
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
setForceQuit(true);
|
||||
});
|
||||
if (process.platform === "darwin") {
|
||||
app.on("before-quit", function (event) {
|
||||
if (!forceQuit) {
|
||||
event.preventDefault();
|
||||
forceQuit = true;
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// REVIEW - Awaiting javascript execution is silly
|
||||
passedWindow.on("focus", () => {
|
||||
void passedWindow.webContents.executeJavaScript(`document.body.removeAttribute("unFocused");`);
|
||||
|
|
|
@ -5,8 +5,9 @@ import path from "path";
|
|||
import {createSettingsWindow} from "./settings/main.js";
|
||||
import {getConfig, getConfigLocation, setConfig} from "./common/config.js";
|
||||
import {getDisplayVersion} from "./common/version.js";
|
||||
import {setForceQuit} from "./common/forceQuit.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.
|
||||
|
@ -86,8 +87,7 @@ void app.whenReady().then(async () => {
|
|||
{
|
||||
label: `Quit ${clientName}`,
|
||||
click() {
|
||||
//NOTE - It would be better to unify isQuitting with forceQuit in window.ts that's used on macOS
|
||||
isQuitting = true;
|
||||
setForceQuit(true);
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue