gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-ops-www] branch master updated: refactor ua


From: gnunet
Subject: [taler-taler-ops-www] branch master updated: refactor ua
Date: Sun, 31 Mar 2024 16:24:23 +0200

This is an automated email from the git hooks/post-receive script.

nora-grothoff pushed a commit to branch master
in repository taler-ops-www.

The following commit(s) were added to refs/heads/master by this push:
     new e6e2c4c  refactor ua
e6e2c4c is described below

commit e6e2c4c40bb19b1c935464a1cb51598b4fbb4d47
Author: Nullptrderef <nullptrderef@proton.me>
AuthorDate: Sun Mar 31 16:24:20 2024 +0200

    refactor ua
---
 static/js/vendored/ua.ts | 218 +++++++++++++++++++++++------------------------
 1 file changed, 107 insertions(+), 111 deletions(-)

diff --git a/static/js/vendored/ua.ts b/static/js/vendored/ua.ts
index 978a914..b74cabd 100644
--- a/static/js/vendored/ua.ts
+++ b/static/js/vendored/ua.ts
@@ -16,7 +16,7 @@ export enum OS {
   Android = 'android',
   iOS = 'ios',
   Linux = 'linux',
-  Darwin = 'darwin',
+  MacOS = 'macos',
   Win32 = 'win32',
   Unknown = '',
 }
