Skip to content

desktop/src-tauri/src/app_state.rs

Comment 1, line 1

desktop/src-tauri/src/app_state.rs:1

//! Application state: one storage writer, local source-host identity, settings and collection status.

Comment 2, line 2

desktop/src-tauri/src/app_state.rs:2

//! GUI/headless share configuration and collection state (M6). Serialize writes through a Mutex;

Comment 3, line 3

desktop/src-tauri/src/app_state.rs:3

//! queries prefer pooled/read-only connections and fall back to the writer when those are unavailable.

Comment 4, line 11

desktop/src-tauri/src/app_state.rs:11

/// Retention in days: details 7, hours 3, days 90, weeks 1095,

Comment 5, line 12

desktop/src-tauri/src/app_state.rs:12

/// months 3650 and yearly None for lifetime retention.

Comment 6, line 36

desktop/src-tauri/src/app_state.rs:36

/// Provider pricing preferences: exact channels first; unknown channels permit only an unambiguous same-model official reference.

Comment 7, line 42

desktop/src-tauri/src/app_state.rs:42

/// Default cache-write TTL in minutes: 5/60, or None to leave cache writes unpriced.

Comment 8, line 47

desktop/src-tauri/src/app_state.rs:47

/// Cost estimation settings; estimates and usage-limit reminders default off.

Comment 9, line 54

desktop/src-tauri/src/app_state.rs:54

/// models.dev online refresh defaults off; enabling it permits only the public HTTPS price request.

Comment 10, line 57

desktop/src-tauri/src/app_state.rs:57

/// Raw-response cache TTL: default 3 days, range 1-365; fresh caches avoid requests.

Comment 11, line 62

desktop/src-tauri/src/app_state.rs:62

/// Explicit Default avoids deriving online_cache_ttl_days as u32 zero,

Comment 12, line 63

desktop/src-tauri/src/app_state.rs:63

/// which made new installations/settings without pricing display zero instead of the required three days.

Comment 13, line 80

desktop/src-tauri/src/app_state.rs:80

/// Convert to core estimate options with case-normalized provider keys.

Comment 14, line 98

desktop/src-tauri/src/app_state.rs:98

/// Persistent user-visible settings; application language starts as zh-CN.

Comment 15, line 102

desktop/src-tauri/src/app_state.rs:102

/// None follows locale: Monday for zh and other locales, Sunday for en-US/CA.

Comment 16, line 104

desktop/src-tauri/src/app_state.rs:104

/// Tiered archive retention.

Comment 17, line 107

desktop/src-tauri/src/app_state.rs:107

/// Collection interval in seconds: zero disables automatic collection; default one hour.

Comment 18, line 117

desktop/src-tauri/src/app_state.rs:117

/// Theme: system, light or dark.

Comment 19, line 120

desktop/src-tauri/src/app_state.rs:120

/// User-added source roots.

Comment 20, line 123

desktop/src-tauri/src/app_state.rs:123

/// Explicitly restrict discovery to configured roots, including OS launches.

Comment 21, line 126

desktop/src-tauri/src/app_state.rs:126

/// Local host display alias; does not change host_id.

Comment 22, line 129

desktop/src-tauri/src/app_state.rs:129

/// M5 local OTLP receiver, optional and off by default, bound to 127.0.0.1.

Comment 23, line 134

desktop/src-tauri/src/app_state.rs:134

/// F2 cost estimation, off by default; cost panels appear only when enabled.

Comment 24, line 184

desktop/src-tauri/src/app_state.rs:184

/// Prefer explicit week start; otherwise Monday for zh/other locales and Sunday for en-US/CA.

Comment 25, line 185

desktop/src-tauri/src/app_state.rs:185

/// Core accepts only zero or six.

Comment 26, line 203

desktop/src-tauri/src/app_state.rs:203

/// OS username for the initial user display name.

Comment 27, line 204

desktop/src-tauri/src/app_state.rs:204

/// Read USERNAME, then USER; unavailable/empty/default values fall back to default.

Comment 28, line 217

desktop/src-tauri/src/app_state.rs:217

// If TZ is absent, use jiff system IANA timezone discovery, including Windows; absence falls back to UTC.

Comment 29, line 224

