[PM-4441] Refactor utils helper functions (#6672)
This commit is contained in:
parent
7ff4a157f9
commit
6355a1964b
|
@ -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());
|
||||
|
||||
// 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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue