refactor(server/utils): isElectron - replace fn with boolean

this values cannot change during runtime,
=> there is no need to have these checks
as dynamic function, instead just
export the boolean value directly
This commit is contained in:
Panagiotis Papadopoulos
2025-01-22 18:57:06 +01:00
parent 94411cf418
commit ca2bb94200
16 changed files with 33 additions and 40 deletions

View File

@@ -13,6 +13,12 @@ import { dirname, join } from "path";
const randtoken = generator({ source: "crypto" });
export const isMac = process.platform === "darwin";
export const isWindows = process.platform === "win32";
export const isElectron = !!process.versions["electron"];
export function newEntityId() {
return randomString(12);
}
@@ -58,10 +64,6 @@ export function hmac(secret: any, value: any) {
return hmac.digest("base64");
}
export function isElectron() {
return !!process.versions["electron"];
}
export function hash(text: string) {
text = text.normalize();
@@ -128,7 +130,7 @@ export function escapeRegExp(str: string) {
}
export async function crash() {
if (isElectron()) {
if (isElectron) {
(await import("electron")).app.exit(1);
} else {
process.exit(1);
@@ -314,19 +316,13 @@ export function envToBoolean(val: string | undefined) {
* @returns the resource dir.
*/
export function getResourceDir() {
if (isElectron() && !env.isDev()) {
if (isElectron && !env.isDev()) {
return process.resourcesPath;
} else {
return join(dirname(fileURLToPath(import.meta.url)), "..", "..");
}
}
export const isMac = process.platform === "darwin";
export const isWindows = process.platform === "win32";
return process.platform === "win32";
}
export default {
randomSecureToken,
randomString,