mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-11-15 22:52:16 +03:00
Add new helper method: isElectron() to detect whether the current window is running inside Electron
This commit is contained in:
2
src/helpers/ua-parser-helpers.d.ts
vendored
2
src/helpers/ua-parser-helpers.d.ts
vendored
@@ -7,6 +7,7 @@ import { IResult } from "../main/ua-parser";
|
|||||||
declare function getDeviceVendor(model: string): string | undefined;
|
declare function getDeviceVendor(model: string): string | undefined;
|
||||||
declare function isAppleSilicon(res: IResult): boolean;
|
declare function isAppleSilicon(res: IResult): boolean;
|
||||||
declare function isChromeFamily(res: IResult): boolean;
|
declare function isChromeFamily(res: IResult): boolean;
|
||||||
|
declare function isElectron(): boolean;
|
||||||
declare function isFromEU(): boolean;
|
declare function isFromEU(): boolean;
|
||||||
declare function isFrozenUA(ua: string): boolean;
|
declare function isFrozenUA(ua: string): boolean;
|
||||||
declare function isStandalonePWA(): boolean;
|
declare function isStandalonePWA(): boolean;
|
||||||
@@ -15,6 +16,7 @@ export {
|
|||||||
getDeviceVendor,
|
getDeviceVendor,
|
||||||
isAppleSilicon,
|
isAppleSilicon,
|
||||||
isChromeFamily,
|
isChromeFamily,
|
||||||
|
isElectron,
|
||||||
isFromEU,
|
isFromEU,
|
||||||
isFrozenUA,
|
isFrozenUA,
|
||||||
isStandalonePWA
|
isStandalonePWA
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ const isAppleSilicon = (res) => {
|
|||||||
|
|
||||||
const isChromeFamily = (res) => res.engine.is(Engine.BLINK);
|
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 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 ||
|
const isStandalonePWA = () => window && (window.matchMedia('(display-mode: standalone)').matches ||
|
||||||
@@ -51,6 +54,7 @@ module.exports = {
|
|||||||
getDeviceVendor,
|
getDeviceVendor,
|
||||||
isAppleSilicon,
|
isAppleSilicon,
|
||||||
isChromeFamily,
|
isChromeFamily,
|
||||||
|
isElectron,
|
||||||
isFromEU,
|
isFromEU,
|
||||||
isFrozenUA,
|
isFrozenUA,
|
||||||
isStandalonePWA
|
isStandalonePWA
|
||||||
|
|||||||
Reference in New Issue
Block a user