-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #695 from Stremio/refactor/platform-device
refactor: platform device logic
- Loading branch information
Showing
6 changed files
with
42 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Bowser from 'bowser'; | ||
|
||
const APPLE_MOBILE_DEVICES = [ | ||
'iPad Simulator', | ||
'iPhone Simulator', | ||
'iPod Simulator', | ||
'iPad', | ||
'iPhone', | ||
'iPod', | ||
]; | ||
|
||
const { userAgent, platform, maxTouchPoints } = globalThis.navigator; | ||
|
||
// this detects ipad properly in safari | ||
// while bowser does not | ||
const isIOS = APPLE_MOBILE_DEVICES.includes(platform) || (userAgent.includes('Mac') && 'ontouchend' in document); | ||
|
||
// Edge case: iPad is included in this function | ||
// Keep in mind maxTouchPoints for Vision Pro might change in the future | ||
const isVisionOS = userAgent.includes('Macintosh') || maxTouchPoints === 5; | ||
|
||
const bowser = Bowser.getParser(userAgent); | ||
const os = bowser.getOSName().toLowerCase(); | ||
|
||
const name = isVisionOS ? 'visionos' : isIOS ? 'ios' : os || 'unknown'; | ||
const isMobile = ['ios', 'android'].includes(name); | ||
|
||
export { | ||
name, | ||
isMobile, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters