@capawesome/capacitor-device-info 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/CapawesomeCapacitorDeviceInfo.podspec +21 -0
- package/LICENSE +21 -0
- package/Package.swift +29 -0
- package/README.md +264 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/DeviceInfo.java +119 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/DeviceInfoPlugin.java +106 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/classes/results/GetIdResult.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/classes/results/GetInfoResult.java +98 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/classes/results/GetUptimeResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +413 -0
- package/dist/esm/definitions.d.ts +203 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +13 -0
- package/dist/esm/web.js +130 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +144 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +147 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Results/GetIdResult.swift +16 -0
- package/ios/Plugin/Classes/Results/GetInfoResult.swift +66 -0
- package/ios/Plugin/Classes/Results/GetUptimeResult.swift +16 -0
- package/ios/Plugin/DeviceInfo.swift +89 -0
- package/ios/Plugin/DeviceInfoPlugin.swift +64 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/PrivacyInfo.xcprivacy +23 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +91 -0
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
var capacitorDeviceInfo = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const DeviceInfo = core.registerPlugin('DeviceInfo', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.DeviceInfoWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class DeviceInfoWeb extends core.WebPlugin {
|
|
9
|
+
async getId() {
|
|
10
|
+
let identifier = window.localStorage.getItem(DeviceInfoWeb.identifierStorageKey);
|
|
11
|
+
if (!identifier) {
|
|
12
|
+
identifier = this.createIdentifier();
|
|
13
|
+
window.localStorage.setItem(DeviceInfoWeb.identifierStorageKey, identifier);
|
|
14
|
+
}
|
|
15
|
+
return { identifier };
|
|
16
|
+
}
|
|
17
|
+
async getInfo() {
|
|
18
|
+
var _a;
|
|
19
|
+
const userAgent = navigator.userAgent;
|
|
20
|
+
const userAgentData = navigator
|
|
21
|
+
.userAgentData;
|
|
22
|
+
return {
|
|
23
|
+
androidSdkVersion: null,
|
|
24
|
+
deviceType: this.determineDeviceType(userAgent, userAgentData),
|
|
25
|
+
iosVersion: null,
|
|
26
|
+
isVirtual: false,
|
|
27
|
+
manufacturer: 'unknown',
|
|
28
|
+
model: 'unknown',
|
|
29
|
+
name: null,
|
|
30
|
+
operatingSystem: this.determineOperatingSystem(userAgent, userAgentData),
|
|
31
|
+
osVersion: (_a = this.determineOsVersion(userAgent)) !== null && _a !== void 0 ? _a : 'unknown',
|
|
32
|
+
platform: 'web',
|
|
33
|
+
totalMemory: null,
|
|
34
|
+
usedMemory: null,
|
|
35
|
+
webViewVersion: this.determineWebViewVersion(userAgent),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
async getUptime() {
|
|
39
|
+
throw this.unimplemented('Not implemented on web.');
|
|
40
|
+
}
|
|
41
|
+
createIdentifier() {
|
|
42
|
+
if (typeof crypto !== 'undefined' && 'randomUUID' in crypto) {
|
|
43
|
+
return crypto.randomUUID();
|
|
44
|
+
}
|
|
45
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, character => {
|
|
46
|
+
const random = (Math.random() * 16) | 0;
|
|
47
|
+
const value = character === 'x' ? random : (random & 0x3) | 0x8;
|
|
48
|
+
return value.toString(16);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
determineDeviceType(userAgent, userAgentData) {
|
|
52
|
+
if (/TV|SmartTV|Tizen|Web0S|WebOS/i.test(userAgent)) {
|
|
53
|
+
return 'tv';
|
|
54
|
+
}
|
|
55
|
+
if (/iPad/.test(userAgent)) {
|
|
56
|
+
return 'tablet';
|
|
57
|
+
}
|
|
58
|
+
if (/Android/.test(userAgent) && !/Mobile/.test(userAgent)) {
|
|
59
|
+
return 'tablet';
|
|
60
|
+
}
|
|
61
|
+
if (userAgentData === null || userAgentData === void 0 ? void 0 : userAgentData.mobile) {
|
|
62
|
+
return 'phone';
|
|
63
|
+
}
|
|
64
|
+
if (/Mobile|iPhone|iPod/.test(userAgent)) {
|
|
65
|
+
return 'phone';
|
|
66
|
+
}
|
|
67
|
+
return 'desktop';
|
|
68
|
+
}
|
|
69
|
+
determineOperatingSystem(userAgent, userAgentData) {
|
|
70
|
+
var _a;
|
|
71
|
+
const platform = (_a = userAgentData === null || userAgentData === void 0 ? void 0 : userAgentData.platform) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
72
|
+
if (platform) {
|
|
73
|
+
if (platform.includes('win')) {
|
|
74
|
+
return 'windows';
|
|
75
|
+
}
|
|
76
|
+
if (platform.includes('android')) {
|
|
77
|
+
return 'android';
|
|
78
|
+
}
|
|
79
|
+
if (platform.includes('ios')) {
|
|
80
|
+
return 'ios';
|
|
81
|
+
}
|
|
82
|
+
if (platform.includes('mac')) {
|
|
83
|
+
return 'mac';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (/Windows/.test(userAgent)) {
|
|
87
|
+
return 'windows';
|
|
88
|
+
}
|
|
89
|
+
if (/Android/.test(userAgent)) {
|
|
90
|
+
return 'android';
|
|
91
|
+
}
|
|
92
|
+
if (/iPhone|iPad|iPod/.test(userAgent)) {
|
|
93
|
+
return 'ios';
|
|
94
|
+
}
|
|
95
|
+
if (/Mac OS X/.test(userAgent)) {
|
|
96
|
+
return 'mac';
|
|
97
|
+
}
|
|
98
|
+
return 'unknown';
|
|
99
|
+
}
|
|
100
|
+
determineOsVersion(userAgent) {
|
|
101
|
+
const windowsMatch = /Windows NT ([0-9._]+)/.exec(userAgent);
|
|
102
|
+
if (windowsMatch) {
|
|
103
|
+
return windowsMatch[1];
|
|
104
|
+
}
|
|
105
|
+
const androidMatch = /Android ([0-9._]+)/.exec(userAgent);
|
|
106
|
+
if (androidMatch) {
|
|
107
|
+
return androidMatch[1];
|
|
108
|
+
}
|
|
109
|
+
const iosMatch = /OS ([0-9_]+) like Mac OS X/.exec(userAgent);
|
|
110
|
+
if (iosMatch) {
|
|
111
|
+
return iosMatch[1].replace(/_/g, '.');
|
|
112
|
+
}
|
|
113
|
+
const macMatch = /Mac OS X ([0-9_]+)/.exec(userAgent);
|
|
114
|
+
if (macMatch) {
|
|
115
|
+
return macMatch[1].replace(/_/g, '.');
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
determineWebViewVersion(userAgent) {
|
|
120
|
+
const patterns = [
|
|
121
|
+
/Edg\/([0-9.]+)/,
|
|
122
|
+
/Chrome\/([0-9.]+)/,
|
|
123
|
+
/Firefox\/([0-9.]+)/,
|
|
124
|
+
/Version\/([0-9.]+).*Safari/,
|
|
125
|
+
];
|
|
126
|
+
for (const pattern of patterns) {
|
|
127
|
+
const match = pattern.exec(userAgent);
|
|
128
|
+
if (match) {
|
|
129
|
+
return match[1];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
DeviceInfoWeb.identifierStorageKey = 'capawesome-capacitor-device-info-id';
|
|
136
|
+
|
|
137
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
138
|
+
__proto__: null,
|
|
139
|
+
DeviceInfoWeb: DeviceInfoWeb
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
exports.DeviceInfo = DeviceInfo;
|
|
143
|
+
|
|
144
|
+
return exports;
|
|
145
|
+
|
|
146
|
+
})({}, capacitorExports);
|
|
147
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst DeviceInfo = registerPlugin('DeviceInfo', {\n web: () => import('./web').then(m => new m.DeviceInfoWeb()),\n});\nexport * from './definitions';\nexport { DeviceInfo };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class DeviceInfoWeb extends WebPlugin {\n async getId() {\n let identifier = window.localStorage.getItem(DeviceInfoWeb.identifierStorageKey);\n if (!identifier) {\n identifier = this.createIdentifier();\n window.localStorage.setItem(DeviceInfoWeb.identifierStorageKey, identifier);\n }\n return { identifier };\n }\n async getInfo() {\n var _a;\n const userAgent = navigator.userAgent;\n const userAgentData = navigator\n .userAgentData;\n return {\n androidSdkVersion: null,\n deviceType: this.determineDeviceType(userAgent, userAgentData),\n iosVersion: null,\n isVirtual: false,\n manufacturer: 'unknown',\n model: 'unknown',\n name: null,\n operatingSystem: this.determineOperatingSystem(userAgent, userAgentData),\n osVersion: (_a = this.determineOsVersion(userAgent)) !== null && _a !== void 0 ? _a : 'unknown',\n platform: 'web',\n totalMemory: null,\n usedMemory: null,\n webViewVersion: this.determineWebViewVersion(userAgent),\n };\n }\n async getUptime() {\n throw this.unimplemented('Not implemented on web.');\n }\n createIdentifier() {\n if (typeof crypto !== 'undefined' && 'randomUUID' in crypto) {\n return crypto.randomUUID();\n }\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, character => {\n const random = (Math.random() * 16) | 0;\n const value = character === 'x' ? random : (random & 0x3) | 0x8;\n return value.toString(16);\n });\n }\n determineDeviceType(userAgent, userAgentData) {\n if (/TV|SmartTV|Tizen|Web0S|WebOS/i.test(userAgent)) {\n return 'tv';\n }\n if (/iPad/.test(userAgent)) {\n return 'tablet';\n }\n if (/Android/.test(userAgent) && !/Mobile/.test(userAgent)) {\n return 'tablet';\n }\n if (userAgentData === null || userAgentData === void 0 ? void 0 : userAgentData.mobile) {\n return 'phone';\n }\n if (/Mobile|iPhone|iPod/.test(userAgent)) {\n return 'phone';\n }\n return 'desktop';\n }\n determineOperatingSystem(userAgent, userAgentData) {\n var _a;\n const platform = (_a = userAgentData === null || userAgentData === void 0 ? void 0 : userAgentData.platform) === null || _a === void 0 ? void 0 : _a.toLowerCase();\n if (platform) {\n if (platform.includes('win')) {\n return 'windows';\n }\n if (platform.includes('android')) {\n return 'android';\n }\n if (platform.includes('ios')) {\n return 'ios';\n }\n if (platform.includes('mac')) {\n return 'mac';\n }\n }\n if (/Windows/.test(userAgent)) {\n return 'windows';\n }\n if (/Android/.test(userAgent)) {\n return 'android';\n }\n if (/iPhone|iPad|iPod/.test(userAgent)) {\n return 'ios';\n }\n if (/Mac OS X/.test(userAgent)) {\n return 'mac';\n }\n return 'unknown';\n }\n determineOsVersion(userAgent) {\n const windowsMatch = /Windows NT ([0-9._]+)/.exec(userAgent);\n if (windowsMatch) {\n return windowsMatch[1];\n }\n const androidMatch = /Android ([0-9._]+)/.exec(userAgent);\n if (androidMatch) {\n return androidMatch[1];\n }\n const iosMatch = /OS ([0-9_]+) like Mac OS X/.exec(userAgent);\n if (iosMatch) {\n return iosMatch[1].replace(/_/g, '.');\n }\n const macMatch = /Mac OS X ([0-9_]+)/.exec(userAgent);\n if (macMatch) {\n return macMatch[1].replace(/_/g, '.');\n }\n return null;\n }\n determineWebViewVersion(userAgent) {\n const patterns = [\n /Edg\\/([0-9.]+)/,\n /Chrome\\/([0-9.]+)/,\n /Firefox\\/([0-9.]+)/,\n /Version\\/([0-9.]+).*Safari/,\n ];\n for (const pattern of patterns) {\n const match = pattern.exec(userAgent);\n if (match) {\n return match[1];\n }\n }\n return null;\n }\n}\nDeviceInfoWeb.identifierStorageKey = 'capawesome-capacitor-device-info-id';\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;IAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;IAC/D,CAAC;;ICFM,MAAM,aAAa,SAASC,cAAS,CAAC;IAC7C,IAAI,MAAM,KAAK,GAAG;IAClB,QAAQ,IAAI,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,aAAa,CAAC,oBAAoB,CAAC;IACxF,QAAQ,IAAI,CAAC,UAAU,EAAE;IACzB,YAAY,UAAU,GAAG,IAAI,CAAC,gBAAgB,EAAE;IAChD,YAAY,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,aAAa,CAAC,oBAAoB,EAAE,UAAU,CAAC;IACvF,QAAQ;IACR,QAAQ,OAAO,EAAE,UAAU,EAAE;IAC7B,IAAI;IACJ,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,IAAI,EAAE;IACd,QAAQ,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS;IAC7C,QAAQ,MAAM,aAAa,GAAG;IAC9B,aAAa,aAAa;IAC1B,QAAQ,OAAO;IACf,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AAoB,CAAC,IAAI,CAAC,SAAS,CAAC;IAC7D,QAAQ,IAAI,QAAQ,EAAE;IACtB,YAAY,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;IACjD,QAAQ;IACR,QAAQ,OAAO,IAAI;IACnB,IAAI;IACJ,IAAI,uBAAuB,CAAC,SAAS,EAAE;IACvC,QAAQ,MAAM,QAAQ,GAAG;IACzB,YAAY,gBAAgB;IAC5B,YAAY,mBAAmB;IAC/B,YAAY,oBAAoB;IAChC,YAAY,4BAA4B;IACxC,SAAS;IACT,QAAQ,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;IACxC,YAAY,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;IACjD,YAAY,IAAI,KAAK,EAAE;IACvB,gBAAgB,OAAO,KAAK,CAAC,CAAC,CAAC;IAC/B,YAAY;IACZ,QAAQ;IACR,QAAQ,OAAO,IAAI;IACnB,IAAI;IACJ;IACA,aAAa,CAAC,oBAAoB,GAAG,qCAAqC;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class GetIdResult: NSObject, Result {
|
|
5
|
+
let identifier: String
|
|
6
|
+
|
|
7
|
+
init(identifier: String) {
|
|
8
|
+
self.identifier = identifier
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@objc public func toJSObject() -> AnyObject {
|
|
12
|
+
var result = JSObject()
|
|
13
|
+
result["identifier"] = identifier
|
|
14
|
+
return result as AnyObject
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class GetInfoResult: NSObject, Result {
|
|
5
|
+
let androidSdkVersion: Int?
|
|
6
|
+
let deviceType: String
|
|
7
|
+
let iosVersion: Int?
|
|
8
|
+
let isVirtual: Bool
|
|
9
|
+
let manufacturer: String
|
|
10
|
+
let model: String
|
|
11
|
+
let name: String?
|
|
12
|
+
let operatingSystem: String
|
|
13
|
+
let osVersion: String
|
|
14
|
+
let platform: String
|
|
15
|
+
let totalMemory: Int?
|
|
16
|
+
let usedMemory: Int?
|
|
17
|
+
let webViewVersion: String?
|
|
18
|
+
|
|
19
|
+
init(
|
|
20
|
+
androidSdkVersion: Int?,
|
|
21
|
+
deviceType: String,
|
|
22
|
+
iosVersion: Int?,
|
|
23
|
+
isVirtual: Bool,
|
|
24
|
+
manufacturer: String,
|
|
25
|
+
model: String,
|
|
26
|
+
name: String?,
|
|
27
|
+
operatingSystem: String,
|
|
28
|
+
osVersion: String,
|
|
29
|
+
platform: String,
|
|
30
|
+
totalMemory: Int?,
|
|
31
|
+
usedMemory: Int?,
|
|
32
|
+
webViewVersion: String?
|
|
33
|
+
) {
|
|
34
|
+
self.androidSdkVersion = androidSdkVersion
|
|
35
|
+
self.deviceType = deviceType
|
|
36
|
+
self.iosVersion = iosVersion
|
|
37
|
+
self.isVirtual = isVirtual
|
|
38
|
+
self.manufacturer = manufacturer
|
|
39
|
+
self.model = model
|
|
40
|
+
self.name = name
|
|
41
|
+
self.operatingSystem = operatingSystem
|
|
42
|
+
self.osVersion = osVersion
|
|
43
|
+
self.platform = platform
|
|
44
|
+
self.totalMemory = totalMemory
|
|
45
|
+
self.usedMemory = usedMemory
|
|
46
|
+
self.webViewVersion = webViewVersion
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@objc public func toJSObject() -> AnyObject {
|
|
50
|
+
var result = JSObject()
|
|
51
|
+
result["androidSdkVersion"] = androidSdkVersion == nil ? NSNull() : androidSdkVersion
|
|
52
|
+
result["deviceType"] = deviceType
|
|
53
|
+
result["iosVersion"] = iosVersion == nil ? NSNull() : iosVersion
|
|
54
|
+
result["isVirtual"] = isVirtual
|
|
55
|
+
result["manufacturer"] = manufacturer
|
|
56
|
+
result["model"] = model
|
|
57
|
+
result["name"] = name == nil ? NSNull() : name
|
|
58
|
+
result["operatingSystem"] = operatingSystem
|
|
59
|
+
result["osVersion"] = osVersion
|
|
60
|
+
result["platform"] = platform
|
|
61
|
+
result["totalMemory"] = totalMemory == nil ? NSNull() : totalMemory
|
|
62
|
+
result["usedMemory"] = usedMemory == nil ? NSNull() : usedMemory
|
|
63
|
+
result["webViewVersion"] = webViewVersion == nil ? NSNull() : webViewVersion
|
|
64
|
+
return result as AnyObject
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class GetUptimeResult: NSObject, Result {
|
|
5
|
+
let uptime: Int
|
|
6
|
+
|
|
7
|
+
init(uptime: Int) {
|
|
8
|
+
self.uptime = uptime
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@objc public func toJSObject() -> AnyObject {
|
|
12
|
+
var result = JSObject()
|
|
13
|
+
result["uptime"] = uptime
|
|
14
|
+
return result as AnyObject
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
@objc public class DeviceInfo: NSObject {
|
|
5
|
+
let plugin: DeviceInfoPlugin
|
|
6
|
+
|
|
7
|
+
init(plugin: DeviceInfoPlugin) {
|
|
8
|
+
self.plugin = plugin
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@objc public func getId(completion: @escaping (GetIdResult?, Error?) -> Void) {
|
|
12
|
+
let identifier = UIDevice.current.identifierForVendor?.uuidString ?? ""
|
|
13
|
+
completion(GetIdResult(identifier: identifier), nil)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@objc public func getInfo(completion: @escaping (GetInfoResult?, Error?) -> Void) {
|
|
17
|
+
let result = GetInfoResult(
|
|
18
|
+
androidSdkVersion: nil,
|
|
19
|
+
deviceType: determineDeviceType(),
|
|
20
|
+
iosVersion: ProcessInfo.processInfo.operatingSystemVersion.majorVersion,
|
|
21
|
+
isVirtual: determineIsVirtual(),
|
|
22
|
+
manufacturer: "Apple",
|
|
23
|
+
model: determineModel(),
|
|
24
|
+
name: UIDevice.current.name,
|
|
25
|
+
operatingSystem: "ios",
|
|
26
|
+
osVersion: UIDevice.current.systemVersion,
|
|
27
|
+
platform: "ios",
|
|
28
|
+
totalMemory: Int(ProcessInfo.processInfo.physicalMemory),
|
|
29
|
+
usedMemory: determineUsedMemory(),
|
|
30
|
+
webViewVersion: UIDevice.current.systemVersion
|
|
31
|
+
)
|
|
32
|
+
completion(result, nil)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@objc public func getUptime(completion: @escaping (GetUptimeResult?, Error?) -> Void) {
|
|
36
|
+
let uptime = Int(ProcessInfo.processInfo.systemUptime * 1000)
|
|
37
|
+
completion(GetUptimeResult(uptime: uptime), nil)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private func determineDeviceType() -> String {
|
|
41
|
+
switch UIDevice.current.userInterfaceIdiom {
|
|
42
|
+
case .phone:
|
|
43
|
+
return "phone"
|
|
44
|
+
case .pad:
|
|
45
|
+
return "tablet"
|
|
46
|
+
case .tv:
|
|
47
|
+
return "tv"
|
|
48
|
+
case .mac:
|
|
49
|
+
return "desktop"
|
|
50
|
+
default:
|
|
51
|
+
return "unknown"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private func determineIsVirtual() -> Bool {
|
|
56
|
+
#if targetEnvironment(simulator)
|
|
57
|
+
return true
|
|
58
|
+
#else
|
|
59
|
+
return false
|
|
60
|
+
#endif
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private func determineModel() -> String {
|
|
64
|
+
var systemInfo = utsname()
|
|
65
|
+
uname(&systemInfo)
|
|
66
|
+
let machineMirror = Mirror(reflecting: systemInfo.machine)
|
|
67
|
+
let identifier = machineMirror.children.reduce(into: "") { identifier, element in
|
|
68
|
+
guard let value = element.value as? Int8, value != 0 else {
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
identifier += String(UnicodeScalar(UInt8(value)))
|
|
72
|
+
}
|
|
73
|
+
return identifier.isEmpty ? UIDevice.current.model : identifier
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private func determineUsedMemory() -> Int? {
|
|
77
|
+
var info = task_vm_info_data_t()
|
|
78
|
+
var count = mach_msg_type_number_t(MemoryLayout<task_vm_info_data_t>.size) / 4
|
|
79
|
+
let result = withUnsafeMutablePointer(to: &info) { pointer in
|
|
80
|
+
pointer.withMemoryRebound(to: integer_t.self, capacity: Int(count)) { rebound in
|
|
81
|
+
task_info(mach_task_self_, task_flavor_t(TASK_VM_INFO), rebound, &count)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
guard result == KERN_SUCCESS else {
|
|
85
|
+
return nil
|
|
86
|
+
}
|
|
87
|
+
return Int(info.phys_footprint)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc(DeviceInfoPlugin)
|
|
5
|
+
public class DeviceInfoPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
+
public let identifier = "DeviceInfoPlugin"
|
|
7
|
+
public let jsName = "DeviceInfo"
|
|
8
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
9
|
+
CAPPluginMethod(name: "getId", returnType: CAPPluginReturnPromise),
|
|
10
|
+
CAPPluginMethod(name: "getInfo", returnType: CAPPluginReturnPromise),
|
|
11
|
+
CAPPluginMethod(name: "getUptime", returnType: CAPPluginReturnPromise)
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
public static let tag = "DeviceInfoPlugin"
|
|
15
|
+
|
|
16
|
+
private var implementation: DeviceInfo?
|
|
17
|
+
|
|
18
|
+
override public func load() {
|
|
19
|
+
self.implementation = DeviceInfo(plugin: self)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@objc func getId(_ call: CAPPluginCall) {
|
|
23
|
+
implementation?.getId { result, error in
|
|
24
|
+
if let error = error {
|
|
25
|
+
self.rejectCall(call, error)
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
self.resolveCall(call, result)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@objc func getInfo(_ call: CAPPluginCall) {
|
|
33
|
+
implementation?.getInfo { result, error in
|
|
34
|
+
if let error = error {
|
|
35
|
+
self.rejectCall(call, error)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
self.resolveCall(call, result)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@objc func getUptime(_ call: CAPPluginCall) {
|
|
43
|
+
implementation?.getUptime { result, error in
|
|
44
|
+
if let error = error {
|
|
45
|
+
self.rejectCall(call, error)
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
self.resolveCall(call, result)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private func rejectCall(_ call: CAPPluginCall, _ error: Error) {
|
|
53
|
+
CAPLog.print("[", DeviceInfoPlugin.tag, "] ", error)
|
|
54
|
+
call.reject(error.localizedDescription)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private func resolveCall(_ call: CAPPluginCall, _ result: Result?) {
|
|
58
|
+
if let result = result?.toJSObject() as? JSObject {
|
|
59
|
+
call.resolve(result)
|
|
60
|
+
} else {
|
|
61
|
+
call.resolve()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleExecutable</key>
|
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
+
<key>CFBundleIdentifier</key>
|
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
+
<string>6.0</string>
|
|
13
|
+
<key>CFBundleName</key>
|
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
|
15
|
+
<key>CFBundlePackageType</key>
|
|
16
|
+
<string>FMWK</string>
|
|
17
|
+
<key>CFBundleShortVersionString</key>
|
|
18
|
+
<string>1.0</string>
|
|
19
|
+
<key>CFBundleVersion</key>
|
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSPrincipalClass</key>
|
|
22
|
+
<string></string>
|
|
23
|
+
</dict>
|
|
24
|
+
</plist>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>NSPrivacyTracking</key>
|
|
6
|
+
<false/>
|
|
7
|
+
<key>NSPrivacyTrackingDomains</key>
|
|
8
|
+
<array/>
|
|
9
|
+
<key>NSPrivacyCollectedDataTypes</key>
|
|
10
|
+
<array/>
|
|
11
|
+
<key>NSPrivacyAccessedAPITypes</key>
|
|
12
|
+
<array>
|
|
13
|
+
<dict>
|
|
14
|
+
<key>NSPrivacyAccessedAPIType</key>
|
|
15
|
+
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
|
|
16
|
+
<key>NSPrivacyAccessedAPITypeReasons</key>
|
|
17
|
+
<array>
|
|
18
|
+
<string>35F9.1</string>
|
|
19
|
+
</array>
|
|
20
|
+
</dict>
|
|
21
|
+
</array>
|
|
22
|
+
</dict>
|
|
23
|
+
</plist>
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capawesome/capacitor-device-info",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Capacitor plugin to read device information.",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Plugin/",
|
|
14
|
+
"CapawesomeCapacitorDeviceInfo.podspec",
|
|
15
|
+
"Package.swift"
|
|
16
|
+
],
|
|
17
|
+
"author": "Robin Genz <mail@robingenz.dev>",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/capawesome-team/capacitor-plugins.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/capawesome-team/capacitor-plugins/issues"
|
|
25
|
+
},
|
|
26
|
+
"funding": [
|
|
27
|
+
{
|
|
28
|
+
"type": "github",
|
|
29
|
+
"url": "https://github.com/sponsors/capawesome-team/"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "opencollective",
|
|
33
|
+
"url": "https://opencollective.com/capawesome"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"homepage": "https://capawesome.io/docs/sdks/capacitor/device-info/",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"capacitor",
|
|
39
|
+
"plugin",
|
|
40
|
+
"native"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
44
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
|
45
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
46
|
+
"verify:web": "npm run build",
|
|
47
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
48
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
49
|
+
"eslint": "eslint . --ext ts",
|
|
50
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
51
|
+
"swiftlint": "node-swiftlint",
|
|
52
|
+
"docgen": "docgen --api DeviceInfoPlugin --output-readme README.md --output-json dist/docs.json",
|
|
53
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
54
|
+
"clean": "rimraf ./dist",
|
|
55
|
+
"watch": "tsc --watch",
|
|
56
|
+
"ios:pod:install": "cd ios && pod install --repo-update && cd ..",
|
|
57
|
+
"ios:spm:install": "cd ios && swift package resolve && cd ..",
|
|
58
|
+
"prepublishOnly": "npm run build"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@capacitor/android": "8.0.0",
|
|
62
|
+
"@capacitor/cli": "8.0.0",
|
|
63
|
+
"@capacitor/core": "8.0.0",
|
|
64
|
+
"@capacitor/docgen": "0.3.1",
|
|
65
|
+
"@capacitor/ios": "8.0.0",
|
|
66
|
+
"@ionic/eslint-config": "0.4.0",
|
|
67
|
+
"eslint": "8.57.0",
|
|
68
|
+
"prettier-plugin-java": "2.6.7",
|
|
69
|
+
"rimraf": "6.1.2",
|
|
70
|
+
"rollup": "4.53.3",
|
|
71
|
+
"swiftlint": "2.0.0",
|
|
72
|
+
"typescript": "5.9.3"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@capacitor/core": ">=8.0.0"
|
|
76
|
+
},
|
|
77
|
+
"eslintConfig": {
|
|
78
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
79
|
+
},
|
|
80
|
+
"capacitor": {
|
|
81
|
+
"ios": {
|
|
82
|
+
"src": "ios"
|
|
83
|
+
},
|
|
84
|
+
"android": {
|
|
85
|
+
"src": "android"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"publishConfig": {
|
|
89
|
+
"access": "public"
|
|
90
|
+
}
|
|
91
|
+
}
|