|
15 | 15 | //! same single `statfs` per tick with the permanent watcher. |
16 | 16 |
|
17 | 17 | use log::{debug, info, warn}; |
18 | | -use serde::Serialize; |
| 18 | +use serde::{Deserialize, Serialize}; |
19 | 19 | use std::collections::HashMap; |
20 | 20 | use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; |
21 | 21 | use std::sync::{Mutex, OnceLock}; |
22 | 22 | use std::time::Duration; |
23 | 23 | use tauri::{AppHandle, Emitter}; |
| 24 | +use tauri_specta::Event; |
24 | 25 |
|
25 | 26 | use crate::file_system::get_volume_manager; |
26 | 27 | use crate::file_system::volume::DEFAULT_VOLUME_ID; |
@@ -84,13 +85,16 @@ struct CachedSpace { |
84 | 85 | available_bytes: u64, |
85 | 86 | } |
86 | 87 |
|
87 | | -/// Payload for the `volume-space-changed` Tauri event. |
88 | | -#[derive(Clone, Serialize)] |
| 88 | +/// Typed `volume-space-changed` Tauri event. The struct name kebab-cases to the |
| 89 | +/// wire event name (`volume-space-changed`) via `tauri_specta::Event`. Both the |
| 90 | +/// TS payload type and a typed `events.volumeSpaceChanged.listen(...)` helper are |
| 91 | +/// generated into `apps/desktop/src/lib/ipc/bindings.ts`. |
| 92 | +#[derive(Clone, Serialize, Deserialize, specta::Type, Event)] |
89 | 93 | #[serde(rename_all = "camelCase")] |
90 | | -struct VolumeSpaceChangedPayload { |
91 | | - volume_id: String, |
92 | | - total_bytes: u64, |
93 | | - available_bytes: u64, |
| 94 | +pub struct VolumeSpaceChanged { |
| 95 | + pub volume_id: String, |
| 96 | + pub total_bytes: u64, |
| 97 | + pub available_bytes: u64, |
94 | 98 | } |
95 | 99 |
|
96 | 100 | /// Payload for the `low-disk-space` Tauri event. |
@@ -385,13 +389,13 @@ fn update_cache(volume_id: &str, space: &CachedSpace) { |
385 | 389 |
|
386 | 390 | fn emit(volume_id: &str, space: &CachedSpace) { |
387 | 391 | let Some(app) = APP_HANDLE.get() else { return }; |
388 | | - let payload = VolumeSpaceChangedPayload { |
| 392 | + let payload = VolumeSpaceChanged { |
389 | 393 | volume_id: volume_id.to_string(), |
390 | 394 | total_bytes: space.total_bytes, |
391 | 395 | available_bytes: space.available_bytes, |
392 | 396 | }; |
393 | 397 | debug!("volume-space-changed: {} ({} avail)", volume_id, space.available_bytes); |
394 | | - if let Err(e) = app.emit("volume-space-changed", &payload) { |
| 398 | + if let Err(e) = payload.emit(app) { |
395 | 399 | warn!("Failed to emit volume-space-changed: {}", e); |
396 | 400 | } |
397 | 401 | } |
|
0 commit comments