guess platform, might need tweaking still
This commit is contained in:
parent
5704ade5dc
commit
822431ac14
2 changed files with 28 additions and 6 deletions
|
@ -26,10 +26,32 @@ export const Platform = createEnum(
|
|||
"Linux"
|
||||
);
|
||||
|
||||
export function guessApplicablePlatforms(userAgent) {
|
||||
// use https://github.com/faisalman/ua-parser-js to guess, and pass as RootVM options
|
||||
return [Platform.DesktopWeb, Platform.Linux];
|
||||
// return [Platform.MobileWeb, Platform.Android];
|
||||
export function guessApplicablePlatforms(userAgent, platform) {
|
||||
// return [Platform.DesktopWeb, Platform.Linux];
|
||||
let nativePlatform;
|
||||
let webPlatform;
|
||||
if (/android/i.test(userAgent)) {
|
||||
nativePlatform = Platform.Android;
|
||||
webPlatform = Platform.MobileWeb;
|
||||
} else if ( // https://stackoverflow.com/questions/9038625/detect-if-device-is-ios/9039885
|
||||
(
|
||||
/iPad|iPhone|iPod/.test(navigator.platform) ||
|
||||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)
|
||||
) && !window.MSStream
|
||||
) {
|
||||
nativePlatform = Platform.iOS;
|
||||
webPlatform = Platform.MobileWeb;
|
||||
} else if (platform.toLowerCase().indexOf("linux") !== -1) {
|
||||
nativePlatform = Platform.Linux;
|
||||
webPlatform = Platform.DesktopWeb;
|
||||
} else if (platform.toLowerCase().indexOf("mac") !== -1) {
|
||||
nativePlatform = Platform.macOS;
|
||||
webPlatform = Platform.DesktopWeb;
|
||||
} else {
|
||||
nativePlatform = Platform.Windows;
|
||||
webPlatform = Platform.DesktopWeb;
|
||||
}
|
||||
return [nativePlatform, webPlatform];
|
||||
}
|
||||
|
||||
export function isWebPlatform(p) {
|
||||
|
@ -39,4 +61,4 @@ export function isWebPlatform(p) {
|
|||
|
||||
export function isDesktopPlatform(p) {
|
||||
return p === Platform.Linux || p === Platform.Windows || p === Platform.macOS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ export async function main(container) {
|
|||
const vm = new RootViewModel({
|
||||
request: xhrRequest,
|
||||
openLink: url => location.href = url,
|
||||
platforms: guessApplicablePlatforms(navigator.userAgent),
|
||||
platforms: guessApplicablePlatforms(navigator.userAgent, navigator.platform),
|
||||
preferences: new Preferences(window.localStorage),
|
||||
origin: location.origin,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue