Add new helper method: isElectron() to detect whether the current window is running inside Electron

This commit is contained in:
Faisal Salman
2024-09-14 13:13:36 +07:00
parent db1612401f
commit 3de1961892
2 changed files with 6 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import { IResult } from "../main/ua-parser";
declare function getDeviceVendor(model: string): string | undefined;
declare function isAppleSilicon(res: IResult): boolean;
declare function isChromeFamily(res: IResult): boolean;
declare function isElectron(): boolean;
declare function isFromEU(): boolean;
declare function isFrozenUA(ua: string): boolean;
declare function isStandalonePWA(): boolean;
@@ -15,6 +16,7 @@ export {
getDeviceVendor,
isAppleSilicon,
isChromeFamily,
isElectron,
isFromEU,
isFrozenUA,
isStandalonePWA

View File

@@ -35,6 +35,9 @@ const isAppleSilicon = (res) => {
const isChromeFamily = (res) => res.engine.is(Engine.BLINK);
const isElectron = () => !!(process?.versions?.hasOwnProperty('electron') || // node.js
/ electron\//i.test(navigator?.userAgent)); // browser
const isFrozenUA = (ua) => /^Mozilla\/5\.0 \((Windows NT 10\.0; Win64; x64|Macintosh; Intel Mac OS X 10_15_7|X11; Linux x86_64|X11; CrOS x86_64 14541\.0\.0|Fuchsia|Linux; Android 10; K)\) AppleWebKit\/537\.36 \(KHTML, like Gecko\) Chrome\/\d+\.0\.0\.0 (Mobile )?Safari\/537\.36/.test(ua);
const isStandalonePWA = () => window && (window.matchMedia('(display-mode: standalone)').matches ||
@@ -51,6 +54,7 @@ module.exports = {
getDeviceVendor,
isAppleSilicon,
isChromeFamily,
isElectron,
isFromEU,
isFrozenUA,
isStandalonePWA