From 6355a1964b52d55ef36071810138f5d28877b14f Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Mon, 23 Oct 2023 23:52:42 +0200 Subject: [PATCH] [PM-4441] Refactor utils helper functions (#6672) --- apps/desktop/src/main/window.main.ts | 27 +++++++++++++++++++-------- apps/desktop/src/utils.ts | 26 +++++++++++++++++--------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/apps/desktop/src/main/window.main.ts b/apps/desktop/src/main/window.main.ts index e326b9e9e1..cf792a9348 100644 --- a/apps/desktop/src/main/window.main.ts +++ b/apps/desktop/src/main/window.main.ts @@ -9,7 +9,15 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service" import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; -import { cleanUserAgent, isDev, isMacAppStore, isSnapStore } from "../utils"; +import { + cleanUserAgent, + isDev, + isLinux, + isMac, + isMacAppStore, + isSnapStore, + isWindows, +} from "../utils"; const mainWindowSizeKey = "mainWindowSize"; const WindowEventHandlingDelay = 100; @@ -41,9 +49,12 @@ export class WindowMain { // User might have changed theme, ensure the window is updated. this.win.setBackgroundColor(await this.getBackgroundColor()); - const crashEvent = once(this.win.webContents, "render-process-gone"); - this.win.webContents.forcefullyCrashRenderer(); - await crashEvent; + // By default some linux distro collect core dumps on crashes which gets written to disk. + if (!isLinux()) { + const crashEvent = once(this.win.webContents, "render-process-gone"); + this.win.webContents.forcefullyCrashRenderer(); + await crashEvent; + } this.win.webContents.reloadIgnoringCache(); this.session.clearCache(); @@ -66,7 +77,7 @@ export class WindowMain { } this.win.focus(); } - if (process.platform === "win32" || process.platform === "linux") { + if (isWindows() || isLinux()) { if (this.argvCallback != null) { this.argvCallback(argv); } @@ -96,7 +107,7 @@ export class WindowMain { app.on("window-all-closed", () => { // On OS X it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q - if (process.platform !== "darwin" || this.isQuitting || isMacAppStore()) { + if (!isMac() || this.isQuitting || isMacAppStore()) { app.quit(); } }); @@ -137,8 +148,8 @@ export class WindowMain { x: this.windowStates[mainWindowSizeKey].x, y: this.windowStates[mainWindowSizeKey].y, title: app.name, - icon: process.platform === "linux" ? path.join(__dirname, "/images/icon.png") : undefined, - titleBarStyle: process.platform === "darwin" ? "hiddenInset" : undefined, + icon: isLinux() ? path.join(__dirname, "/images/icon.png") : undefined, + titleBarStyle: isMac() ? "hiddenInset" : undefined, show: false, backgroundColor: await this.getBackgroundColor(), alwaysOnTop: this.enableAlwaysOnTop, diff --git a/apps/desktop/src/utils.ts b/apps/desktop/src/utils.ts index 603cc1bec1..c1597d53b5 100644 --- a/apps/desktop/src/utils.ts +++ b/apps/desktop/src/utils.ts @@ -25,8 +25,16 @@ export function isDev() { return process.defaultApp || /node_modules[\\/]electron[\\/]/.test(process.execPath); } +export function isLinux() { + return process.platform === "linux"; +} + export function isAppImage() { - return process.platform === "linux" && "APPIMAGE" in process.env; + return isLinux() && "APPIMAGE" in process.env; +} + +export function isSnapStore() { + return isLinux() && process.env.SNAP_USER_DATA != null; } export function isMac() { @@ -37,25 +45,25 @@ export function isMacAppStore() { return isMac() && process.mas === true; } +export function isWindows() { + return process.platform === "win32"; +} + export function isWindowsStore() { - const isWindows = process.platform === "win32"; + const windows = isWindows(); let windowsStore = process.windowsStore; if ( - isWindows && + windows && !windowsStore && process.resourcesPath.indexOf("8bitSolutionsLLC.bitwardendesktop_") > -1 ) { windowsStore = true; } - return isWindows && windowsStore === true; -} - -export function isSnapStore() { - return process.platform === "linux" && process.env.SNAP_USER_DATA != null; + return windows && windowsStore === true; } export function isWindowsPortable() { - return process.platform === "win32" && process.env.PORTABLE_EXECUTABLE_DIR != null; + return isWindows() && process.env.PORTABLE_EXECUTABLE_DIR != null; } /**