@cardsjd/device 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/device.js +64 -7
  2. package/package.json +2 -2
package/lib/device.js CHANGED
@@ -1,6 +1,4 @@
1
1
  import '@sagi.io/globalthis';
2
- import { getOS } from '@cardsjd/utilities';
3
- import { Capacitor } from '@capacitor/core';
4
2
  export default class Device {
5
3
  constructor() {
6
4
  this.onBackButton = null;
@@ -30,26 +28,85 @@ export default class Device {
30
28
  }
31
29
  }
32
30
 
31
+ /**
32
+ * @returns {OSType}
33
+ */
33
34
  getOS() {
34
- return getOS();
35
+ const ua = navigator.userAgent;
36
+
37
+ if (/(MSAppHost\/3.0)/i.test(navigator.appVersion)) {
38
+ // Windows 10 UWP
39
+ return 'windows';
40
+ }
41
+
42
+ const isKindle = /Kindle|Silk|Amazon|KFDOWI|KFAPWA|KFSAW|KFGIWI|KFGIWI|KFAPW|KFARWI|KFTBWI|KFASWI|KFFOWI|KFJW|KFMEWI|KFOT|KFSAW|KFSOWI|KFTBW|KFTHW|KFTT|WFFOWI|KFJWA|KFJWI|KFTHWA|KFTHWI|KFAPWI|KFKAWI/i.test(ua);
43
+ if (/(android)/i.test(navigator.userAgent) && isKindle) {
44
+ return 'amazon';
45
+ }
46
+
47
+ if (/(android)/i.test(navigator.userAgent) && !isKindle) {
48
+ return 'android';
49
+ }
50
+
51
+ if (/(ipod|iphone|ipad)/i.test(navigator.userAgent) || navigator.platform === 'MacIntel') {
52
+ return 'ios';
53
+ }
54
+ if (/(win)/i.test(navigator.userAgent)) {
55
+ return 'windows';
56
+ }
57
+
58
+ return 'web';
35
59
  }
60
+ /** @typedef { 'windows' | 'amazon' | 'android' | 'ios' | 'web'} OSType */
36
61
 
37
62
  getBrowser() {
38
63
  return navigator.userAgent;
39
64
  }
40
65
 
66
+ /**
67
+ * @returns {PlatformType}
68
+ */
41
69
  getPlatform() {
70
+ //facebook instant
42
71
  if (typeof globalThis.FBInstant !== 'undefined') {
43
72
  return 'FBInstant';
44
73
  }
45
-
74
+ //native Cordova
46
75
  if (typeof globalThis.cordova !== 'undefined') {
47
- return 'Cordova';
76
+ const isKindle = /Kindle|Silk|Amazon|KFDOWI|KFAPWA|KFSAW|KFGIWI|KFGIWI|KFAPW|KFARWI|KFTBWI|KFASWI|KFFOWI|KFJW|KFMEWI|KFOT|KFSAW|KFSOWI|KFTBW|KFTHW|KFTT|WFFOWI|KFJWA|KFJWI|KFTHWA|KFTHWI|KFAPWI|KFKAWI/i.test(ua);
77
+ if (/(android)/i.test(navigator.userAgent) && isKindle) {
78
+ return 'amazon';
79
+ }
80
+ if (/(android)/i.test(navigator.userAgent) && !isKindle) {
81
+ return 'android';
82
+ }
83
+ if (/(ipod|iphone|ipad)/i.test(navigator.userAgent) || navigator.platform === 'MacIntel') {
84
+ return 'ios';
85
+ }
86
+ return platformCordova;
87
+ }
88
+ //native Capacitor
89
+ if (Capacitor.isNativePlatform() === true) {
90
+ if (Capacitor.getPlatform() === 'ios') {
91
+ return 'ios';
92
+ }
93
+ if (Capacitor.getPlatform() === 'android') {
94
+ return 'android';
95
+ }
96
+ return Capacitor.getPlatform();
97
+ }
98
+ //stream
99
+ const searchParams = new URLSearchParams(window.location.search);
100
+ if (searchParams.get('steamId')) {
101
+ return 'steam';
48
102
  }
49
- if( Capacitor.isNativePlatform() === true){
50
- return 'native';
103
+ //pwa + edg = Edge
104
+ const isInStandaloneMode = (window.matchMedia('(display-mode: standalone)').matches) || (globalThis.navigator.standalone) || document.referrer.includes('android-app://');
105
+ if (isInStandaloneMode && /(Edg)/i.test(navigator.userAgent)) {
106
+ return 'windowsPWA';
51
107
  }
52
108
 
53
109
  return 'web';
54
110
  }
111
+ /** @typedef {'FBInstant' | 'windowsPhone' | 'windows' | 'amazon' | 'android' | 'ios' | 'steam' | 'windowsPWA' | 'web'} PlatformType */
55
112
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cardsjd/device",
3
3
  "private": false,
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "files": [
@@ -15,7 +15,7 @@
15
15
  "@capacitor/core": "^6.0.0"
16
16
  },
17
17
  "peerDependencies": {
18
- "@cardsjd/utilities": "^0.0.0",
18
+ "@cardsjd/device": "^0.1.3",
19
19
  "@sagi.io/globalthis": "^0.0.2"
20
20
  }
21
21
  }