@cardsjd/device 0.1.0 → 0.1.2
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 +112 -52
- package/lib/index.js +3 -3
- package/package.json +21 -20
package/lib/device.js
CHANGED
|
@@ -1,52 +1,112 @@
|
|
|
1
|
-
import '@sagi.io/globalthis';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (typeof navigator.
|
|
25
|
-
navigator.
|
|
26
|
-
} else
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
import '@sagi.io/globalthis';
|
|
2
|
+
export default class Device {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.onBackButton = null;
|
|
5
|
+
document.addEventListener('deviceready', () => this.onDeviceReady(), false);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
onDeviceReady() {
|
|
9
|
+
document.addEventListener('backbutton', (e) => this.backButton(e), false);
|
|
10
|
+
|
|
11
|
+
globalThis.AndroidFullScreen?.immersiveMode?.();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
backButton(e) {
|
|
15
|
+
if (typeof this.onBackButton === 'function') {
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
this.onBackButton();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exitApp() {
|
|
22
|
+
if (typeof navigator.app?.exitApp === 'function') {
|
|
23
|
+
navigator.app.exitApp();
|
|
24
|
+
} else if (typeof navigator.device?.exitApp === 'function') {
|
|
25
|
+
navigator.device.exitApp();
|
|
26
|
+
} else {
|
|
27
|
+
window.close();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @returns {OSType}
|
|
33
|
+
*/
|
|
34
|
+
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';
|
|
59
|
+
}
|
|
60
|
+
/** @typedef { 'windows' | 'amazon' | 'android' | 'ios' | 'web'} OSType */
|
|
61
|
+
|
|
62
|
+
getBrowser() {
|
|
63
|
+
return navigator.userAgent;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @returns {PlatformType}
|
|
68
|
+
*/
|
|
69
|
+
getPlatform() {
|
|
70
|
+
//facebook instant
|
|
71
|
+
if (typeof globalThis.FBInstant !== 'undefined') {
|
|
72
|
+
return 'FBInstant';
|
|
73
|
+
}
|
|
74
|
+
//native Cordova
|
|
75
|
+
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(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';
|
|
102
|
+
}
|
|
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';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return 'web';
|
|
110
|
+
}
|
|
111
|
+
/** @typedef {'FBInstant' | 'windowsPhone' | 'windows' | 'amazon' | 'android' | 'ios' | 'steam' | 'windowsPWA' | 'web'} PlatformType */
|
|
112
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import Device from './device';
|
|
2
|
-
|
|
3
|
-
export { Device };
|
|
1
|
+
import Device from './device';
|
|
2
|
+
|
|
3
|
+
export { Device };
|
package/package.json
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@cardsjd/device",
|
|
3
|
-
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "lib/index.js",
|
|
7
|
-
"files": [
|
|
8
|
-
"lib"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"lint": "eslint lib --report-unused-disable-directives --max-warnings 0",
|
|
12
|
-
"lint:fix": "npm run lint -- --fix"
|
|
13
|
-
},
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"@cardsjd/
|
|
19
|
-
|
|
20
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@cardsjd/device",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.1.2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"lint": "eslint lib --report-unused-disable-directives --max-warnings 0",
|
|
12
|
+
"lint:fix": "npm run lint -- --fix"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@capacitor/core": "^6.0.0"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@cardsjd/device": "^0.1.2",
|
|
19
|
+
"@sagi.io/globalthis": "^0.0.2"
|
|
20
|
+
}
|
|
21
|
+
}
|