tauri-plugin-device-info-api 1.1.1 → 1.3.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 CHANGED
@@ -5,6 +5,78 @@ All notable changes to this project are documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.3.0] - 2026-11-18
9
+
10
+ ### Changed
11
+
12
+ - **Minimum versions:** the plugin now requires Tauri **2.12** (`tauri`
13
+ crate) and `@tauri-apps/api` **^2.12.5**.
14
+ - **Dependencies:**
15
+ - `sysinfo` 0.40, `wmi` 0.18 (Windows), and the other dependencies
16
+ updated within range.
17
+ - Apple Silicon: `sysinfo` now reads the CPU clock, so the device tier
18
+ score can rise slightly (an M5 Pro moves from 90 to 92).
19
+ - **Mobile builds:** desktop-only crates (`sysinfo`, `local-ip-address`, the
20
+ network crate) are no longer compiled for iOS and Android
21
+ ([#7](https://github.com/edisdev/tauri-plugin-device-info/pull/7)).
22
+ - **Package manager:** the repository uses pnpm instead of yarn. Install
23
+ commands in the docs show npm, pnpm and yarn.
24
+
25
+ ### Fixed
26
+
27
+ - **Unmaintained crates replaced:**
28
+ - `battery` is replaced by `starship-battery`, its maintained fork, on
29
+ Windows and Linux. On macOS it was never used and is no longer compiled.
30
+ - `default-net` is replaced by `netdev`, its successor.
31
+ - **Security advisories:** no known advisories remain in the JS
32
+ dependencies of the plugin, the docs or the example app.
33
+
34
+ ## [1.2.0] - 2026-11-17
35
+
36
+ ### Added
37
+
38
+ - **Adaptive Apps** — signals that turn raw readings into decisions.
39
+ - `getPowerProfile()` / `watchPowerProfile()` — one `full | balanced | saver`
40
+ recommendation combining battery level, charging state, OS power-saving mode
41
+ (Low Power Mode, Battery Saver, Linux `low-power` profile) and thermal
42
+ pressure, plus the `reasons` behind it. Battery thresholds apply only on
43
+ battery — not while charging or on external power (`onExternalPower`:
44
+ AC/USB-C adapter detected on macOS, Windows, Linux, iOS and Android, so a
45
+ laptop on AC that is full or held at a charge limit is not "low") — and an
46
+ unknown battery level (iOS Simulator, unsupported Android capacity) is
47
+ ignored rather than read as empty. On Linux only CPU/SoC thermal zones are
48
+ considered.
49
+ - `getDeviceTier()` — a `low | mid | high` capability class and 0-100 score
50
+ from memory, CPU cores and peak clock, scored against the device's form
51
+ factor; honours Android's low-RAM flag and media performance class.
52
+ - `get_power_profile` / `get_device_tier` commands with matching
53
+ `allow-get-power-profile` / `allow-get-device-tier` permissions, included in
54
+ `device-info:default`.
55
+ - New `power` watch kind (polled, default 5 s).
56
+ - Rust: `get_power_profile()`, `get_device_tier()`, `get_power_state()` and
57
+ `get_hardware_info()` on `DeviceInfo`, and the pure
58
+ `adaptive::power_profile` / `adaptive::device_tier` functions.
59
+ - New types: `PowerProfile`, `PowerProfileKind`, `PowerProfileReason`,
60
+ `ThermalState`, `DeviceTier`, `DeviceTierKind`, `HardwareInfo`.
61
+
62
+ ### Fixed
63
+
64
+ - **Watch API: late subscribers now get the current value.** A `watch*` call
65
+ for a kind that was already being watched (a second component, or the same
66
+ page after a webview reload) only received *future* changes, because the
67
+ running monitor emits on change. `start_watching` now returns the current
68
+ value, which the `watch*` call delivers to its own callback only; monitors
69
+ emit only on change, so existing subscribers no longer see duplicates and
70
+ the first subscriber gets the initial value exactly once.
71
+ - **iOS / Android: unknown battery level reported as 0%.** iOS sent `0` when
72
+ `batteryLevel` is unknown (always on the Simulator) and Android passed through
73
+ an unsupported `BATTERY_PROPERTY_CAPACITY`; `level` is now omitted instead
74
+ (Android falls back to the battery intent's level/scale first).
75
+ - **iOS release builds failed to link** with `Undefined symbols:
76
+ _init_plugin_device_info` on Xcode 27 / Swift 6.4, which hides `internal`
77
+ symbols when merging a package's objects in release. The Swift entry point is
78
+ now `public`.
79
+
8
80
  ## [1.1.1] - 2026-11-17
9
81
 
10
82
  ### Fixed
@@ -76,6 +148,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
76
148
  `getStorageInfo`, and `getDisplayInfo` across Windows, macOS, Linux, iOS, and
77
149
  Android.
78
150
 
151
+ [1.3.0]: https://github.com/edisdev/tauri-plugin-device-info/releases/tag/v1.3.0
152
+ [1.2.0]: https://github.com/edisdev/tauri-plugin-device-info/releases/tag/v1.2.0
79
153
  [1.1.1]: https://github.com/edisdev/tauri-plugin-device-info/releases/tag/v1.1.1
80
154
  [1.1.0]: https://github.com/edisdev/tauri-plugin-device-info/releases/tag/v1.1.0
81
155
  [1.0.1]: https://github.com/edisdev/tauri-plugin-device-info/releases/tag/v1.0.1
package/README.md CHANGED
@@ -26,6 +26,7 @@ A comprehensive Tauri plugin to access device information including Battery, Net
26
26
  - 💾 **Storage** — total/free space and storage type
27
27
  - 🖥️ **Display** — resolution, scale factor, and refresh rate
28
28
  - 🆔 **Device** — manufacturer, model, serial, and device name
29
+ - ⚡ **Adaptive** — one `full | balanced | saver` power signal and a `low | mid | high` device tier, so your app can adjust itself
29
30
  - 🔔 **Reactive** — `watch*` APIs push updates on change (native event-driven on macOS, polling fallback elsewhere)
30
31
  - 📱 **Truly cross-platform** — Windows, macOS, Linux, iOS, and Android
31
32
  - 🛡️ **Type-safe** — full TypeScript types and granular Tauri permissions
@@ -33,15 +34,13 @@ A comprehensive Tauri plugin to access device information including Battery, Net
33
34
 
34
35
  ## 📸 Preview
35
36
 
36
- <div>
37
- <img src="./docs/public/DeviceInfo_Android_Gif.gif" alt="Android Preview GIF" width="250">
38
- <br>
39
- <img src="./docs/public/DeviceInfo_Mac.png" alt="macOS Preview" width="400">
40
- <img src="./docs/public/DeviceInfo_Windows.png" alt="Windows Preview" width="400">
41
- <br>
42
- <img src="./docs/public/DeviceInfo_Android.png" alt="Android Preview" width="250">
43
- <img src="./docs/public/DeviceInfo_iOS.png" alt="iOS Preview" width="250">
44
- <p><i>Example Dashboard Application across platforms</i></p>
37
+ <div align="center">
38
+ <img src="./docs/public/DeviceInfo_Promo.gif" alt="The plugin in the example app: live signals on macOS and iOS, then the power profile adapting on Windows and Android" width="900">
39
+ <br><br>
40
+ <img src="./docs/public/DeviceInfo_macOS.gif" alt="Vitals on macOS: switching pages, simulating the Saver profile and changing themes" width="560">
41
+ <img src="./docs/public/DeviceInfo_iOS.gif" alt="Vitals on iPhone: live battery and thermal readings, the Adaptive page and themes" width="230">
42
+ <p><i><b>Vitals</b> — the example app in <a href="./examples/tauri-app">examples/tauri-app</a>, built on this plugin.<br>
43
+ Real readings on macOS, iOS, Windows 10 and Android 16.</i></p>
45
44
  </div>
46
45
 
47
46
  ## Platform Support
@@ -61,6 +60,8 @@ A comprehensive Tauri plugin to access device information including Battery, Net
61
60
  ```bash
62
61
  npm run tauri add device-info
63
62
  # or
63
+ pnpm tauri add device-info
64
+ # or
64
65
  yarn tauri add device-info
65
66
  ```
66
67
 
@@ -70,7 +71,7 @@ yarn tauri add device-info
70
71
 
71
72
  ```toml
72
73
  [dependencies]
73
- tauri-plugin-device-info = "1.0" # Check crates.io for latest version
74
+ tauri-plugin-device-info = "1.3" # Check crates.io for latest version
74
75
  # or from git
75
76
  tauri-plugin-device-info = { git = "https://github.com/edisdev/tauri-plugin-device-info" }
76
77
  ```
@@ -80,7 +81,7 @@ tauri-plugin-device-info = { git = "https://github.com/edisdev/tauri-plugin-devi
80
81
  ```json
81
82
  {
82
83
  "dependencies": {
83
- "tauri-plugin-device-info-api": "^1.0.0"
84
+ "tauri-plugin-device-info-api": "^1.3.0"
84
85
  }
85
86
  }
86
87
  ```
@@ -234,9 +235,32 @@ await Promise.all(unwatchers.map((unwatch) => unwatch()));
234
235
  `watch*` accepts an optional `{ intervalMs }` that applies **only to polled
235
236
  kinds** (native kinds ignore it). Defaults and minimums are per kind: `device`
236
237
  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
+ 1000 ms), `power` to 5000 ms (floored at 1000 ms), and others to 2000 ms (floored at 250 ms). Subscribers to the same
238
239
  kind share one monitor, so only the first subscriber's interval takes effect.
239
240
 
241
+ ### Adaptive Apps
242
+
243
+ Raw readings tell you what the device is doing; these tell you what to do about
244
+ it. `getPowerProfile()` folds battery, Low Power Mode / Battery Saver and thermal
245
+ pressure into one recommendation, and `getDeviceTier()` classifies the hardware.
246
+
247
+ ```typescript
248
+ import { watchPowerProfile, getDeviceTier } from "tauri-plugin-device-info-api";
249
+
250
+ // Back off when the device is hot, in Low Power Mode, or low on battery.
251
+ await watchPowerProfile(({ profile, reasons }) => {
252
+ document.documentElement.dataset.power = profile; // "full" | "balanced" | "saver"
253
+ console.log(reasons); // e.g. ["thermalSerious", "batteryLow"]
254
+ });
255
+
256
+ // Pick a quality level the hardware can sustain.
257
+ const { tier, score } = await getDeviceTier(); // "low" | "mid" | "high", 0-100
258
+ const particles = { low: 0, mid: 200, high: 1000 }[tier];
259
+ ```
260
+
261
+ See [Adaptive Apps](https://edisdev.github.io/tauri-plugin-device-info/api/adaptive)
262
+ for the exact rules, thresholds and per-platform sources.
263
+
240
264
  ## API Reference
241
265
 
242
266
  ### getDeviceInfo()
@@ -293,6 +317,29 @@ Returns display/screen information.
293
317
  | `scaleFactor` | `number?` | Display scale factor (e.g., 2.0 for Retina) |
294
318
  | `refreshRate` | `number?` | Screen refresh rate in Hz |
295
319
 
320
+ ### getPowerProfile()
321
+
322
+ Returns a recommendation for how much work the app should do right now.
323
+
324
+ | Field | Type | Description |
325
+ | -------------- | ------------------------------------------------ | ----------------------------------------------- |
326
+ | `profile` | `"full" \| "balanced" \| "saver"` | Most restrictive profile implied by any reason |
327
+ | `reasons` | `PowerProfileReason[]` | Why it isn't `full` (empty when it is) |
328
+ | `batteryLevel` | `number?` | 0-100; absent without a battery |
329
+ | `isCharging` | `boolean?` | Whether the device is charging |
330
+ | `lowPowerMode` | `boolean?` | Low Power Mode / Battery Saver / `low-power` |
331
+ | `thermalState` | `"nominal" \| "fair" \| "serious" \| "critical"?` | Thermal pressure (not available on Windows) |
332
+
333
+ ### getDeviceTier()
334
+
335
+ Classifies the hardware relative to devices of the same form factor.
336
+
337
+ | Field | Type | Description |
338
+ | ---------- | ---------------------------- | ---------------------------------------------- |
339
+ | `tier` | `"low" \| "mid" \| "high"` | Capability class |
340
+ | `score` | `number` | 0-100 (`low` < 30 ≤ `mid` < 65 ≤ `high`) |
341
+ | `hardware` | `HardwareInfo` | CPU cores, CPU model, peak clock, total memory |
342
+
296
343
  ### watch\*(callback, options?)
297
344
 
298
345
  Subscribes to a kind and invokes `callback` with the current value immediately,
@@ -306,6 +353,7 @@ to stop watching and remove the listener.
306
353
  | `watchNetwork()` | `NetworkInfo` |
307
354
  | `watchStorage()` | `StorageInfo` |
308
355
  | `watchDisplay()` | `DisplayInfo` |
356
+ | `watchPowerProfile()` | `PowerProfile` |
309
357
 
310
358
  **Options**
311
359
 
@@ -324,6 +372,9 @@ import type {
324
372
  NetworkInfo,
325
373
  StorageInfo,
326
374
  DisplayInfo,
375
+ PowerProfile,
376
+ DeviceTier,
377
+ HardwareInfo,
327
378
  WatchOptions,
328
379
  UnwatchFn,
329
380
  } from "tauri-plugin-device-info-api";
@@ -355,6 +406,8 @@ Add the required permissions in your `capabilities` configuration.
355
406
  | `device-info:allow-get-network-info` | Allows getting network details |
356
407
  | `device-info:allow-get-storage-info` | Allows getting storage info |
357
408
  | `device-info:allow-get-display-info` | Allows getting display info |
409
+ | `device-info:allow-get-power-profile` | Allows getting the power profile |
410
+ | `device-info:allow-get-device-tier` | Allows getting the device tier |
358
411
  | `device-info:allow-start-watching` | Allows starting a reactive watch |
359
412
  | `device-info:allow-stop-watching` | Allows stopping a reactive watch |
360
413
 
@@ -417,7 +470,7 @@ cargo fmt -- --check
417
470
  cargo clippy -- -D warnings
418
471
 
419
472
  # JavaScript type check
420
- yarn tsc --noEmit
473
+ pnpm exec tsc --noEmit
421
474
  ```
422
475
 
423
476
  ## Changelog
package/dist-js/index.cjs CHANGED
@@ -33,23 +33,62 @@ async function getStorageInfo() {
33
33
  async function getDisplayInfo() {
34
34
  return await core.invoke('plugin:device-info|get_display_info');
35
35
  }
36
+ // ============================================================================
37
+ // Adaptive signals
38
+ // ============================================================================
39
+ /**
40
+ * Get a single `full | balanced | saver` recommendation that combines battery
41
+ * level, charging state, OS power-saving mode and thermal pressure.
42
+ *
43
+ * @example
44
+ * const { profile } = await getPowerProfile()
45
+ * if (profile === 'saver') disableBackgroundSync()
46
+ */
47
+ async function getPowerProfile() {
48
+ return await core.invoke('plugin:device-info|get_power_profile');
49
+ }
50
+ /**
51
+ * Classify the device as `low | mid | high` from its CPU and memory, scored
52
+ * against devices of the same form factor (desktop vs. mobile).
53
+ *
54
+ * @example
55
+ * const { tier } = await getDeviceTier()
56
+ * document.body.dataset.tier = tier // style with [data-tier="low"] { ... }
57
+ */
58
+ async function getDeviceTier() {
59
+ return await core.invoke('plugin:device-info|get_device_tier');
60
+ }
36
61
  /**
37
62
  * Subscribes to a device-info kind and invokes `callback` whenever the value changes.
38
63
  * The current value is delivered immediately, then on every change.
39
64
  * Returns a function that stops watching and removes the listener.
40
65
  */
41
66
  async function watch(kind, callback, options) {
67
+ // Listen before starting so no change emitted after the start is missed.
68
+ let changed = false;
42
69
  const unlisten = await event.listen(`device-info://${kind}-changed`, (event) => {
70
+ changed = true;
43
71
  callback(event.payload);
44
72
  });
73
+ let current;
45
74
  try {
46
- await core.invoke('plugin:device-info|start_watching', { kind, intervalMs: options?.intervalMs });
75
+ // Returns the current value for this subscriber only; the backend emits
76
+ // events only on change, so other subscribers don't get a duplicate.
77
+ current = await core.invoke('plugin:device-info|start_watching', {
78
+ kind,
79
+ intervalMs: options?.intervalMs
80
+ });
47
81
  }
48
82
  catch (error) {
49
83
  // Don't leak the event listener if the backend failed to start the watcher.
50
84
  unlisten();
51
85
  throw error;
52
86
  }
87
+ // A change event that already arrived is at least as new as `current`;
88
+ // delivering `current` after it would roll the caller back to a stale value.
89
+ if (current !== null && current !== undefined && !changed) {
90
+ callback(current);
91
+ }
53
92
  return async () => {
54
93
  unlisten();
55
94
  await core.invoke('plugin:device-info|stop_watching', { kind });
@@ -75,14 +114,29 @@ function watchDisplay(callback, options) {
75
114
  function watchDevice(callback, options) {
76
115
  return watch('device', callback, options);
77
116
  }
117
+ /**
118
+ * Watch the power profile — fires when the profile, any reason, or the
119
+ * underlying battery/thermal/low-power readings change.
120
+ *
121
+ * @example
122
+ * const unwatch = await watchPowerProfile(({ profile }) => {
123
+ * animations.enabled = profile === 'full'
124
+ * })
125
+ */
126
+ function watchPowerProfile(callback, options) {
127
+ return watch('power', callback, options);
128
+ }
78
129
 
79
130
  exports.getBatteryInfo = getBatteryInfo;
80
131
  exports.getDeviceInfo = getDeviceInfo;
132
+ exports.getDeviceTier = getDeviceTier;
81
133
  exports.getDisplayInfo = getDisplayInfo;
82
134
  exports.getNetworkInfo = getNetworkInfo;
135
+ exports.getPowerProfile = getPowerProfile;
83
136
  exports.getStorageInfo = getStorageInfo;
84
137
  exports.watchBattery = watchBattery;
85
138
  exports.watchDevice = watchDevice;
86
139
  exports.watchDisplay = watchDisplay;
87
140
  exports.watchNetwork = watchNetwork;
141
+ exports.watchPowerProfile = watchPowerProfile;
88
142
  exports.watchStorage = watchStorage;
@@ -1,5 +1,5 @@
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';
1
+ import type { DeviceInfoResponse, BatteryInfo, NetworkInfo, StorageInfo, DisplayInfo, PowerProfile, DeviceTier, WatchOptions, UnwatchFn } from './type';
2
+ export type { DeviceInfoResponse, DeviceInfoResponse as DeviceInfo, BatteryInfo, NetworkInfo, StorageInfo, DisplayInfo, ThermalState, PowerProfile, PowerProfileKind, PowerProfileReason, HardwareInfo, DeviceTier, DeviceTierKind, WatchOptions, UnwatchFn } from './type';
3
3
  /**
4
4
  * Get comprehensive device information including UUID, manufacturer, model, etc.
5
5
  */
@@ -20,6 +20,24 @@ 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
+ /**
24
+ * Get a single `full | balanced | saver` recommendation that combines battery
25
+ * level, charging state, OS power-saving mode and thermal pressure.
26
+ *
27
+ * @example
28
+ * const { profile } = await getPowerProfile()
29
+ * if (profile === 'saver') disableBackgroundSync()
30
+ */
31
+ export declare function getPowerProfile(): Promise<PowerProfile>;
32
+ /**
33
+ * Classify the device as `low | mid | high` from its CPU and memory, scored
34
+ * against devices of the same form factor (desktop vs. mobile).
35
+ *
36
+ * @example
37
+ * const { tier } = await getDeviceTier()
38
+ * document.body.dataset.tier = tier // style with [data-tier="low"] { ... }
39
+ */
40
+ export declare function getDeviceTier(): Promise<DeviceTier>;
23
41
  /** Watch battery status (level, charging state, health) for changes. */
24
42
  export declare function watchBattery(callback: (info: BatteryInfo) => void, options?: WatchOptions): Promise<UnwatchFn>;
25
43
  /** Watch network connectivity (IP, type, MAC) for changes — e.g. Wi-Fi ↔ offline. */
@@ -30,3 +48,13 @@ export declare function watchStorage(callback: (info: StorageInfo) => void, opti
30
48
  export declare function watchDisplay(callback: (info: DisplayInfo) => void, options?: WatchOptions): Promise<UnwatchFn>;
31
49
  /** Watch device identity fields for changes (rarely changes; useful on mobile). */
32
50
  export declare function watchDevice(callback: (info: DeviceInfoResponse) => void, options?: WatchOptions): Promise<UnwatchFn>;
51
+ /**
52
+ * Watch the power profile — fires when the profile, any reason, or the
53
+ * underlying battery/thermal/low-power readings change.
54
+ *
55
+ * @example
56
+ * const unwatch = await watchPowerProfile(({ profile }) => {
57
+ * animations.enabled = profile === 'full'
58
+ * })
59
+ */
60
+ export declare function watchPowerProfile(callback: (profile: PowerProfile) => void, options?: WatchOptions): Promise<UnwatchFn>;
package/dist-js/index.js CHANGED
@@ -31,23 +31,62 @@ async function getStorageInfo() {
31
31
  async function getDisplayInfo() {
32
32
  return await invoke('plugin:device-info|get_display_info');
33
33
  }
34
+ // ============================================================================
35
+ // Adaptive signals
36
+ // ============================================================================
37
+ /**
38
+ * Get a single `full | balanced | saver` recommendation that combines battery
39
+ * level, charging state, OS power-saving mode and thermal pressure.
40
+ *
41
+ * @example
42
+ * const { profile } = await getPowerProfile()
43
+ * if (profile === 'saver') disableBackgroundSync()
44
+ */
45
+ async function getPowerProfile() {
46
+ return await invoke('plugin:device-info|get_power_profile');
47
+ }
48
+ /**
49
+ * Classify the device as `low | mid | high` from its CPU and memory, scored
50
+ * against devices of the same form factor (desktop vs. mobile).
51
+ *
52
+ * @example
53
+ * const { tier } = await getDeviceTier()
54
+ * document.body.dataset.tier = tier // style with [data-tier="low"] { ... }
55
+ */
56
+ async function getDeviceTier() {
57
+ return await invoke('plugin:device-info|get_device_tier');
58
+ }
34
59
  /**
35
60
  * Subscribes to a device-info kind and invokes `callback` whenever the value changes.
36
61
  * The current value is delivered immediately, then on every change.
37
62
  * Returns a function that stops watching and removes the listener.
38
63
  */
39
64
  async function watch(kind, callback, options) {
65
+ // Listen before starting so no change emitted after the start is missed.
66
+ let changed = false;
40
67
  const unlisten = await listen(`device-info://${kind}-changed`, (event) => {
68
+ changed = true;
41
69
  callback(event.payload);
42
70
  });
71
+ let current;
43
72
  try {
44
- await invoke('plugin:device-info|start_watching', { kind, intervalMs: options?.intervalMs });
73
+ // Returns the current value for this subscriber only; the backend emits
74
+ // events only on change, so other subscribers don't get a duplicate.
75
+ current = await invoke('plugin:device-info|start_watching', {
76
+ kind,
77
+ intervalMs: options?.intervalMs
78
+ });
45
79
  }
46
80
  catch (error) {
47
81
  // Don't leak the event listener if the backend failed to start the watcher.
48
82
  unlisten();
49
83
  throw error;
50
84
  }
85
+ // A change event that already arrived is at least as new as `current`;
86
+ // delivering `current` after it would roll the caller back to a stale value.
87
+ if (current !== null && current !== undefined && !changed) {
88
+ callback(current);
89
+ }
51
90
  return async () => {
52
91
  unlisten();
53
92
  await invoke('plugin:device-info|stop_watching', { kind });
@@ -73,5 +112,17 @@ function watchDisplay(callback, options) {
73
112
  function watchDevice(callback, options) {
74
113
  return watch('device', callback, options);
75
114
  }
115
+ /**
116
+ * Watch the power profile — fires when the profile, any reason, or the
117
+ * underlying battery/thermal/low-power readings change.
118
+ *
119
+ * @example
120
+ * const unwatch = await watchPowerProfile(({ profile }) => {
121
+ * animations.enabled = profile === 'full'
122
+ * })
123
+ */
124
+ function watchPowerProfile(callback, options) {
125
+ return watch('power', callback, options);
126
+ }
76
127
 
77
- export { getBatteryInfo, getDeviceInfo, getDisplayInfo, getNetworkInfo, getStorageInfo, watchBattery, watchDevice, watchDisplay, watchNetwork, watchStorage };
128
+ export { getBatteryInfo, getDeviceInfo, getDeviceTier, getDisplayInfo, getNetworkInfo, getPowerProfile, getStorageInfo, watchBattery, watchDevice, watchDisplay, watchNetwork, watchPowerProfile, watchStorage };
package/dist-js/type.d.ts CHANGED
@@ -27,6 +27,73 @@ export interface DisplayInfo {
27
27
  scaleFactor?: number;
28
28
  refreshRate?: number;
29
29
  }
30
+ /** Thermal pressure on Apple's four-level scale (other platforms are mapped onto it). */
31
+ export type ThermalState = 'nominal' | 'fair' | 'serious' | 'critical';
32
+ /**
33
+ * Recommended amount of work for the app right now:
34
+ * - `full` — no constraints, run at full quality
35
+ * - `balanced` — some pressure; skip non-essential work, lower animation/refresh rates
36
+ * - `saver` — heavy pressure; do the minimum, pause background work and effects
37
+ */
38
+ export type PowerProfileKind = 'full' | 'balanced' | 'saver';
39
+ /**
40
+ * Why the profile is not `full`:
41
+ * - `lowPowerMode` — OS power saving is on (→ saver)
42
+ * - `thermalCritical` / `thermalSerious` — device is hot (→ saver)
43
+ * - `thermalFair` — device is warm (→ balanced)
44
+ * - `batteryCritical` — on battery at ≤ 20% (→ saver)
45
+ * - `batteryLow` — on battery at ≤ 40% (→ balanced)
46
+ *
47
+ * "On battery" means not charging and not on external power; an unknown or
48
+ * implausible battery level never triggers a battery reason.
49
+ */
50
+ export type PowerProfileReason = 'lowPowerMode' | 'thermalCritical' | 'thermalSerious' | 'thermalFair' | 'batteryCritical' | 'batteryLow';
51
+ export interface PowerProfile {
52
+ /** The recommended profile — the most restrictive one implied by any reason. */
53
+ profile: PowerProfileKind;
54
+ /** Every condition pushing the profile below `full` (empty when `full`). */
55
+ reasons: PowerProfileReason[];
56
+ /** Battery level 0-100; absent on devices without a battery or when the level is unknown. */
57
+ batteryLevel?: number;
58
+ isCharging?: boolean;
59
+ /** Low Power Mode / Battery Saver / `low-power` profile; absent if the OS doesn't expose it. */
60
+ lowPowerMode?: boolean;
61
+ /** Absent where the OS has no thermal API (Windows). */
62
+ thermalState?: ThermalState;
63
+ /**
64
+ * Running on external power (AC adapter, USB-C charger), even when the
65
+ * battery isn't charging — e.g. full or held at a charge limit. Battery
66
+ * reasons never apply while this is `true`. Absent when the OS doesn't say.
67
+ */
68
+ onExternalPower?: boolean;
69
+ }
70
+ export interface HardwareInfo {
71
+ /** Logical CPU cores. */
72
+ cpuCores?: number;
73
+ /** Physical CPU cores (desktop only). */
74
+ physicalCores?: number;
75
+ /** CPU / SoC name, e.g. "Apple M2" or "iPhone15,2". */
76
+ cpuModel?: string;
77
+ /** Peak CPU clock in MHz, where available (not on iOS or Apple Silicon). */
78
+ cpuMaxFrequencyMhz?: number;
79
+ /** Total physical memory in bytes. */
80
+ totalMemory?: number;
81
+ /** Whether the tier was scored against mobile hardware. */
82
+ isMobile: boolean;
83
+ /** Android only: the OS flags this as a low-RAM device (forces tier `low`). */
84
+ isLowRamDevice?: boolean;
85
+ /** Android 12+ only: declared media performance class (31+ → at least `mid`, 33+ → `high`). */
86
+ mediaPerformanceClass?: number;
87
+ }
88
+ export type DeviceTierKind = 'low' | 'mid' | 'high';
89
+ export interface DeviceTier {
90
+ /** Capability class relative to devices of the same form factor. */
91
+ tier: DeviceTierKind;
92
+ /** 0 (weakest) – 100 (strongest). `low` < 30 ≤ `mid` < 65 ≤ `high`. */
93
+ score: number;
94
+ /** The hardware signals the score was computed from. */
95
+ hardware: HardwareInfo;
96
+ }
30
97
  /** Options for the reactive `watch*` APIs. */
31
98
  export interface WatchOptions {
32
99
  /**
@@ -37,6 +104,7 @@ export interface WatchOptions {
37
104
  * some values rarely change:
38
105
  * - `device`: defaults to 60000ms, floored at 10000ms (reads are costly and it barely changes)
39
106
  * - `storage`: defaults to 10000ms, floored at 1000ms
107
+ * - `power`: defaults to 5000ms, floored at 1000ms
40
108
  * - others: default 2000ms, floored at 250ms
41
109
  *
42
110
  * Only the first subscriber for a given kind sets the interval.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tauri-plugin-device-info-api",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "author": "edisdev<edisdev14@gmail.com>",
5
5
  "description": "A Tauri plugin to access device information.",
6
6
  "license": "MIT",
@@ -50,20 +50,20 @@
50
50
  ],
51
51
  "files": [
52
52
  "dist-js",
53
- "README.md"
53
+ "README.md",
54
+ "CHANGELOG.md"
54
55
  ],
55
- "scripts": {
56
- "build": "rollup -c",
57
- "prepublishOnly": "yarn build",
58
- "pretest": "yarn build"
59
- },
60
56
  "dependencies": {
61
- "@tauri-apps/api": "^2.0.0"
57
+ "@tauri-apps/api": "^2.12.5"
62
58
  },
63
59
  "devDependencies": {
64
- "@rollup/plugin-typescript": "^12.0.0",
65
- "rollup": "^4.9.6",
66
- "typescript": "^5.3.3",
67
- "tslib": "^2.6.2"
60
+ "@rollup/plugin-typescript": "^12.3.1",
61
+ "rollup": "^4.68.5",
62
+ "tslib": "^2.9.1",
63
+ "typescript": "^5.9.3"
64
+ },
65
+ "scripts": {
66
+ "build": "rollup -c",
67
+ "pretest": "pnpm build"
68
68
  }
69
69
  }
@@ -1,7 +0,0 @@
1
- {
2
- "recommendations": [
3
- "svelte.svelte-vscode",
4
- "tauri-apps.tauri-vscode",
5
- "rust-lang.rust-analyzer"
6
- ]
7
- }