@@ -32,9 +32,9 @@ export default class Platform {
   public static readonly OS = OS;
   public static readonly Browser = Browser;
 
-  public device = Device.Desktop;
-  public os = OS.Android;
-  public browser = Browser.Firefox;
+  public device = Device.Unknown;
+  public os = OS.Unknown;
+  public browser = Browser.Unknown;
 
   public constructor(public userAgent = navigator.userAgent) {
     this.update(userAgent);
@@ -43,9 +43,63 @@ export default class Platform {
   public update(userAgent = navigator.userAgent) {
     this.userAgent = userAgent;
 
-    this.setDevice();
-    this.setOS();
-    this.setBrowser();
+    switch (true) {
+      case this.isTabletUA():
+        this.device = Device.Tablet;
+        break;
+      case this.isMobileUA():
+        this.device = Device.Mobile;
+        break;
+      case this.isDesktopUA():
+        this.device = Device.Desktop;
+        break;
+      default:
+        this.device = Device.Unknown;
+        break;
+    }
+    switch (true) {
+      case this.isAndroidUA():
+        this.os = OS.Android;
+        break;
+      case this.isIOSUA():
+        this.os = OS.iOS;
+        break;
+      case this.isLinuxUA():
+        this.os = OS.Linux;
+        break;
+      case this.isMacOSUA():
+        this.os = OS.MacOS;
+        break;
+      case this.isWin32UA():
+        this.os = OS.Win32;
+        break;
+      default:
+        this.os = OS.Unknown;
+        break;
+    }
+    switch (true) {
+      case this.isChrome():
+        this.browser = Browser.Chromium;
+        break;
+      case this.isFirefox():
+        this.browser = Browser.Firefox;
+        break;
+      case this.isOpera():
+        this.browser = Browser.Opera;
+        break;
+      case this.isEdge():
+        this.browser = Browser.Edge;
+        break;
+      case this.isSafari():
+        this.browser = Browser.Safari;
+        break;
+      case this.isIE():
+        this.browser = Browser.IE;
+        break;
+      default:
+        this.browser = Browser.Unknown;
+        break;
+    }
   }
 
   /** Adds OS, Device and Browser classes to the body */
@@ -55,155 +109,97 @@ export default class Platform {
     if (this.browser) document.body.classList.add(this.browser);
   }
 
-  public compareDevice(device: string): boolean {
-    return this.device === device;
-  }
-
-  public compareOs(os: string): boolean {
-    return this.os === os;
-  }
-
-  public compareBrowser(browser: string): boolean {
-    return this.browser === browser;
-  }
-
-  public isDesktop(): boolean {
-    return this.compareDevice(Device.Desktop);
+  public get desktop(): boolean {
+    return this.device === Device.Desktop;
   }
 
-  public isTablet(): boolean {
-    return this.compareDevice(Device.Tablet);
+  public get tablet(): boolean {
+    return this.device === Device.Tablet;
   }
 
-  public isMobile(): boolean {
-    return this.compareDevice(Device.Mobile);
+  public get mobile(): boolean {
+    return this.device === Device.Mobile;
   }
 
-  public detectDesktop(): boolean {
-    return !this.detectMobile() && !this.detectTablet();
+  /** Checks if the user is on desktop (true if not mobile and not tablet) */
+  public isDesktopUA(): boolean {
+    return !this.isMobileUA() && !this.isTabletUA();
   }
 
-  public detectTablet(): boolean {
+  /** Checks if the user is on a tablet or not */
+  public isTabletUA(): boolean {
     return /tablet|ipad/i.test(this.userAgent);
   }
 
-  public detectMobile(): boolean {
+  /** Checks if the user is on a list of known phones */
+  public isMobileUA(): boolean {
     return /mobile|iphone|ipod|android|windows *phone/i.test(this.userAgent);
   }
 
-  public detectAndroid(): boolean {
+  /** Checks if the user is on android */
+  public isAndroidUA(): boolean {
     return /android/i.test(this.userAgent);
   }
 
-  public detectIOS(): boolean {
+  /** Checks if the user is on iOS */
+  public isIOSUA(): boolean {
     return /ipad|iphone|ipod/i.test(this.userAgent);
   }
 
-  public detectLinux(): boolean {
+  /** Checks if the user is on Linux */
+  public isLinuxUA(): boolean {
     return /linux/i.test(this.userAgent);
   }
 
-  public detectDarwin(): boolean {
+  /** Checks if the user is on Macos/MacOS */
+  public isMacOSUA(): boolean {
     return /macintosh|os *x/i.test(this.userAgent);
   }
 
-  public detectWin32(): boolean {
+  /**
+   * Checks if the user is on a Windows User-Agent
+   * Note: Name is misleading; Windows refers to itself as Win32 on x64 aswell.
+   */
+  public isWin32UA(): boolean {
     return /windows|win64|win32/i.test(this.userAgent);
   }
 
-  public detectChrome(): boolean {
-    return (
-      /chrome/i.test(this.userAgent) &&
-      !this.detectOpera() &&
-      !this.detectEdge()
-    );
+  /** Checks if we're chrome/chromium based */
+  public isChromiumBased(): boolean {
+    return /chrome|chromium/i.test(this.userAgent);
+  }
+  /** Checks if we're chrome/chromium but not a fork thereof */
+  public isChrome(): boolean {
+    return this.isChromiumBased() && !this.isOpera() && !this.isEdge();
   }
 
-  public detectFirefox(): boolean {
+  /** Checks if we're on firefox */
+  public isFirefox(): boolean {
     return /firefox/i.test(this.userAgent);
   }
 
-  public detectOpera(): boolean {
+  /** Checks if we're on opera */
+  public isOpera(): boolean {
     return /opr/i.test(this.userAgent);
   }
 
-  public detectEdge(): boolean {
+  /** Chceks if we're on Edge */
+  public isEdge(): boolean {
     return /edge/i.test(this.userAgent);
   }
 
-  public detectSafari(): boolean {
+  /** Checks if we're on Safari */
+  public isSafari(): boolean {
     return (
       /safari/i.test(this.userAgent) &&
-      !this.detectChrome() &&
-      !this.detectOpera() &&
-      !this.detectEdge()
+      !this.isChrome() &&
+      !this.isOpera() &&
+      !this.isEdge()
     );
   }
 
-  public detectExplorer(): boolean {
+  /** Checks if we're on IE/pre-chromium Edge */
+  public isIE(): boolean {
     return /msie|trident/i.test(this.userAgent);
   }
-
-  public setDevice(): void {
-    switch (true) {
-      case this.detectTablet():
-        this.device = Device.Tablet;
-        break;
-      case this.detectMobile():
-        this.device = Device.Mobile;
-        break;
-      case this.detectDesktop():
-        this.device = Device.Desktop;
-        break;
-      default:
-        this.device = Device.Unknown;
-    }
-  }
-
-  public setOS(): void {
-    switch (true) {
-      case this.detectAndroid():
-        this.os = OS.Android;
-        break;
-      case this.detectIOS():
-        this.os = OS.iOS;
-        break;
-      case this.detectLinux():
-        this.os = OS.Linux;
-        break;
-      case this.detectDarwin():
-        this.os = OS.Darwin;
-        break;
-      case this.detectWin32():
-        this.os = OS.Win32;
-        break;
-      default:
-        this.os = OS.Unknown;
-    }
-  }
-
-  public setBrowser(): void {
-    switch (true) {
-      case this.detectChrome():
-        this.browser = Browser.Chromium;
-        break;
-      case this.detectFirefox():
-        this.browser = Browser.Firefox;
-        break;
-      case this.detectOpera():
-        this.browser = Browser.Opera;
-        break;
-      case this.detectEdge():
-        this.browser = Browser.Edge;
-        break;
-      case this.detectSafari():
-        this.browser = Browser.Safari;
-        break;
-      case this.detectExplorer():
-        this.browser = Browser.IE;
-        break;
-      default:
-        this.browser = Browser.Unknown;
-    }
-  }
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]