@cardsjd/device 0.1.2 → 0.1.4

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 (3) hide show
  1. package/lib/device.js +125 -112
  2. package/lib/index.js +3 -3
  3. package/package.json +21 -21
package/lib/device.js CHANGED
@@ -1,112 +1,125 @@
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
- }
1
+ import '@sagi.io/globalthis';
2
+ import { Capacitor } from '@capacitor/core';
3
+
4
+ export default class Device {
5
+ constructor() {
6
+ this.onBackButton = null;
7
+ document.addEventListener('deviceready', () => this.onDeviceReady(), false);
8
+ }
9
+
10
+ onDeviceReady() {
11
+ document.addEventListener('backbutton', (e) => this.backButton(e), false);
12
+
13
+ globalThis.AndroidFullScreen?.immersiveMode?.();
14
+ }
15
+
16
+ backButton(e) {
17
+ if (typeof this.onBackButton === 'function') {
18
+ e.preventDefault();
19
+ this.onBackButton();
20
+ }
21
+ }
22
+
23
+ exitApp() {
24
+ if (typeof navigator.app?.exitApp === 'function') {
25
+ navigator.app.exitApp();
26
+ } else if (typeof navigator.device?.exitApp === 'function') {
27
+ navigator.device.exitApp();
28
+ } else {
29
+ window.close();
30
+ }
31
+ }
32
+
33
+ /**
34
+ * @returns {OSType}
35
+ */
36
+ getOS() {
37
+ const ua = navigator.userAgent;
38
+
39
+ if (/(MSAppHost\/3.0)/i.test(navigator.appVersion)) {
40
+ // Windows 10 UWP
41
+ return 'windows';
42
+ }
43
+
44
+ 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);
45
+ if (/(android)/i.test(navigator.userAgent) && isKindle) {
46
+ return 'amazon';
47
+ }
48
+
49
+ if (/(android)/i.test(navigator.userAgent) && !isKindle) {
50
+ return 'android';
51
+ }
52
+
53
+ if (/(ipod|iphone|ipad)/i.test(navigator.userAgent) || navigator.platform === 'MacIntel') {
54
+ return 'ios';
55
+ }
56
+
57
+ if (/(win)/i.test(navigator.userAgent)) {
58
+ return 'windows';
59
+ }
60
+
61
+ return 'web';
62
+ }
63
+
64
+ /** @typedef {'FBMessenger' | 'windowsPhone' | 'windows' | 'amazon' | 'android' | 'ios' | 'Steam' | 'windowsPWA' | 'web'} OSType */
65
+
66
+ getBrowser() {
67
+ return navigator.userAgent;
68
+ }
69
+
70
+ /**
71
+ * @returns {PlatformType}
72
+ */
73
+ getPlatform() {
74
+ //facebook instant
75
+ if (typeof globalThis.FBInstant !== 'undefined') {
76
+ return 'FBInstant';
77
+ }
78
+
79
+ //native Cordova
80
+ if (typeof globalThis.cordova !== 'undefined') {
81
+ 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);
82
+ if (/(android)/i.test(navigator.userAgent) && isKindle) {
83
+ return 'amazon';
84
+ }
85
+
86
+ if (/(android)/i.test(navigator.userAgent) && !isKindle) {
87
+ return 'android';
88
+ }
89
+
90
+ if (/(ipod|iphone|ipad)/i.test(navigator.userAgent) || navigator.platform === 'MacIntel') {
91
+ return 'ios';
92
+ }
93
+ }
94
+
95
+ //native Capacitor
96
+ if (Capacitor.isNativePlatform() === true) {
97
+ if (Capacitor.getPlatform() === 'ios') {
98
+ return 'ios';
99
+ }
100
+
101
+ if (Capacitor.getPlatform() === 'android') {
102
+ return 'android';
103
+ }
104
+
105
+ return Capacitor.getPlatform();
106
+ }
107
+
108
+ //stream
109
+ const searchParams = new URLSearchParams(window.location.search);
110
+ if (searchParams.get('steamId')) {
111
+ return 'steam';
112
+ }
113
+
114
+ //pwa + edg = Edge
115
+ const isInStandaloneMode = (window.matchMedia('(display-mode: standalone)').matches) || (globalThis.navigator.standalone) || document.referrer.includes('android-app://');
116
+ if (isInStandaloneMode && /(Edg)/i.test(navigator.userAgent)) {
117
+ return 'windowsPWA';
118
+ }
119
+
120
+ return 'web';
121
+ }
122
+
123
+ /** @typedef {'FBInstant' | 'windowsPhone' | 'windows' | 'amazon' | 'android' | 'ios' | 'steam' | 'windowsPWA' | 'web'} PlatformType */
124
+
125
+ }
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,21 +1,21 @@
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
- }
1
+ {
2
+ "name": "@cardsjd/device",
3
+ "private": false,
4
+ "version": "0.1.4",
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.4",
19
+ "@sagi.io/globalthis": "^0.0.2"
20
+ }
21
+ }