@cardsjd/device 0.1.3 → 0.1.5
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.
- package/lib/device.js +21 -4
- package/package.json +2 -2
package/lib/device.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import '@sagi.io/globalthis';
|
|
2
|
+
import { Capacitor } from '@capacitor/core';
|
|
3
|
+
|
|
2
4
|
export default class Device {
|
|
3
5
|
constructor() {
|
|
4
6
|
this.onBackButton = null;
|
|
@@ -51,13 +53,15 @@ export default class Device {
|
|
|
51
53
|
if (/(ipod|iphone|ipad)/i.test(navigator.userAgent) || navigator.platform === 'MacIntel') {
|
|
52
54
|
return 'ios';
|
|
53
55
|
}
|
|
56
|
+
|
|
54
57
|
if (/(win)/i.test(navigator.userAgent)) {
|
|
55
58
|
return 'windows';
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
return 'web';
|
|
59
62
|
}
|
|
60
|
-
|
|
63
|
+
|
|
64
|
+
/** @typedef {'FBMessenger' | 'windowsPhone' | 'windows' | 'amazon' | 'android' | 'ios' | 'Steam' | 'windowsPWA' | 'web'} OSType */
|
|
61
65
|
|
|
62
66
|
getBrowser() {
|
|
63
67
|
return navigator.userAgent;
|
|
@@ -71,35 +75,46 @@ export default class Device {
|
|
|
71
75
|
if (typeof globalThis.FBInstant !== 'undefined') {
|
|
72
76
|
return 'FBInstant';
|
|
73
77
|
}
|
|
78
|
+
|
|
79
|
+
if (typeof globalThis.CrazyGames !== 'undefined') {
|
|
80
|
+
return 'CrazyGames';
|
|
81
|
+
}
|
|
82
|
+
|
|
74
83
|
//native Cordova
|
|
75
84
|
if (typeof globalThis.cordova !== 'undefined') {
|
|
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(
|
|
85
|
+
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(navigator.userAgent);
|
|
77
86
|
if (/(android)/i.test(navigator.userAgent) && isKindle) {
|
|
78
87
|
return 'amazon';
|
|
79
88
|
}
|
|
89
|
+
|
|
80
90
|
if (/(android)/i.test(navigator.userAgent) && !isKindle) {
|
|
81
91
|
return 'android';
|
|
82
92
|
}
|
|
93
|
+
|
|
83
94
|
if (/(ipod|iphone|ipad)/i.test(navigator.userAgent) || navigator.platform === 'MacIntel') {
|
|
84
95
|
return 'ios';
|
|
85
96
|
}
|
|
86
|
-
return platformCordova;
|
|
87
97
|
}
|
|
98
|
+
|
|
88
99
|
//native Capacitor
|
|
89
100
|
if (Capacitor.isNativePlatform() === true) {
|
|
90
101
|
if (Capacitor.getPlatform() === 'ios') {
|
|
91
102
|
return 'ios';
|
|
92
103
|
}
|
|
104
|
+
|
|
93
105
|
if (Capacitor.getPlatform() === 'android') {
|
|
94
106
|
return 'android';
|
|
95
107
|
}
|
|
108
|
+
|
|
96
109
|
return Capacitor.getPlatform();
|
|
97
110
|
}
|
|
111
|
+
|
|
98
112
|
//stream
|
|
99
113
|
const searchParams = new URLSearchParams(window.location.search);
|
|
100
114
|
if (searchParams.get('steamId')) {
|
|
101
115
|
return 'steam';
|
|
102
116
|
}
|
|
117
|
+
|
|
103
118
|
//pwa + edg = Edge
|
|
104
119
|
const isInStandaloneMode = (window.matchMedia('(display-mode: standalone)').matches) || (globalThis.navigator.standalone) || document.referrer.includes('android-app://');
|
|
105
120
|
if (isInStandaloneMode && /(Edg)/i.test(navigator.userAgent)) {
|
|
@@ -108,5 +123,7 @@ export default class Device {
|
|
|
108
123
|
|
|
109
124
|
return 'web';
|
|
110
125
|
}
|
|
111
|
-
|
|
126
|
+
|
|
127
|
+
/** @typedef {'FBInstant' | 'windowsPhone' | 'windows' | 'amazon' | 'android' | 'ios' | 'steam' | 'windowsPWA' | 'web' | 'CrazyGames'} PlatformType */
|
|
128
|
+
|
|
112
129
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cardsjd/device",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
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/device": "^0.1.
|
|
18
|
+
"@cardsjd/device": "^0.1.4",
|
|
19
19
|
"@sagi.io/globalthis": "^0.0.2"
|
|
20
20
|
}
|
|
21
21
|
}
|