Skip to content

Commit

Permalink
fix(platform): correct behavior for isApple util (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Oct 10, 2024
1 parent 3dc11b0 commit 9a36f07
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
2 changes: 2 additions & 0 deletions libs/platform/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const WA_SAFARI_REG_EXP = /^((?!chrome|android).)*safari/i;
export const WA_IOS_REG_EXP = /ipad|iphone|ipod|mac/i;
1 change: 1 addition & 0 deletions libs/platform/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './constants';
export * from './is-android';
export * from './is-apple';
export * from './is-edge';
Expand Down
15 changes: 4 additions & 11 deletions libs/platform/src/is-apple.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
/**
* @description:
* All Chrome / Chromium-based browsers will return MacIntel on macOS,
* no matter what the hardware architecture is. See the source code here:
* https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/frame/navigator_id.cc;l=64;drc=703d3c472cf27470dad21a3f2c8972aca3732cd6
* But maybe in future years, it will be changed to MacM1
*
* Documentation:
* https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform
*/
import {WA_SAFARI_REG_EXP} from './constants';
import {isIos} from './is-ios';

export function isApple(navigator: Navigator): boolean {
return navigator.platform.startsWith('Mac') || navigator.platform === 'iPhone';
return isIos(navigator) || WA_SAFARI_REG_EXP.test(navigator.userAgent);
}
11 changes: 3 additions & 8 deletions libs/platform/src/is-ios.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import {inject, InjectionToken} from '@angular/core';
import {WA_NAVIGATOR} from '@ng-web-apis/common';

import {isApple} from './is-apple';
import {WA_IOS_REG_EXP as ios, WA_SAFARI_REG_EXP as safari} from './constants';

const IOS_REG_EXP = /ipad|iphone|ipod/;

export function isIos(navigator: Navigator): boolean {
return (
IOS_REG_EXP.test(navigator.userAgent.toLowerCase()) ||
(isApple(navigator) && navigator.maxTouchPoints > 1)
);
export function isIos({userAgent, maxTouchPoints}: Navigator): boolean {
return ios.test(userAgent) || (safari.test(userAgent) && maxTouchPoints > 1);
}

export const WA_IS_IOS = new InjectionToken<boolean>('', {
Expand Down

0 comments on commit 9a36f07

Please sign in to comment.