Files
Lumotia/src-tauri/src/commands/nudges.rs
Jake 26c7307607
Some checks failed
check / cargo check (macos-latest) (push) Has been cancelled
check / cargo check (ubuntu-22.04) (push) Has been cancelled
check / cargo check (windows-latest) (push) Has been cancelled
check / svelte build + lint (push) Has been cancelled
agent: lumotia-rebrand — docs, scripts, root config, residuals
Phase 9 of the rebrand cascade. Sweep covers everything the Phase 8
frontend pass deliberately skipped: docs/, root markdown, scripts,
Cargo.toml descriptions, code comments that survived earlier
word-boundary sed, plus a handful of identifiers caught on the final
verify pass.

transcription-app changes:
- README.md, HANDOVER.md, KNOWN-ISSUES.md, run.sh — magnotia/Magnotia
  -> lumotia/Lumotia.
- docs/ — sweep across all subdirs except docs/handovers/ (preserved
  as immutable audit trail). Includes architecture-map references
  to magnotia_core::*, magnotia_storage::*, etc. now pointing at
  lumotia_*; dev-setup.md tracing output examples (lumotia_startup
  target); brief/ + superpowers/ + issues/ + whisper-ecosystem/ +
  audit/.
- Cargo.toml descriptions on 9 crates (core, audio, cloud-providers,
  hotkey, llm, mcp, plus referenced others).
- crates/core/src/{error,hardware,recommendation,paths}.rs +
  crates/audio/src/wav.rs + crates/llm/src/model_manager.rs +
  crates/cloud-providers/src/keystore.rs + crates/mcp/src/lib.rs —
  doc comments and a model-manager user-agent string.
- Caught on final pass: BroadcastChannel("magnotia_task_sync") -> ...
  ("lumotia_task_sync"); magnotia_locale i18n localStorage key
  renamed + migration shim added; CSS keyframe names
  magnotiaPulse / magnotiaBar / magnotiaFade renamed in the design-
  system kit; magnotia_viewer_item / magnotia_viewer_mode handoff
  keys renamed in HistoryPage + viewer/+page.svelte; src/assets/
  wordmark.svg text.
- src-tauri/src/lib.rs comment cleanup ("magnotia era" was sed'd
  to "lumotia era" earlier — restored).

Preserved (intentional):
- crates/core/src/paths.rs — keeps "magnotia" / "Magnotia" / ".magnotia"
  legacy detection strings in legacy_and_target_paths() so the
  migration shim can still find user data from the magnotia era.
- src/lib/stores/{page,focusTimer}.svelte.ts + src/lib/i18n/index.ts
  — migration call sites reference the legacy magnotia keys
  deliberately.
- docs/handovers/ — historical audit trail.

cargo build --workspace passes. npm run check: 0 errors / 0 warnings
(3958 files). cargo test --workspace: 339 pass / 0 fail.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 12:38:03 +01:00

64 lines
2.4 KiB
Rust

//! Phase 6 of the feature-complete roadmap: Margot soft-touch nudges.
//!
//! The nudge bus lives in the frontend (`nudgeBus.svelte.ts`) — it
//! owns trigger subscription, suppression rules, and the hourly cap.
//! This module is the thin Rust side that:
//!
//! - Guards delivery to the main window only (secondary windows like
//! the task float can't fire notifications at the user — they're
//! already beside the user's attention).
//! - Delegates to `tauri-plugin-notification` for cross-platform OS
//! delivery. The plugin handles the macOS Notification Center /
//! Linux org.freedesktop.Notifications / Windows toast plumbing.
//!
//! Permission handling happens on the JS side via the plugin's
//! `isPermissionGranted` / `requestPermission` API — before the first
//! `deliver_nudge` call, the nudge bus prompts the user. If denied,
//! subsequent calls return an error that the bus logs and swallows.
//!
//! No persistence for v1. Cooldown state is ephemeral; the roadmap's
//! nudge-audit table is deferred until a real need emerges.
use serde::Deserialize;
use tauri_plugin_notification::NotificationExt;
use crate::commands::security::ensure_main_window;
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DeliverNudgeInput {
pub title: String,
pub body: String,
}
/// Deliver a single OS notification. Does not apply suppression
/// logic — the frontend nudge bus is responsible for cadence and
/// cooldown, so this command is a blunt "push it now" primitive.
///
/// Returns an error if the notification plugin refuses the call
/// (typically because permission was denied by the user at the OS
/// level). The nudge bus logs and swallows these — nudges are
/// fire-and-forget and must never surface errors to the user.
#[tauri::command]
pub fn deliver_nudge(
app: tauri::AppHandle,
window: tauri::WebviewWindow,
input: DeliverNudgeInput,
) -> Result<(), String> {
ensure_main_window(&window)?;
let title = input.title.trim();
let body = input.body.trim();
if title.is_empty() && body.is_empty() {
// A blank nudge is worse than no nudge — stay quiet.
return Ok(());
}
app.notification()
.builder()
.title(if title.is_empty() { "Lumotia" } else { title })
.body(body)
.show()
.map_err(|e| format!("notification delivery failed: {e}"))
}