-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: AnalyticsInfo support for WASM
- Loading branch information
1 parent
ba9356c
commit 8b7b97d
Showing
6 changed files
with
202 additions
and
48 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
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,59 @@ | ||
namespace Windows.System.Profile { | ||
|
||
export class AnalyticsInfo { | ||
public static getDeviceType(): string { | ||
var ua = navigator.userAgent; | ||
|
||
if (!ua || ua === '') { | ||
// No user agent. | ||
return "unknown"; | ||
} | ||
if (ua.match(/GoogleTV|SmartTV|SMART-TV|Internet TV|NetCast|NETTV|AppleTV|boxee|Kylo|Roku|DLNADOC|hbbtv|CrKey|CE\-HTML/i)) { | ||
// if user agent is a smart TV - http://goo.gl/FocDk | ||
return "Television"; | ||
} else if (ua.match(/Xbox|PLAYSTATION (3|4)|Wii/i)) { | ||
// if user agent is a TV Based Gaming Console | ||
return "GameConsole"; | ||
} else if (ua.match(/QtCarBrowser/i)) { | ||
// if the user agent is a car | ||
return "Car"; | ||
} else if (ua.match(/iP(a|ro)d/i) || (ua.match(/tablet/i) && !ua.match(/RX-34/i)) || ua.match(/FOLIO/i)) { | ||
// if user agent is a Tablet | ||
return "Tablet"; | ||
} else if (ua.match(/Linux/i) && ua.match(/Android/i) && !ua.match(/Fennec|mobi|HTC Magic|HTCX06HT|Nexus One|SC-02B|fone 945/i)) { | ||
// if user agent is an Android Tablet | ||
return "Tablet"; | ||
} else if (ua.match(/Kindle/i) || (ua.match(/Mac OS/i) && ua.match(/Silk/i)) || (ua.match(/AppleWebKit/i) && ua.match(/Silk/i) && !ua.match(/Playstation Vita/i))) { | ||
// if user agent is a Kindle or Kindle Fire | ||
return "Tablet"; | ||
} else if (ua.match(/GT-P10|SC-01C|SHW-M180S|SGH-T849|SCH-I800|SHW-M180L|SPH-P100|SGH-I987|zt180|HTC( Flyer|_Flyer)|Sprint ATP51|ViewPad7|pandigital(sprnova|nova)|Ideos S7|Dell Streak 7|Advent Vega|A101IT|A70BHT|MID7015|Next2|nook/i) || (ua.match(/MB511/i) && ua.match(/RUTEM/i))) { | ||
// if user agent is a pre Android 3.0 Tablet | ||
return "Tablet"; | ||
} else if (ua.match(/BOLT|Fennec|Iris|Maemo|Minimo|Mobi|mowser|NetFront|Novarra|Prism|RX-34|Skyfire|Tear|XV6875|XV6975|Google Wireless Transcoder/i) && !ua.match(/AdsBot-Google-Mobile/i)) { | ||
// if user agent is unique phone User Agent | ||
return "Mobile"; | ||
} else if (ua.match(/Opera/i) && ua.match(/Windows NT 5/i) && ua.match(/HTC|Xda|Mini|Vario|SAMSUNG\-GT\-i8000|SAMSUNG\-SGH\-i9/i)) { | ||
// if user agent is an odd Opera User Agent - http://goo.gl/nK90K | ||
return "Mobile"; | ||
} else if ((ua.match(/Windows( )?(NT|XP|ME|9)/) && !ua.match(/Phone/i)) && !ua.match(/Bot|Spider|ia_archiver|NewsGator/i) || ua.match(/Win( ?9|NT)/i) || ua.match(/Go-http-client/i)) { | ||
// if user agent is Windows Desktop | ||
return "Desktop"; | ||
} else if (ua.match(/Macintosh|PowerPC/i) && !ua.match(/Silk|moatbot/i)) { | ||
// if agent is Mac Desktop | ||
return "Desktop"; | ||
} else if (ua.match(/Linux/i) && ua.match(/X11/i) && !ua.match(/Charlotte|JobBot/i)) { | ||
// if user agent is a Linux Desktop | ||
return "Desktop"; | ||
} else if (ua.match(/CrOS/)) { | ||
// if user agent is a Chrome Book | ||
return "Desktop"; | ||
} else if (ua.match(/Solaris|SunOS|BSD/i)) { | ||
// if user agent is a Solaris, SunOS, BSD Desktop | ||
return "Desktop"; | ||
} else { | ||
// Otherwise returning the unknown type configured | ||
return "Unknown"; | ||
} | ||
} | ||
} | ||
} |
90 changes: 45 additions & 45 deletions
90
src/Uno.UI/ts/Windows/System/Profile/AnalyticsVersionInfo.ts
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 |
---|---|---|
@@ -1,54 +1,54 @@ | ||
interface Window { | ||
opr: any; | ||
opera: any; | ||
mozVibrate(pattern: number | number[]): boolean; | ||
msVibrate(pattern: number | number[]): boolean; | ||
InstallTrigger: any; | ||
HTMLElement: any; | ||
StyleMedia: any; | ||
chrome: any; | ||
CSS: any; | ||
safari: any; | ||
opr: any; | ||
opera: any; | ||
mozVibrate(pattern: number | number[]): boolean; | ||
msVibrate(pattern: number | number[]): boolean; | ||
InstallTrigger: any; | ||
HTMLElement: any; | ||
StyleMedia: any; | ||
chrome: any; | ||
CSS: any; | ||
safari: any; | ||
} | ||
|
||
interface Document { | ||
documentMode: any; | ||
documentMode: any; | ||
} | ||
|
||
namespace Windows.System.Profile { | ||
|
||
export class AnalyticsVersionInfo { | ||
public static getUserAgent(): string { | ||
return navigator.userAgent; | ||
} | ||
|
||
public static getBrowserName(): string { | ||
// Opera 8.0+ | ||
if ((!!window.opr && !!window.opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { | ||
return "Opera"; | ||
} | ||
|
||
// Firefox 1.0+ | ||
if (typeof window.InstallTrigger !== 'undefined') { | ||
return "Firefox"; | ||
} | ||
|
||
// Safari 3.0+ "[object HTMLElementConstructor]" | ||
if (/constructor/i.test(window.HTMLElement) || | ||
((p: any) => p.toString() === "[object SafariRemoteNotification]")( | ||
typeof window.safari !== 'undefined' && window.safari.pushNotification)) { | ||
return "Safari"; | ||
} | ||
|
||
// Edge 20+ | ||
if (!!window.StyleMedia) { | ||
return "Edge"; | ||
} | ||
|
||
// Chrome 1 - 71 | ||
if (!!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime)) { | ||
return "Chrome"; | ||
} | ||
} | ||
} | ||
export class AnalyticsVersionInfo { | ||
public static getUserAgent(): string { | ||
return navigator.userAgent; | ||
} | ||
|
||
public static getBrowserName(): string { | ||
// Opera 8.0+ | ||
if ((!!window.opr && !!window.opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { | ||
return "Opera"; | ||
} | ||
|
||
// Firefox 1.0+ | ||
if (typeof window.InstallTrigger !== 'undefined') { | ||
return "Firefox"; | ||
} | ||
|
||
// Safari 3.0+ "[object HTMLElementConstructor]" | ||
if (/constructor/i.test(window.HTMLElement) || | ||
((p: any) => p.toString() === "[object SafariRemoteNotification]")( | ||
typeof window.safari !== 'undefined' && window.safari.pushNotification)) { | ||
return "Safari"; | ||
} | ||
|
||
// Edge 20+ | ||
if (!!window.StyleMedia) { | ||
return "Edge"; | ||
} | ||
|
||
// Chrome 1 - 71 | ||
if (!!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime)) { | ||
return "Chrome"; | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
#if __WASM__ | ||
using System; | ||
using Uno.Foundation; | ||
|
||
namespace Windows.System.Profile | ||
{ | ||
public static partial class AnalyticsInfo | ||
{ | ||
private static UnoDeviceForm GetDeviceForm() => UnoDeviceForm.Unknown; | ||
private const string JsType = "Windows.System.Profile.AnalyticsInfo"; | ||
|
||
private static UnoDeviceForm GetDeviceForm() | ||
{ | ||
var typeString = WebAssemblyRuntime.InvokeJS($"{JsType}.getDeviceType()"); | ||
if (Enum.TryParse(typeString, true, out UnoDeviceForm deviceForm)) | ||
{ | ||
return deviceForm; | ||
} | ||
return UnoDeviceForm.Unknown; | ||
} | ||
} | ||
} | ||
#endif |
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 |
---|---|---|
|
@@ -10,5 +10,6 @@ internal enum UnoDeviceForm | |
Watch, | ||
VirtualReality, | ||
Desktop, | ||
GameConsole, | ||
} | ||
} |