[submodule:helpers] Add an optional parameter in isAppleSilicon() that flags the use of feature detection

This commit is contained in:
Faisal Salman 2024-11-09 20:04:29 +07:00
parent 75690f16cc
commit 19e5d322e2
2 changed files with 13 additions and 11 deletions

View File

@ -5,7 +5,7 @@
import { IResult } from "../main/ua-parser";
declare function getDeviceVendor(model: string): string | undefined;
declare function isAppleSilicon(res: IResult): boolean;
declare function isAppleSilicon(res: IResult, useFeatureDetection?: boolean): boolean;
declare function isBot(res: IResult): boolean;
declare function isChromeFamily(res: IResult): boolean;
declare function isElectron(): boolean;

View File

@ -15,11 +15,12 @@ const { isStandalonePWA } = require('is-standalone-pwa');
const getDeviceVendor = (model) => UAParser(`Mozilla/5.0 (Linux; Android 10; ${model}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36`).device.vendor;
const isAppleSilicon = (res) => {
const isAppleSilicon = (res, useFeatureDetection) => {
if (res.os.is(OS.MACOS)) {
if (res.cpu.is(CPU.ARM)) {
return true;
}
if (useFeatureDetection) {
try {
const canvas = document.createElement('canvas');
const webgl = canvas.getContext('webgl2') || canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
@ -32,6 +33,7 @@ const isAppleSilicon = (res) => {
return false;
}
}
}
return false;
}