tauri-plugin-device-info-api 1.0.1 → 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 +111 -1
- 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 +1 -1
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
|
@@ -7,14 +7,30 @@
|
|
|
7
7
|
[](https://github.com/edisdev/tauri-plugin-device-info)
|
|
8
8
|
[](https://github.com/edisdev/tauri-plugin-device-info/fork)
|
|
9
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)
|
|
11
13
|
|
|
12
14
|
A comprehensive Tauri plugin to access device information including Battery, Network, Storage, Display, and System Details.
|
|
13
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
|
+
|
|
14
18
|
---
|
|
15
19
|
|
|
16
20
|
**📖 [Read the Documentation](https://edisdev.github.io/tauri-plugin-device-info)**
|
|
17
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
|
+
|
|
18
34
|
## 📸 Preview
|
|
19
35
|
|
|
20
36
|
<div>
|
|
@@ -178,6 +194,49 @@ console.log(display);
|
|
|
178
194
|
}
|
|
179
195
|
```
|
|
180
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
|
+
|
|
181
240
|
## API Reference
|
|
182
241
|
|
|
183
242
|
### getDeviceInfo()
|
|
@@ -234,6 +293,26 @@ Returns display/screen information.
|
|
|
234
293
|
| `scaleFactor` | `number?` | Display scale factor (e.g., 2.0 for Retina) |
|
|
235
294
|
| `refreshRate` | `number?` | Screen refresh rate in Hz |
|
|
236
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. |
|
|
315
|
+
|
|
237
316
|
## TypeScript Types
|
|
238
317
|
|
|
239
318
|
All types are exported and can be imported:
|
|
@@ -245,6 +324,8 @@ import type {
|
|
|
245
324
|
NetworkInfo,
|
|
246
325
|
StorageInfo,
|
|
247
326
|
DisplayInfo,
|
|
327
|
+
WatchOptions,
|
|
328
|
+
UnwatchFn,
|
|
248
329
|
} from "tauri-plugin-device-info-api";
|
|
249
330
|
```
|
|
250
331
|
|
|
@@ -274,6 +355,8 @@ Add the required permissions in your `capabilities` configuration.
|
|
|
274
355
|
| `device-info:allow-get-network-info` | Allows getting network details |
|
|
275
356
|
| `device-info:allow-get-storage-info` | Allows getting storage info |
|
|
276
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 |
|
|
277
360
|
|
|
278
361
|
### Individual Permissions Example
|
|
279
362
|
|
|
@@ -320,6 +403,33 @@ If you want to grant only specific permissions:
|
|
|
320
403
|
- Display refresh rate requires X11 (xrandr)
|
|
321
404
|
- Device info read from `/sys/class/dmi/id/`
|
|
322
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
|
+
|
|
323
432
|
## License
|
|
324
433
|
|
|
325
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>;
|