refactor(calendar): split import_pst into a reusable core fn

import_pst_core takes &AppHandle/&dyn Store directly instead of the
State<AppState> extractor, so the startup auto-sync pass (lib.rs) can
run the same import logic without going through a Tauri command.
This commit is contained in:
iamdoubz
2026-07-06 14:55:34 -05:00
parent 75ec24ddf6
commit 871b11d75e
+19 -6
View File
@@ -60,6 +60,8 @@ fn default_settings() -> Settings {
sync_enabled: false,
retention_max_age_days: None,
retention_max_size_gb: None,
pst_last_path: None,
pst_auto_sync: false,
}
}
@@ -1947,10 +1949,12 @@ pub async fn confirm_action_items(
/// progress, so `pst://progress` is a start/done signal rather than
/// per-item — real per-item progress would mean reimplementing readpst's
/// internals, not worth it for a one-shot import.
#[tauri::command]
pub async fn import_pst(
app: AppHandle,
state: State<'_, AppState>,
///
/// Split from the `#[tauri::command]` wrapper so the startup auto-sync pass
/// (T6.2, `pst_auto_sync`) can call the same logic without a `State` extractor.
pub(crate) async fn import_pst_core(
app: &AppHandle,
store: &dyn crate::storage::Store,
path: String,
password: Option<String>,
) -> WaResult<u32> {
@@ -1967,8 +1971,7 @@ pub async fn import_pst(
serde_json::json!({ "processed": 0, "total": total }),
);
let imported = state
.store
let imported = store
.import_calendar_events(events)
.await
.map_err(|e| WaError::new("storage", e.to_string()))?;
@@ -1980,6 +1983,16 @@ pub async fn import_pst(
Ok(imported)
}
#[tauri::command]
pub async fn import_pst(
app: AppHandle,
state: State<'_, AppState>,
path: String,
password: Option<String>,
) -> WaResult<u32> {
import_pst_core(&app, state.store.as_ref(), path, password).await
}
/// Browse imported calendar events (T6.3, FR-CAL-2).
#[tauri::command]
pub async fn list_calendar_events(