@cardsjd/device 0.0.1
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/README.md +0 -0
- package/lib/device.js +52 -0
- package/lib/index.js +3 -0
- package/package.json +16 -0
package/README.md
ADDED
|
Binary file
|
package/lib/device.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import '@sagi.io/globalthis';
|
|
2
|
+
import { getOS } from '@cardsjd/utilities';
|
|
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
|
+
getOS() {
|
|
34
|
+
return getOS();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getBrowser() {
|
|
38
|
+
return navigator.userAgent;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getPlatform() {
|
|
42
|
+
if (typeof globalThis.FBInstant !== 'undefined') {
|
|
43
|
+
return 'FBInstant';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (typeof globalThis.cordova !== 'undefined') {
|
|
47
|
+
return 'Cordova';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return 'web';
|
|
51
|
+
}
|
|
52
|
+
}
|
package/lib/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cardsjd/device",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.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
|
+
"devDependencies": {},
|
|
15
|
+
"dependencies": {}
|
|
16
|
+
}
|