tauri-plugin-device-info-api 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Hatice Edis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,224 @@
1
+ # Tauri Plugin device-info
2
+
3
+ [![npm version](https://img.shields.io/npm/v/tauri-plugin-device-info-api.svg)](https://www.npmjs.com/package/tauri-plugin-device-info-api)
4
+ [![Crates.io](https://img.shields.io/crates/v/tauri-plugin-device-info.svg)](https://crates.io/crates/tauri-plugin-device-info)
5
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+
7
+ A comprehensive Tauri plugin to access device information including Battery, Network, Storage, Display, and System Details.
8
+
9
+ ---
10
+
11
+ **📖 [Read the Documentation](https://edisdev.github.io/tauri-plugin-device-info)**
12
+
13
+ ## 📸 Preview
14
+
15
+ <div>
16
+ <img src="./docs/public/DeviceInfo_Android_Gif.gif" alt="Android Preview GIF" width="250">
17
+ <br>
18
+ <img src="./docs/public/DeviceInfo_Mac.png" alt="macOS Preview" width="400">
19
+ <img src="./docs/public/DeviceInfo_Windows.png" alt="Windows Preview" width="400">
20
+ <br>
21
+ <img src="./docs/public/DeviceInfo_Android.png" alt="Android Preview" width="250">
22
+ <img src="./docs/public/DeviceInfo_iOS.png" alt="iOS Preview" width="250">
23
+ <p><i>Example Dashboard Application across platforms</i></p>
24
+ </div>
25
+
26
+ ## Platform Support
27
+
28
+ | Platform | Support |
29
+ |----------|---------|
30
+ | Windows | ✅ |
31
+ | macOS | ✅ |
32
+ | Linux | ✅ |
33
+ | iOS | ✅ |
34
+ | Android | ✅ |
35
+
36
+ ## Installation
37
+
38
+ ### Using Tauri CLI (Recommended)
39
+
40
+ ```bash
41
+ npm run tauri add device-info
42
+ # or
43
+ yarn tauri add device-info
44
+ ```
45
+
46
+ ### Manual Installation
47
+
48
+ **Cargo.toml:**
49
+ ```toml
50
+ [dependencies]
51
+ tauri-plugin-device-info = "0.1.0"
52
+ # or from git
53
+ tauri-plugin-device-info = { git = "https://github.com/edisdev/tauri-plugin-device-info" }
54
+ ```
55
+
56
+ **package.json:**
57
+ ```json
58
+ {
59
+ "dependencies": {
60
+ "tauri-plugin-device-info-api": "latest"
61
+ }
62
+ }
63
+ ```
64
+
65
+ ## Setup
66
+
67
+ Register the plugin in your Tauri app:
68
+
69
+ **src-tauri/src/lib.rs:**
70
+ ```rust
71
+ fn main() {
72
+ tauri::Builder::default()
73
+ .plugin(tauri_plugin_device_info::init())
74
+ .run(tauri::generate_context!())
75
+ .expect("error while running tauri application");
76
+ }
77
+ ```
78
+
79
+ ## Usage
80
+
81
+ ```typescript
82
+ import {
83
+ getDeviceInfo,
84
+ getBatteryInfo,
85
+ getNetworkInfo,
86
+ getStorageInfo,
87
+ getDisplayInfo
88
+ } from 'tauri-plugin-device-info-api';
89
+
90
+ // Get device information
91
+ const device = await getDeviceInfo();
92
+ console.log(device);
93
+
94
+ // Get battery status
95
+ const battery = await getBatteryInfo();
96
+ console.log(battery);
97
+
98
+ // Get network information
99
+ const network = await getNetworkInfo();
100
+ console.log(network);
101
+
102
+ // Get storage information
103
+ const storage = await getStorageInfo();
104
+ console.log(storage);
105
+
106
+ // Get display information
107
+ const display = await getDisplayInfo();
108
+ console.log(display);
109
+ ```
110
+
111
+ ## API Reference
112
+
113
+ ### getDeviceInfo()
114
+
115
+ Returns device identification and hardware information.
116
+
117
+ | Field | Type | Description |
118
+ |-------|------|-------------|
119
+ | `uuid` | `string?` | Unique device identifier |
120
+ | `manufacturer` | `string?` | Device manufacturer (e.g., "Apple Inc.") |
121
+ | `model` | `string?` | Device model (e.g., "MacBookPro16,1") |
122
+ | `serial` | `string?` | Serial number (restricted on some platforms) |
123
+ | `android_id` | `string?` | Android-specific ID (Android only) |
124
+ | `device_name` | `string?` | User-assigned device name |
125
+
126
+ ### getBatteryInfo()
127
+
128
+ Returns battery status and health information.
129
+
130
+ | Field | Type | Description |
131
+ |-------|------|-------------|
132
+ | `level` | `number?` | Battery percentage (0-100) |
133
+ | `isCharging` | `boolean?` | Whether the device is charging |
134
+ | `health` | `string?` | Battery health status |
135
+
136
+ ### getNetworkInfo()
137
+
138
+ Returns network connection details.
139
+
140
+ | Field | Type | Description |
141
+ |-------|------|-------------|
142
+ | `ipAddress` | `string?` | Local IP address |
143
+ | `networkType` | `string?` | Connection type: "wifi", "cellular", "ethernet", "unknown" |
144
+ | `macAddress` | `string?` | MAC address (unavailable on iOS/Android due to privacy) |
145
+
146
+ ### getStorageInfo()
147
+
148
+ Returns storage capacity information.
149
+
150
+ | Field | Type | Description |
151
+ |-------|------|-------------|
152
+ | `totalSpace` | `number?` | Total storage in bytes |
153
+ | `freeSpace` | `number?` | Available storage in bytes |
154
+ | `storageType` | `string?` | Storage type: "SSD", "HDD", "internal" |
155
+
156
+ ### getDisplayInfo()
157
+
158
+ Returns display/screen information.
159
+
160
+ | Field | Type | Description |
161
+ |-------|------|-------------|
162
+ | `width` | `number?` | Screen width in pixels |
163
+ | `height` | `number?` | Screen height in pixels |
164
+ | `scaleFactor` | `number?` | Display scale factor (e.g., 2.0 for Retina) |
165
+ | `refreshRate` | `number?` | Screen refresh rate in Hz |
166
+
167
+ ## TypeScript Types
168
+
169
+ All types are exported and can be imported:
170
+
171
+ ```typescript
172
+ import type {
173
+ DeviceInfoResponse,
174
+ BatteryInfo,
175
+ NetworkInfo,
176
+ StorageInfo,
177
+ DisplayInfo
178
+ } from 'tauri-plugin-device-info-api';
179
+ ```
180
+
181
+ ## Permissions
182
+
183
+ Add the required permissions in your `capabilities` configuration:
184
+
185
+ ```json
186
+ {
187
+ "permissions": [
188
+ "device-info:default"
189
+ ]
190
+ }
191
+ ```
192
+
193
+ Or individually:
194
+ - `device-info:allow-get-device-info`
195
+ - `device-info:allow-get-battery-info`
196
+ - `device-info:allow-get-network-info`
197
+ - `device-info:allow-get-storage-info`
198
+ - `device-info:allow-get-display-info`
199
+
200
+ ## Platform-Specific Notes
201
+
202
+ ### iOS
203
+ - MAC address is not available due to Apple's privacy restrictions (returns "unavailable")
204
+ - Serial number uses a persistent Keychain-stored UUID
205
+
206
+ ### Android
207
+ - MAC address is restricted on Android 6.0+ (returns "restricted")
208
+ - Requires no special permissions for basic device info
209
+
210
+ ### macOS
211
+ - Uses native CoreGraphics API for accurate refresh rate detection
212
+ - Full access to all device information
213
+
214
+ ### Windows
215
+ - Uses WMI (Windows Management Instrumentation) for device info
216
+ - Full access to all device information
217
+
218
+ ### Linux
219
+ - Display refresh rate requires X11 (xrandr)
220
+ - Device info read from `/sys/class/dmi/id/`
221
+
222
+ ## License
223
+
224
+ MIT
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ var core = require('@tauri-apps/api/core');
4
+
5
+ /**
6
+ * Get comprehensive device information including UUID, manufacturer, model, etc.
7
+ */
8
+ async function getDeviceInfo() {
9
+ return await core.invoke('plugin:device-info|get_device_info');
10
+ }
11
+ /**
12
+ * Get battery status including level, charging state, and health.
13
+ */
14
+ async function getBatteryInfo() {
15
+ return await core.invoke('plugin:device-info|get_battery_info');
16
+ }
17
+ /**
18
+ * Get network information including IP address, network type, and MAC address.
19
+ */
20
+ async function getNetworkInfo() {
21
+ return await core.invoke('plugin:device-info|get_network_info');
22
+ }
23
+ /**
24
+ * Get storage information including total space, free space, and storage type.
25
+ */
26
+ async function getStorageInfo() {
27
+ return await core.invoke('plugin:device-info|get_storage_info');
28
+ }
29
+ /**
30
+ * Get display information including resolution, scale factor, and refresh rate.
31
+ */
32
+ async function getDisplayInfo() {
33
+ return await core.invoke('plugin:device-info|get_display_info');
34
+ }
35
+
36
+ exports.getBatteryInfo = getBatteryInfo;
37
+ exports.getDeviceInfo = getDeviceInfo;
38
+ exports.getDisplayInfo = getDisplayInfo;
39
+ exports.getNetworkInfo = getNetworkInfo;
40
+ exports.getStorageInfo = getStorageInfo;
@@ -0,0 +1,22 @@
1
+ import type { DeviceInfoResponse, BatteryInfo, NetworkInfo, StorageInfo, DisplayInfo } from './type';
2
+ export type { DeviceInfoResponse, DeviceInfoResponse as DeviceInfo, BatteryInfo, NetworkInfo, StorageInfo, DisplayInfo } from './type';
3
+ /**
4
+ * Get comprehensive device information including UUID, manufacturer, model, etc.
5
+ */
6
+ export declare function getDeviceInfo(): Promise<DeviceInfoResponse>;
7
+ /**
8
+ * Get battery status including level, charging state, and health.
9
+ */
10
+ export declare function getBatteryInfo(): Promise<BatteryInfo>;
11
+ /**
12
+ * Get network information including IP address, network type, and MAC address.
13
+ */
14
+ export declare function getNetworkInfo(): Promise<NetworkInfo>;
15
+ /**
16
+ * Get storage information including total space, free space, and storage type.
17
+ */
18
+ export declare function getStorageInfo(): Promise<StorageInfo>;
19
+ /**
20
+ * Get display information including resolution, scale factor, and refresh rate.
21
+ */
22
+ export declare function getDisplayInfo(): Promise<DisplayInfo>;
@@ -0,0 +1,34 @@
1
+ import { invoke } from '@tauri-apps/api/core';
2
+
3
+ /**
4
+ * Get comprehensive device information including UUID, manufacturer, model, etc.
5
+ */
6
+ async function getDeviceInfo() {
7
+ return await invoke('plugin:device-info|get_device_info');
8
+ }
9
+ /**
10
+ * Get battery status including level, charging state, and health.
11
+ */
12
+ async function getBatteryInfo() {
13
+ return await invoke('plugin:device-info|get_battery_info');
14
+ }
15
+ /**
16
+ * Get network information including IP address, network type, and MAC address.
17
+ */
18
+ async function getNetworkInfo() {
19
+ return await invoke('plugin:device-info|get_network_info');
20
+ }
21
+ /**
22
+ * Get storage information including total space, free space, and storage type.
23
+ */
24
+ async function getStorageInfo() {
25
+ return await invoke('plugin:device-info|get_storage_info');
26
+ }
27
+ /**
28
+ * Get display information including resolution, scale factor, and refresh rate.
29
+ */
30
+ async function getDisplayInfo() {
31
+ return await invoke('plugin:device-info|get_display_info');
32
+ }
33
+
34
+ export { getBatteryInfo, getDeviceInfo, getDisplayInfo, getNetworkInfo, getStorageInfo };
@@ -0,0 +1,29 @@
1
+ export interface DeviceInfoResponse {
2
+ uuid?: string;
3
+ manufacturer?: string;
4
+ model?: string;
5
+ serial?: string;
6
+ android_id?: string;
7
+ device_name?: string;
8
+ }
9
+ export interface BatteryInfo {
10
+ level?: number;
11
+ isCharging?: boolean;
12
+ health?: string;
13
+ }
14
+ export interface NetworkInfo {
15
+ ipAddress?: string;
16
+ networkType?: string;
17
+ macAddress?: string;
18
+ }
19
+ export interface StorageInfo {
20
+ totalSpace?: number;
21
+ freeSpace?: number;
22
+ storageType?: string;
23
+ }
24
+ export interface DisplayInfo {
25
+ width?: number;
26
+ height?: number;
27
+ scaleFactor?: number;
28
+ refreshRate?: number;
29
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "recommendations": [
3
+ "svelte.svelte-vscode",
4
+ "tauri-apps.tauri-vscode",
5
+ "rust-lang.rust-analyzer"
6
+ ]
7
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "tauri-plugin-device-info-api",
3
+ "version": "1.0.0",
4
+ "author": "edisdev<edisdev14@gmail.com>",
5
+ "description": "A Tauri plugin to access device information.",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/edisdev/tauri-plugin-device-info.git"
10
+ },
11
+ "keywords": [
12
+ "tauri",
13
+ "plugin",
14
+ "device-info",
15
+ "system",
16
+ "mobile",
17
+ "desktop"
18
+ ],
19
+ "bugs": {
20
+ "url": "https://github.com/edisdev/tauri-plugin-device-info/issues"
21
+ },
22
+ "homepage": "https://edisdev.github.io/tauri-plugin-device-info",
23
+ "type": "module",
24
+ "types": "./dist-js/index.d.ts",
25
+ "main": "./dist-js/index.cjs",
26
+ "module": "./dist-js/index.js",
27
+ "exports": {
28
+ "types": "./dist-js/index.d.ts",
29
+ "import": "./dist-js/index.js",
30
+ "require": "./dist-js/index.cjs"
31
+ },
32
+ "files": [
33
+ "dist-js",
34
+ "README.md"
35
+ ],
36
+ "scripts": {
37
+ "build": "rollup -c",
38
+ "prepublishOnly": "yarn build",
39
+ "pretest": "yarn build"
40
+ },
41
+ "dependencies": {
42
+ "@tauri-apps/api": "^2.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@rollup/plugin-typescript": "^12.0.0",
46
+ "rollup": "^4.9.6",
47
+ "typescript": "^5.3.3",
48
+ "tslib": "^2.6.2"
49
+ }
50
+ }