agent-desktop/src/dispatch_notifications.rs
Lahfir 8aa672c668 refactor: resolve code review findings from notification PR
- fix(core): wait --notification uses index-diff detection instead of
  count, passes text filter, checks deadline before sleep
- fix(core): dismiss-all-notifications uses single NC session with
  batch adapter method and reports individual failures
- refactor(macos): extract dismiss_entry helper to eliminate duplicate
  dismiss logic between single and batch operations
- refactor(macos): restrict nc_session visibility to pub(crate), use
  absolute paths for pgrep/osascript, add bounded wait with kill
  fallback
- refactor(macos): single-pass is_notification_group check using
  matches! macro
- refactor: extract notification CLI args and dispatch into separate
  files to keep cli_args.rs and dispatch.rs under 400 LOC
- refactor: rename DismissAllNotificationsArgs to
  DismissAllNotificationsCliArgs for consistency
- fix(core): remove unused timestamp field from NotificationInfo
- fix: remove poll_interval_ms from wait command (hardcode 500ms)
- docs: update phases.md with completed notification status and
  cross-platform reference notes
2026-02-27 12:42:46 -08:00

45 lines
1.4 KiB
Rust

use agent_desktop_core::{
adapter::PlatformAdapter,
commands::{
dismiss_all_notifications, dismiss_notification, list_notifications, notification_action,
},
error::AppError,
};
use serde_json::Value;
use crate::cli::Commands;
pub fn dispatch_notification(
cmd: Commands,
adapter: &dyn PlatformAdapter,
) -> Result<Value, AppError> {
match cmd {
Commands::ListNotifications(a) => list_notifications::execute(
list_notifications::ListNotificationsArgs {
app: a.app,
text: a.text,
limit: a.limit,
},
adapter,
),
Commands::DismissNotification(a) => dismiss_notification::execute(
dismiss_notification::DismissNotificationArgs {
index: a.index as usize,
app: a.app,
},
adapter,
),
Commands::DismissAllNotifications(a) => dismiss_all_notifications::execute(
dismiss_all_notifications::DismissAllNotificationsArgs { app: a.app },
adapter,
),
Commands::NotificationAction(a) => notification_action::execute(
notification_action::NotificationActionArgs {
index: a.index as usize,
action: a.action,
},
adapter,
),
_ => unreachable!(),
}
}