tauri-plugin-device-info-api 1.0.0 → 1.1.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/CHANGELOG.md +69 -0
- package/README.md +264 -53
- package/dist-js/index.cjs +48 -0
- package/dist-js/index.d.ts +12 -2
- package/dist-js/index.js +44 -1
- package/dist-js/type.d.ts +18 -0
- package/package.json +28 -9
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.1.0] - 2026-08-24
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Reactive Watch API** — subscribe to a kind of device information and receive
|
|
13
|
+
a callback whenever the value changes, instead of polling a getter yourself.
|
|
14
|
+
The current value is delivered immediately, then on every change.
|
|
15
|
+
- `watchBattery`, `watchNetwork`, `watchStorage`, `watchDisplay`, and
|
|
16
|
+
`watchDevice`, each returning a `Promise<UnwatchFn>`.
|
|
17
|
+
- `WatchOptions` (`intervalMs`) and `UnwatchFn` types, exported for consumers.
|
|
18
|
+
- `start_watching` / `stop_watching` commands, with matching
|
|
19
|
+
`allow-start-watching` and `allow-stop-watching` permissions (included in
|
|
20
|
+
`device-info:default`).
|
|
21
|
+
- **Native, event-driven monitors on macOS** — battery via IOKit power
|
|
22
|
+
notifications, display via Core Graphics reconfiguration callbacks, and
|
|
23
|
+
network via SystemConfiguration reachability. The CPU stays idle between
|
|
24
|
+
changes and updates arrive the instant the OS reports them.
|
|
25
|
+
- **Change-detecting polling fallback** for kinds/platforms without a native
|
|
26
|
+
event source (`storage` and `device` everywhere; all kinds off macOS). Events
|
|
27
|
+
are emitted only when the value actually changes.
|
|
28
|
+
- Reference-counted monitors: subscribers to the same kind share a single
|
|
29
|
+
monitor that starts on the first subscriber and is torn down on the last.
|
|
30
|
+
- Documentation for the watch API (API reference page, guide section, examples)
|
|
31
|
+
and unit tests covering the monitor lifecycle for every kind.
|
|
32
|
+
|
|
33
|
+
### Performance
|
|
34
|
+
|
|
35
|
+
- Per-kind polling defaults and floors so expensive getters are not polled
|
|
36
|
+
aggressively: `device` defaults to 60000 ms (min 10000 ms), `storage` to
|
|
37
|
+
10000 ms (min 1000 ms), others to 2000 ms (min 250 ms). Notably, `device`
|
|
38
|
+
(which shells out to `system_profiler` on macOS and rarely changes) is no
|
|
39
|
+
longer read every couple of seconds.
|
|
40
|
+
- The poller now sleeps for the full interval on a condition variable and wakes
|
|
41
|
+
immediately on stop, instead of busy-waking every 100 ms — letting the CPU
|
|
42
|
+
idle and cooperating with power-saving.
|
|
43
|
+
- Change events are emitted by reference, avoiding a deep clone of each snapshot.
|
|
44
|
+
|
|
45
|
+
### Fixed
|
|
46
|
+
|
|
47
|
+
- Removed a run-loop teardown race on macOS that could hang `stop_watching`
|
|
48
|
+
indefinitely when a watcher was stopped just after starting; stop is now
|
|
49
|
+
signalled through the run loop itself and is race-free.
|
|
50
|
+
- `stop_watching` no longer holds the shared watcher lock while tearing down a
|
|
51
|
+
monitor, so a slow teardown can't block subscribe/unsubscribe for other kinds.
|
|
52
|
+
- Contained panics inside the macOS OS callbacks so they can no longer unwind
|
|
53
|
+
across the C ABI boundary and abort the process.
|
|
54
|
+
- The example app surfaces watcher start failures instead of leaving an
|
|
55
|
+
unhandled promise rejection.
|
|
56
|
+
|
|
57
|
+
## [1.0.1]
|
|
58
|
+
|
|
59
|
+
- Documentation updates, crates.io metadata, and a Tests CI badge.
|
|
60
|
+
|
|
61
|
+
## [1.0.0]
|
|
62
|
+
|
|
63
|
+
- Initial release: `getDeviceInfo`, `getBatteryInfo`, `getNetworkInfo`,
|
|
64
|
+
`getStorageInfo`, and `getDisplayInfo` across Windows, macOS, Linux, iOS, and
|
|
65
|
+
Android.
|
|
66
|
+
|
|
67
|
+
[1.1.0]: https://github.com/edisdev/tauri-plugin-device-info/releases/tag/v1.1.0
|
|
68
|
+
[1.0.1]: https://github.com/edisdev/tauri-plugin-device-info/releases/tag/v1.0.1
|
|
69
|
+
[1.0.0]: https://github.com/edisdev/tauri-plugin-device-info/releases/tag/v1.0.0
|
package/README.md
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
1
|
# Tauri Plugin device-info
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/tauri-plugin-device-info-api)
|
|
4
|
+
[](https://www.npmjs.com/package/tauri-plugin-device-info-api)
|
|
4
5
|
[](https://crates.io/crates/tauri-plugin-device-info)
|
|
6
|
+
[](https://crates.io/crates/tauri-plugin-device-info)
|
|
7
|
+
[](https://github.com/edisdev/tauri-plugin-device-info)
|
|
8
|
+
[](https://github.com/edisdev/tauri-plugin-device-info/fork)
|
|
5
9
|
[](LICENSE)
|
|
10
|
+
[](https://tauri.app)
|
|
11
|
+
[](https://github.com/edisdev/tauri-plugin-device-info/actions/workflows/build.yml)
|
|
12
|
+
[](https://github.com/edisdev/tauri-plugin-device-info/actions/workflows/test.yml)
|
|
6
13
|
|
|
7
14
|
A comprehensive Tauri plugin to access device information including Battery, Network, Storage, Display, and System Details.
|
|
8
15
|
|
|
16
|
+
> **One plugin, five data sources, five platforms.** Get battery, network, storage, display, and device identity through a single typed API — on Windows, macOS, Linux, iOS, and Android.
|
|
17
|
+
|
|
9
18
|
---
|
|
10
19
|
|
|
11
20
|
**📖 [Read the Documentation](https://edisdev.github.io/tauri-plugin-device-info)**
|
|
12
21
|
|
|
22
|
+
## ✨ Features
|
|
23
|
+
|
|
24
|
+
- 🔋 **Battery** — charge level, charging state, and health
|
|
25
|
+
- 🌐 **Network** — local IP, connection type, and MAC address
|
|
26
|
+
- 💾 **Storage** — total/free space and storage type
|
|
27
|
+
- 🖥️ **Display** — resolution, scale factor, and refresh rate
|
|
28
|
+
- 🆔 **Device** — manufacturer, model, serial, and device name
|
|
29
|
+
- 🔔 **Reactive** — `watch*` APIs push updates on change (native event-driven on macOS, polling fallback elsewhere)
|
|
30
|
+
- 📱 **Truly cross-platform** — Windows, macOS, Linux, iOS, and Android
|
|
31
|
+
- 🛡️ **Type-safe** — full TypeScript types and granular Tauri permissions
|
|
32
|
+
- ✅ **Tested** — unit-tested core with CI across all desktop platforms
|
|
33
|
+
|
|
13
34
|
## 📸 Preview
|
|
14
35
|
|
|
15
36
|
<div>
|
|
@@ -26,7 +47,7 @@ A comprehensive Tauri plugin to access device information including Battery, Net
|
|
|
26
47
|
## Platform Support
|
|
27
48
|
|
|
28
49
|
| Platform | Support |
|
|
29
|
-
|
|
50
|
+
| -------- | ------- |
|
|
30
51
|
| Windows | ✅ |
|
|
31
52
|
| macOS | ✅ |
|
|
32
53
|
| Linux | ✅ |
|
|
@@ -45,19 +66,21 @@ yarn tauri add device-info
|
|
|
45
66
|
|
|
46
67
|
### Manual Installation
|
|
47
68
|
|
|
48
|
-
**Cargo.toml:**
|
|
69
|
+
**Cargo.toml:** [](https://crates.io/crates/tauri-plugin-device-info)
|
|
70
|
+
|
|
49
71
|
```toml
|
|
50
72
|
[dependencies]
|
|
51
|
-
tauri-plugin-device-info = "
|
|
73
|
+
tauri-plugin-device-info = "1.0" # Check crates.io for latest version
|
|
52
74
|
# or from git
|
|
53
75
|
tauri-plugin-device-info = { git = "https://github.com/edisdev/tauri-plugin-device-info" }
|
|
54
76
|
```
|
|
55
77
|
|
|
56
|
-
**package.json:**
|
|
78
|
+
**package.json:** [](https://www.npmjs.com/package/tauri-plugin-device-info-api)
|
|
79
|
+
|
|
57
80
|
```json
|
|
58
81
|
{
|
|
59
82
|
"dependencies": {
|
|
60
|
-
"tauri-plugin-device-info-api": "
|
|
83
|
+
"tauri-plugin-device-info-api": "^1.0.0"
|
|
61
84
|
}
|
|
62
85
|
}
|
|
63
86
|
```
|
|
@@ -67,6 +90,7 @@ tauri-plugin-device-info = { git = "https://github.com/edisdev/tauri-plugin-devi
|
|
|
67
90
|
Register the plugin in your Tauri app:
|
|
68
91
|
|
|
69
92
|
**src-tauri/src/lib.rs:**
|
|
93
|
+
|
|
70
94
|
```rust
|
|
71
95
|
fn main() {
|
|
72
96
|
tauri::Builder::default()
|
|
@@ -79,146 +103,333 @@ fn main() {
|
|
|
79
103
|
## Usage
|
|
80
104
|
|
|
81
105
|
```typescript
|
|
82
|
-
import {
|
|
83
|
-
getDeviceInfo,
|
|
84
|
-
getBatteryInfo,
|
|
85
|
-
getNetworkInfo,
|
|
86
|
-
getStorageInfo,
|
|
87
|
-
getDisplayInfo
|
|
88
|
-
} from
|
|
106
|
+
import {
|
|
107
|
+
getDeviceInfo,
|
|
108
|
+
getBatteryInfo,
|
|
109
|
+
getNetworkInfo,
|
|
110
|
+
getStorageInfo,
|
|
111
|
+
getDisplayInfo,
|
|
112
|
+
} from "tauri-plugin-device-info-api";
|
|
89
113
|
|
|
90
114
|
// Get device information
|
|
91
115
|
const device = await getDeviceInfo();
|
|
92
116
|
console.log(device);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Response:**
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"uuid": "550e8400-e29b-41d4-a716-446655440000",
|
|
124
|
+
"manufacturer": "Apple Inc.",
|
|
125
|
+
"model": "MacBookPro16,1",
|
|
126
|
+
"serial": "C02XG2JHJG5H",
|
|
127
|
+
"android_id": null,
|
|
128
|
+
"device_name": "John's MacBook Pro"
|
|
129
|
+
}
|
|
130
|
+
```
|
|
93
131
|
|
|
132
|
+
```typescript
|
|
94
133
|
// Get battery status
|
|
95
134
|
const battery = await getBatteryInfo();
|
|
96
135
|
console.log(battery);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**Response:**
|
|
97
139
|
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"level": 85,
|
|
143
|
+
"isCharging": true,
|
|
144
|
+
"health": "Good"
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
98
149
|
// Get network information
|
|
99
150
|
const network = await getNetworkInfo();
|
|
100
151
|
console.log(network);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Response:**
|
|
101
155
|
|
|
156
|
+
```json
|
|
157
|
+
{
|
|
158
|
+
"ipAddress": "192.168.x.x",
|
|
159
|
+
"networkType": "wifi",
|
|
160
|
+
"macAddress": "a1:b2:c3:d4:e5:f6"
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
102
165
|
// Get storage information
|
|
103
166
|
const storage = await getStorageInfo();
|
|
104
167
|
console.log(storage);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Response:**
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"totalSpace": 500107862016,
|
|
175
|
+
"freeSpace": 125026965504,
|
|
176
|
+
"storageType": "SSD"
|
|
177
|
+
}
|
|
178
|
+
```
|
|
105
179
|
|
|
180
|
+
```typescript
|
|
106
181
|
// Get display information
|
|
107
182
|
const display = await getDisplayInfo();
|
|
108
183
|
console.log(display);
|
|
109
184
|
```
|
|
110
185
|
|
|
186
|
+
**Response:**
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"width": 2560,
|
|
191
|
+
"height": 1600,
|
|
192
|
+
"scaleFactor": 2.0,
|
|
193
|
+
"refreshRate": 120
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Reactive Watch API
|
|
198
|
+
|
|
199
|
+
Subscribe to a kind and get a callback whenever the value changes, instead of
|
|
200
|
+
polling a getter yourself. The current value is delivered immediately, then on
|
|
201
|
+
every change. On macOS these are native and event-driven (IOKit / Core Graphics
|
|
202
|
+
/ SystemConfiguration); elsewhere they fall back to change-detecting polling.
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import {
|
|
206
|
+
watchBattery,
|
|
207
|
+
watchNetwork,
|
|
208
|
+
watchStorage,
|
|
209
|
+
watchDisplay,
|
|
210
|
+
watchDevice,
|
|
211
|
+
} from "tauri-plugin-device-info-api";
|
|
212
|
+
import type { UnwatchFn } from "tauri-plugin-device-info-api";
|
|
213
|
+
|
|
214
|
+
// Called immediately with the current value, then on every change.
|
|
215
|
+
const unwatch = await watchBattery((battery) => {
|
|
216
|
+
console.log(`Battery: ${battery.level}% (charging: ${battery.isCharging})`);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// Stop watching and remove the listener when you're done.
|
|
220
|
+
await unwatch();
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Cleaning up several watchers at once (e.g. on component teardown):
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
const unwatchers: UnwatchFn[] = [];
|
|
227
|
+
unwatchers.push(await watchNetwork((info) => console.log(info.networkType)));
|
|
228
|
+
unwatchers.push(await watchDisplay((info) => console.log(info.width, info.height)));
|
|
229
|
+
|
|
230
|
+
// Later:
|
|
231
|
+
await Promise.all(unwatchers.map((unwatch) => unwatch()));
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
`watch*` accepts an optional `{ intervalMs }` that applies **only to polled
|
|
235
|
+
kinds** (native kinds ignore it). Defaults and minimums are per kind: `device`
|
|
236
|
+
defaults to 60000 ms (floored at 10000 ms), `storage` to 10000 ms (floored at
|
|
237
|
+
1000 ms), and others to 2000 ms (floored at 250 ms). Subscribers to the same
|
|
238
|
+
kind share one monitor, so only the first subscriber's interval takes effect.
|
|
239
|
+
|
|
111
240
|
## API Reference
|
|
112
241
|
|
|
113
242
|
### getDeviceInfo()
|
|
114
243
|
|
|
115
244
|
Returns device identification and hardware information.
|
|
116
245
|
|
|
117
|
-
| Field
|
|
118
|
-
|
|
119
|
-
| `uuid`
|
|
120
|
-
| `manufacturer` | `string?` | Device manufacturer (e.g., "Apple Inc.")
|
|
121
|
-
| `model`
|
|
122
|
-
| `serial`
|
|
123
|
-
| `android_id`
|
|
124
|
-
| `device_name`
|
|
246
|
+
| Field | Type | Description |
|
|
247
|
+
| -------------- | --------- | -------------------------------------------- |
|
|
248
|
+
| `uuid` | `string?` | Unique device identifier |
|
|
249
|
+
| `manufacturer` | `string?` | Device manufacturer (e.g., "Apple Inc.") |
|
|
250
|
+
| `model` | `string?` | Device model (e.g., "MacBookPro16,1") |
|
|
251
|
+
| `serial` | `string?` | Serial number (restricted on some platforms) |
|
|
252
|
+
| `android_id` | `string?` | Android-specific ID (Android only) |
|
|
253
|
+
| `device_name` | `string?` | User-assigned device name |
|
|
125
254
|
|
|
126
255
|
### getBatteryInfo()
|
|
127
256
|
|
|
128
257
|
Returns battery status and health information.
|
|
129
258
|
|
|
130
|
-
| Field
|
|
131
|
-
|
|
132
|
-
| `level`
|
|
259
|
+
| Field | Type | Description |
|
|
260
|
+
| ------------ | ---------- | ------------------------------ |
|
|
261
|
+
| `level` | `number?` | Battery percentage (0-100) |
|
|
133
262
|
| `isCharging` | `boolean?` | Whether the device is charging |
|
|
134
|
-
| `health`
|
|
263
|
+
| `health` | `string?` | Battery health status |
|
|
135
264
|
|
|
136
265
|
### getNetworkInfo()
|
|
137
266
|
|
|
138
267
|
Returns network connection details.
|
|
139
268
|
|
|
140
|
-
| Field
|
|
141
|
-
|
|
142
|
-
| `ipAddress`
|
|
269
|
+
| Field | Type | Description |
|
|
270
|
+
| ------------- | --------- | ---------------------------------------------------------- |
|
|
271
|
+
| `ipAddress` | `string?` | Local IP address |
|
|
143
272
|
| `networkType` | `string?` | Connection type: "wifi", "cellular", "ethernet", "unknown" |
|
|
144
|
-
| `macAddress`
|
|
273
|
+
| `macAddress` | `string?` | MAC address (unavailable on iOS/Android due to privacy) |
|
|
145
274
|
|
|
146
275
|
### getStorageInfo()
|
|
147
276
|
|
|
148
277
|
Returns storage capacity information.
|
|
149
278
|
|
|
150
|
-
| Field
|
|
151
|
-
|
|
152
|
-
| `totalSpace`
|
|
153
|
-
| `freeSpace`
|
|
279
|
+
| Field | Type | Description |
|
|
280
|
+
| ------------- | --------- | -------------------------------------- |
|
|
281
|
+
| `totalSpace` | `number?` | Total storage in bytes |
|
|
282
|
+
| `freeSpace` | `number?` | Available storage in bytes |
|
|
154
283
|
| `storageType` | `string?` | Storage type: "SSD", "HDD", "internal" |
|
|
155
284
|
|
|
156
285
|
### getDisplayInfo()
|
|
157
286
|
|
|
158
287
|
Returns display/screen information.
|
|
159
288
|
|
|
160
|
-
| Field
|
|
161
|
-
|
|
162
|
-
| `width`
|
|
163
|
-
| `height`
|
|
289
|
+
| Field | Type | Description |
|
|
290
|
+
| ------------- | --------- | ------------------------------------------- |
|
|
291
|
+
| `width` | `number?` | Screen width in pixels |
|
|
292
|
+
| `height` | `number?` | Screen height in pixels |
|
|
164
293
|
| `scaleFactor` | `number?` | Display scale factor (e.g., 2.0 for Retina) |
|
|
165
|
-
| `refreshRate` | `number?` | Screen refresh rate in Hz
|
|
294
|
+
| `refreshRate` | `number?` | Screen refresh rate in Hz |
|
|
295
|
+
|
|
296
|
+
### watch\*(callback, options?)
|
|
297
|
+
|
|
298
|
+
Subscribes to a kind and invokes `callback` with the current value immediately,
|
|
299
|
+
then on every change. Returns a `Promise<UnwatchFn>`; call the returned function
|
|
300
|
+
to stop watching and remove the listener.
|
|
301
|
+
|
|
302
|
+
| Function | Callback payload |
|
|
303
|
+
| ----------------- | -------------------- |
|
|
304
|
+
| `watchDevice()` | `DeviceInfoResponse` |
|
|
305
|
+
| `watchBattery()` | `BatteryInfo` |
|
|
306
|
+
| `watchNetwork()` | `NetworkInfo` |
|
|
307
|
+
| `watchStorage()` | `StorageInfo` |
|
|
308
|
+
| `watchDisplay()` | `DisplayInfo` |
|
|
309
|
+
|
|
310
|
+
**Options**
|
|
311
|
+
|
|
312
|
+
| Field | Type | Description |
|
|
313
|
+
| ------------ | --------- | -------------------------------------------------------------------------------------------- |
|
|
314
|
+
| `intervalMs` | `number?` | Polling interval for polled kinds only (native kinds ignore it). Per-kind defaults/minimums. |
|
|
166
315
|
|
|
167
316
|
## TypeScript Types
|
|
168
317
|
|
|
169
318
|
All types are exported and can be imported:
|
|
170
319
|
|
|
171
320
|
```typescript
|
|
172
|
-
import type {
|
|
173
|
-
DeviceInfoResponse,
|
|
174
|
-
BatteryInfo,
|
|
175
|
-
NetworkInfo,
|
|
176
|
-
StorageInfo,
|
|
177
|
-
DisplayInfo
|
|
178
|
-
|
|
321
|
+
import type {
|
|
322
|
+
DeviceInfoResponse,
|
|
323
|
+
BatteryInfo,
|
|
324
|
+
NetworkInfo,
|
|
325
|
+
StorageInfo,
|
|
326
|
+
DisplayInfo,
|
|
327
|
+
WatchOptions,
|
|
328
|
+
UnwatchFn,
|
|
329
|
+
} from "tauri-plugin-device-info-api";
|
|
179
330
|
```
|
|
180
331
|
|
|
181
332
|
## Permissions
|
|
182
333
|
|
|
183
|
-
Add the required permissions in your `capabilities` configuration
|
|
334
|
+
Add the required permissions in your `capabilities` configuration.
|
|
335
|
+
|
|
336
|
+
**src-tauri/capabilities/default.json:**
|
|
337
|
+
|
|
338
|
+
```json
|
|
339
|
+
{
|
|
340
|
+
"$schema": "../gen/schemas/desktop-schema.json",
|
|
341
|
+
"identifier": "default",
|
|
342
|
+
"description": "Capability for the main window",
|
|
343
|
+
"windows": ["main"],
|
|
344
|
+
"permissions": ["core:default", "device-info:default"]
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Available Permissions
|
|
349
|
+
|
|
350
|
+
| Permission | Description |
|
|
351
|
+
| ------------------------------------ | --------------------------------- |
|
|
352
|
+
| `device-info:default` | Enables all device-info commands |
|
|
353
|
+
| `device-info:allow-get-device-info` | Allows getting device information |
|
|
354
|
+
| `device-info:allow-get-battery-info` | Allows getting battery status |
|
|
355
|
+
| `device-info:allow-get-network-info` | Allows getting network details |
|
|
356
|
+
| `device-info:allow-get-storage-info` | Allows getting storage info |
|
|
357
|
+
| `device-info:allow-get-display-info` | Allows getting display info |
|
|
358
|
+
| `device-info:allow-start-watching` | Allows starting a reactive watch |
|
|
359
|
+
| `device-info:allow-stop-watching` | Allows stopping a reactive watch |
|
|
360
|
+
|
|
361
|
+
### Individual Permissions Example
|
|
362
|
+
|
|
363
|
+
If you want to grant only specific permissions:
|
|
184
364
|
|
|
185
365
|
```json
|
|
186
366
|
{
|
|
367
|
+
"$schema": "../gen/schemas/desktop-schema.json",
|
|
368
|
+
"identifier": "default",
|
|
369
|
+
"description": "Capability for the main window",
|
|
370
|
+
"windows": ["main"],
|
|
187
371
|
"permissions": [
|
|
188
|
-
"
|
|
372
|
+
"core:default",
|
|
373
|
+
"device-info:allow-get-battery-info",
|
|
374
|
+
"device-info:allow-get-network-info"
|
|
189
375
|
]
|
|
190
376
|
}
|
|
191
377
|
```
|
|
192
378
|
|
|
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
379
|
## Platform-Specific Notes
|
|
201
380
|
|
|
202
381
|
### iOS
|
|
382
|
+
|
|
203
383
|
- MAC address is not available due to Apple's privacy restrictions (returns "unavailable")
|
|
204
384
|
- Serial number uses a persistent Keychain-stored UUID
|
|
205
385
|
|
|
206
386
|
### Android
|
|
387
|
+
|
|
207
388
|
- MAC address is restricted on Android 6.0+ (returns "restricted")
|
|
208
389
|
- Requires no special permissions for basic device info
|
|
209
390
|
|
|
210
391
|
### macOS
|
|
392
|
+
|
|
211
393
|
- Uses native CoreGraphics API for accurate refresh rate detection
|
|
212
394
|
- Full access to all device information
|
|
213
395
|
|
|
214
396
|
### Windows
|
|
397
|
+
|
|
215
398
|
- Uses WMI (Windows Management Instrumentation) for device info
|
|
216
399
|
- Full access to all device information
|
|
217
400
|
|
|
218
401
|
### Linux
|
|
402
|
+
|
|
219
403
|
- Display refresh rate requires X11 (xrandr)
|
|
220
404
|
- Device info read from `/sys/class/dmi/id/`
|
|
221
405
|
|
|
406
|
+
## Testing
|
|
407
|
+
|
|
408
|
+
The Rust core is covered by unit tests that run on every push and pull request
|
|
409
|
+
via GitHub Actions across Linux, macOS, and Windows (see the **Tests** badge above).
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
# Run the Rust test suite
|
|
413
|
+
cargo test
|
|
414
|
+
|
|
415
|
+
# Lint and formatting (same checks as CI)
|
|
416
|
+
cargo fmt -- --check
|
|
417
|
+
cargo clippy -- -D warnings
|
|
418
|
+
|
|
419
|
+
# JavaScript type check
|
|
420
|
+
yarn tsc --noEmit
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
## Changelog
|
|
424
|
+
|
|
425
|
+
See [CHANGELOG.md](CHANGELOG.md) for the release history and notable changes.
|
|
426
|
+
|
|
427
|
+
## Contributing
|
|
428
|
+
|
|
429
|
+
Contributions are welcome! Please read the [Contributing Guide](CONTRIBUTING.md)
|
|
430
|
+
and the [Code of Conduct](CODE_OF_CONDUCT.md) before opening a pull request.
|
|
431
|
+
|
|
222
432
|
## License
|
|
223
433
|
|
|
224
434
|
MIT
|
|
435
|
+
|
package/dist-js/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var core = require('@tauri-apps/api/core');
|
|
4
|
+
var event = require('@tauri-apps/api/event');
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Get comprehensive device information including UUID, manufacturer, model, etc.
|
|
@@ -32,9 +33,56 @@ async function getStorageInfo() {
|
|
|
32
33
|
async function getDisplayInfo() {
|
|
33
34
|
return await core.invoke('plugin:device-info|get_display_info');
|
|
34
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Subscribes to a device-info kind and invokes `callback` whenever the value changes.
|
|
38
|
+
* The current value is delivered immediately, then on every change.
|
|
39
|
+
* Returns a function that stops watching and removes the listener.
|
|
40
|
+
*/
|
|
41
|
+
async function watch(kind, callback, options) {
|
|
42
|
+
const unlisten = await event.listen(`device-info://${kind}-changed`, (event) => {
|
|
43
|
+
callback(event.payload);
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
await core.invoke('plugin:device-info|start_watching', { kind, intervalMs: options?.intervalMs });
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
// Don't leak the event listener if the backend failed to start the watcher.
|
|
50
|
+
unlisten();
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
return async () => {
|
|
54
|
+
unlisten();
|
|
55
|
+
await core.invoke('plugin:device-info|stop_watching', { kind });
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Watch battery status (level, charging state, health) for changes. */
|
|
59
|
+
function watchBattery(callback, options) {
|
|
60
|
+
return watch('battery', callback, options);
|
|
61
|
+
}
|
|
62
|
+
/** Watch network connectivity (IP, type, MAC) for changes — e.g. Wi-Fi ↔ offline. */
|
|
63
|
+
function watchNetwork(callback, options) {
|
|
64
|
+
return watch('network', callback, options);
|
|
65
|
+
}
|
|
66
|
+
/** Watch storage capacity (total/free space) for changes. */
|
|
67
|
+
function watchStorage(callback, options) {
|
|
68
|
+
return watch('storage', callback, options);
|
|
69
|
+
}
|
|
70
|
+
/** Watch display properties (resolution, scale, refresh rate) for changes — e.g. plugging in a monitor. */
|
|
71
|
+
function watchDisplay(callback, options) {
|
|
72
|
+
return watch('display', callback, options);
|
|
73
|
+
}
|
|
74
|
+
/** Watch device identity fields for changes (rarely changes; useful on mobile). */
|
|
75
|
+
function watchDevice(callback, options) {
|
|
76
|
+
return watch('device', callback, options);
|
|
77
|
+
}
|
|
35
78
|
|
|
36
79
|
exports.getBatteryInfo = getBatteryInfo;
|
|
37
80
|
exports.getDeviceInfo = getDeviceInfo;
|
|
38
81
|
exports.getDisplayInfo = getDisplayInfo;
|
|
39
82
|
exports.getNetworkInfo = getNetworkInfo;
|
|
40
83
|
exports.getStorageInfo = getStorageInfo;
|
|
84
|
+
exports.watchBattery = watchBattery;
|
|
85
|
+
exports.watchDevice = watchDevice;
|
|
86
|
+
exports.watchDisplay = watchDisplay;
|
|
87
|
+
exports.watchNetwork = watchNetwork;
|
|
88
|
+
exports.watchStorage = watchStorage;
|
package/dist-js/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DeviceInfoResponse, BatteryInfo, NetworkInfo, StorageInfo, DisplayInfo } from './type';
|
|
2
|
-
export type { DeviceInfoResponse, DeviceInfoResponse as DeviceInfo, BatteryInfo, NetworkInfo, StorageInfo, DisplayInfo } from './type';
|
|
1
|
+
import type { DeviceInfoResponse, BatteryInfo, NetworkInfo, StorageInfo, DisplayInfo, WatchOptions, UnwatchFn } from './type';
|
|
2
|
+
export type { DeviceInfoResponse, DeviceInfoResponse as DeviceInfo, BatteryInfo, NetworkInfo, StorageInfo, DisplayInfo, WatchOptions, UnwatchFn } from './type';
|
|
3
3
|
/**
|
|
4
4
|
* Get comprehensive device information including UUID, manufacturer, model, etc.
|
|
5
5
|
*/
|
|
@@ -20,3 +20,13 @@ export declare function getStorageInfo(): Promise<StorageInfo>;
|
|
|
20
20
|
* Get display information including resolution, scale factor, and refresh rate.
|
|
21
21
|
*/
|
|
22
22
|
export declare function getDisplayInfo(): Promise<DisplayInfo>;
|
|
23
|
+
/** Watch battery status (level, charging state, health) for changes. */
|
|
24
|
+
export declare function watchBattery(callback: (info: BatteryInfo) => void, options?: WatchOptions): Promise<UnwatchFn>;
|
|
25
|
+
/** Watch network connectivity (IP, type, MAC) for changes — e.g. Wi-Fi ↔ offline. */
|
|
26
|
+
export declare function watchNetwork(callback: (info: NetworkInfo) => void, options?: WatchOptions): Promise<UnwatchFn>;
|
|
27
|
+
/** Watch storage capacity (total/free space) for changes. */
|
|
28
|
+
export declare function watchStorage(callback: (info: StorageInfo) => void, options?: WatchOptions): Promise<UnwatchFn>;
|
|
29
|
+
/** Watch display properties (resolution, scale, refresh rate) for changes — e.g. plugging in a monitor. */
|
|
30
|
+
export declare function watchDisplay(callback: (info: DisplayInfo) => void, options?: WatchOptions): Promise<UnwatchFn>;
|
|
31
|
+
/** Watch device identity fields for changes (rarely changes; useful on mobile). */
|
|
32
|
+
export declare function watchDevice(callback: (info: DeviceInfoResponse) => void, options?: WatchOptions): Promise<UnwatchFn>;
|
package/dist-js/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { invoke } from '@tauri-apps/api/core';
|
|
2
|
+
import { listen } from '@tauri-apps/api/event';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Get comprehensive device information including UUID, manufacturer, model, etc.
|
|
@@ -30,5 +31,47 @@ async function getStorageInfo() {
|
|
|
30
31
|
async function getDisplayInfo() {
|
|
31
32
|
return await invoke('plugin:device-info|get_display_info');
|
|
32
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Subscribes to a device-info kind and invokes `callback` whenever the value changes.
|
|
36
|
+
* The current value is delivered immediately, then on every change.
|
|
37
|
+
* Returns a function that stops watching and removes the listener.
|
|
38
|
+
*/
|
|
39
|
+
async function watch(kind, callback, options) {
|
|
40
|
+
const unlisten = await listen(`device-info://${kind}-changed`, (event) => {
|
|
41
|
+
callback(event.payload);
|
|
42
|
+
});
|
|
43
|
+
try {
|
|
44
|
+
await invoke('plugin:device-info|start_watching', { kind, intervalMs: options?.intervalMs });
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
// Don't leak the event listener if the backend failed to start the watcher.
|
|
48
|
+
unlisten();
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
return async () => {
|
|
52
|
+
unlisten();
|
|
53
|
+
await invoke('plugin:device-info|stop_watching', { kind });
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Watch battery status (level, charging state, health) for changes. */
|
|
57
|
+
function watchBattery(callback, options) {
|
|
58
|
+
return watch('battery', callback, options);
|
|
59
|
+
}
|
|
60
|
+
/** Watch network connectivity (IP, type, MAC) for changes — e.g. Wi-Fi ↔ offline. */
|
|
61
|
+
function watchNetwork(callback, options) {
|
|
62
|
+
return watch('network', callback, options);
|
|
63
|
+
}
|
|
64
|
+
/** Watch storage capacity (total/free space) for changes. */
|
|
65
|
+
function watchStorage(callback, options) {
|
|
66
|
+
return watch('storage', callback, options);
|
|
67
|
+
}
|
|
68
|
+
/** Watch display properties (resolution, scale, refresh rate) for changes — e.g. plugging in a monitor. */
|
|
69
|
+
function watchDisplay(callback, options) {
|
|
70
|
+
return watch('display', callback, options);
|
|
71
|
+
}
|
|
72
|
+
/** Watch device identity fields for changes (rarely changes; useful on mobile). */
|
|
73
|
+
function watchDevice(callback, options) {
|
|
74
|
+
return watch('device', callback, options);
|
|
75
|
+
}
|
|
33
76
|
|
|
34
|
-
export { getBatteryInfo, getDeviceInfo, getDisplayInfo, getNetworkInfo, getStorageInfo };
|
|
77
|
+
export { getBatteryInfo, getDeviceInfo, getDisplayInfo, getNetworkInfo, getStorageInfo, watchBattery, watchDevice, watchDisplay, watchNetwork, watchStorage };
|
package/dist-js/type.d.ts
CHANGED
|
@@ -27,3 +27,21 @@ export interface DisplayInfo {
|
|
|
27
27
|
scaleFactor?: number;
|
|
28
28
|
refreshRate?: number;
|
|
29
29
|
}
|
|
30
|
+
/** Options for the reactive `watch*` APIs. */
|
|
31
|
+
export interface WatchOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Polling interval in milliseconds used to detect changes (only applies to
|
|
34
|
+
* kinds that fall back to polling; native event-driven kinds ignore it).
|
|
35
|
+
*
|
|
36
|
+
* Defaults and minimums are per kind, because some getters are expensive and
|
|
37
|
+
* some values rarely change:
|
|
38
|
+
* - `device`: defaults to 60000ms, floored at 10000ms (reads are costly and it barely changes)
|
|
39
|
+
* - `storage`: defaults to 10000ms, floored at 1000ms
|
|
40
|
+
* - others: default 2000ms, floored at 250ms
|
|
41
|
+
*
|
|
42
|
+
* Only the first subscriber for a given kind sets the interval.
|
|
43
|
+
*/
|
|
44
|
+
intervalMs?: number;
|
|
45
|
+
}
|
|
46
|
+
/** Stops a watcher and removes its listener. Returned by every `watch*` function. */
|
|
47
|
+
export type UnwatchFn = () => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tauri-plugin-device-info-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"author": "edisdev<edisdev14@gmail.com>",
|
|
5
5
|
"description": "A Tauri plugin to access device information.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,14 +8,6 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/edisdev/tauri-plugin-device-info.git"
|
|
10
10
|
},
|
|
11
|
-
"keywords": [
|
|
12
|
-
"tauri",
|
|
13
|
-
"plugin",
|
|
14
|
-
"device-info",
|
|
15
|
-
"system",
|
|
16
|
-
"mobile",
|
|
17
|
-
"desktop"
|
|
18
|
-
],
|
|
19
11
|
"bugs": {
|
|
20
12
|
"url": "https://github.com/edisdev/tauri-plugin-device-info/issues"
|
|
21
13
|
},
|
|
@@ -29,6 +21,33 @@
|
|
|
29
21
|
"import": "./dist-js/index.js",
|
|
30
22
|
"require": "./dist-js/index.cjs"
|
|
31
23
|
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"tauri",
|
|
26
|
+
"tauri-plugin",
|
|
27
|
+
"tauri-plugin-device-info",
|
|
28
|
+
"tauri-v2",
|
|
29
|
+
"device-info",
|
|
30
|
+
"device",
|
|
31
|
+
"system-info",
|
|
32
|
+
"hardware",
|
|
33
|
+
"battery",
|
|
34
|
+
"battery-status",
|
|
35
|
+
"network",
|
|
36
|
+
"network-info",
|
|
37
|
+
"storage",
|
|
38
|
+
"disk-space",
|
|
39
|
+
"display",
|
|
40
|
+
"screen",
|
|
41
|
+
"cross-platform",
|
|
42
|
+
"desktop",
|
|
43
|
+
"mobile",
|
|
44
|
+
"ios",
|
|
45
|
+
"android",
|
|
46
|
+
"macos",
|
|
47
|
+
"windows",
|
|
48
|
+
"linux",
|
|
49
|
+
"rust"
|
|
50
|
+
],
|
|
32
51
|
"files": [
|
|
33
52
|
"dist-js",
|
|
34
53
|
"README.md"
|