desktop/src-tauri/src/app_state.rs:224

/// Observable collection state for UI polling, with progress by source instance.

Comment 30, line 231

desktop/src-tauri/src/app_state.rs:231

/// Instance summaries: instance, status, event count and diagnostic count.

Comment 31, line 233

desktop/src-tauri/src/app_state.rs:233

/// Collection percentage and estimated remaining seconds for UI polling.

Comment 32, line 236

desktop/src-tauri/src/app_state.rs:236

/// Completed adapter names in order.

Comment 33, line 238

desktop/src-tauri/src/app_state.rs:238

/// A manual refresh received during a running scan is consumed once afterward.

Comment 34, line 241

desktop/src-tauri/src/app_state.rs:241

/// Only full scans reset the inherited global cadence, never source-only runs.

Comment 35, line 270

desktop/src-tauri/src/app_state.rs:270

/// Current statistics user (v6), stored in settings with the default key as fallback.

Comment 36, line 272

desktop/src-tauri/src/app_state.rs:272

/// Background clear-all/recollection flag prevents duplicate starts without blocking the UI.

Comment 37, line 275

desktop/src-tauri/src/app_state.rs:275

/// F2 models.dev refresh state: running flag and latest outcome for UI polling.

Comment 38, line 280

desktop/src-tauri/src/app_state.rs:280

/// Open the application database and initialize host identity/settings; handle incompatible schemas explicitly.

Comment 39, line 285

desktop/src-tauri/src/app_state.rs:285

// Prerelease databases have no automatic version migration; prompt to rebuild or exit on mismatch.

Comment 40, line 311

desktop/src-tauri/src/app_state.rs:311

// Take a consistent backup before rebuilding; backup failure or insufficient space aborts deletion (M1/V15).

Comment 41, line 332

desktop/src-tauri/src/app_state.rs:332

// F2 seed-price import is repeatable local metadata; report failure without stopping collection.

Comment 42, line 339

desktop/src-tauri/src/app_state.rs:339

// Repair historical UTC day partitions when the selected statistics timezone differs.

Comment 43, line 340

desktop/src-tauri/src/app_state.rs:340

// Recompute retained events in the selected timezone (2026-09-26 repair).

Comment 44, line 342

desktop/src-tauri/src/app_state.rs:342

// On first initialization, use the OS username rather than the default display name.

Comment 45, line 343

desktop/src-tauri/src/app_state.rs:343

// Rename the initial v6 default user while retaining its user_id

Comment 46, line 344

desktop/src-tauri/src/app_state.rs:344

// and source ownership.

Comment 47, line 357

desktop/src-tauri/src/app_state.rs:357

// Initially rename default to the OS username, or create the user.

Comment 48, line 399

desktop/src-tauri/src/app_state.rs:399

/// Rebuild from retained event times when timezone partitions or hourly-field rules need repair.

Comment 49, line 400

desktop/src-tauri/src/app_state.rs:400

/// Skip sealed days through core recomputation; propagate failures to the caller.

Comment 50, line 433

desktop/src-tauri/src/app_state.rs:433

// F2 remove superseded unsealed daily costs for other timezones; retain sealed historical

Comment 51, line 434

desktop/src-tauri/src/app_state.rs:434

// amounts. Later collection/explicit recomputation rebuilds the current timezone.

Comment 52, line 453

desktop/src-tauri/src/app_state.rs:453

/// Prefer pooled/read-only queries, with short retries for transient open errors.

Comment 53, line 454

desktop/src-tauri/src/app_state.rs:454

/// If all read-only attempts fail, queue on the writer Mutex rather than reject the query immediately.

Comment 54, line 511

desktop/src-tauri/src/app_state.rs:511

// Normalize historical zero cache TTL, invalid outside the 1-365-day range.

Comment 55, line 512

desktop/src-tauri/src/app_state.rs:512

// Fall back to the default for zero/out-of-range values; preserve valid user selections.

Comment 56, line 538

desktop/src-tauri/src/app_state.rs:538

/// Convert source run reports to UI summaries.

Comment 57, line 581

desktop/src-tauri/src/app_state.rs:581

// Simulate historical derived-Default zero; loading restores three days without changing other settings.