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"
|
"Linux"
|
||||||
);
|
);
|
||||||
|
|
||||||
export function guessApplicablePlatforms(userAgent) {
|
export function guessApplicablePlatforms(userAgent, platform) {
|
||||||
// use https://github.com/faisalman/ua-parser-js to guess, and pass as RootVM options
|
// return [Platform.DesktopWeb, Platform.Linux];
|
||||||
return [Platform.DesktopWeb, Platform.Linux];
|
let nativePlatform;
|
||||||
// return [Platform.MobileWeb, Platform.Android];
|
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) {
|
export function isWebPlatform(p) {
|
||||||
|
|
|
@ -24,7 +24,7 @@ export async function main(container) {
|
||||||
const vm = new RootViewModel({
|
const vm = new RootViewModel({
|
||||||
request: xhrRequest,
|
request: xhrRequest,
|
||||||
openLink: url => location.href = url,
|
openLink: url => location.href = url,
|
||||||
platforms: guessApplicablePlatforms(navigator.userAgent),
|
platforms: guessApplicablePlatforms(navigator.userAgent, navigator.platform),
|
||||||
preferences: new Preferences(window.localStorage),
|
preferences: new Preferences(window.localStorage),
|
||||||
origin: location.origin,
|
origin: location.origin,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue