M1.12: notifications as toasts
The host publishes picker, command-line and pump errors as notification events (Engine::notify, same id sequence) instead of stderr, keeps notifications and watchFailed published before engine_ready and replays them after the state replay, so startup warnings (corrupt settings, journal entries) reach the UI. ipc.ts announces engine_ready once all subscriptions started together are registered. Frontend: notifications store and NotificationStack (bottom right, info auto-dismissed after 5 s, warnings/errors stay, close button and Escape, at most 5 visible with "+n more", role status/alert); watchFailed maps to a warning toast; failed commands without their own UI raise an error toast. Catalog keys notification.settings.*, project.*, vfs.*, watch.*, command.* plus the runtime allow-list. Docs updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7b7273a947
commit
f41df518b5
21 changed files with 1178 additions and 94 deletions
|
|
@ -152,6 +152,30 @@ impl Engine {
|
|||
self.state.take_events()
|
||||
}
|
||||
|
||||
/// Queues an [`crate::Event::Notification`] from the host, such as an
|
||||
/// error after the folder picker closed, with a fresh id from the same
|
||||
/// sequence as the engine's own notifications, and takes the queued
|
||||
/// events.
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `level`: severity.
|
||||
/// - `message_key`: message-catalog key of the text.
|
||||
/// - `message`: English text, the fallback without a catalog entry.
|
||||
/// - `params`: interpolation params for the catalog text.
|
||||
///
|
||||
/// # Returns
|
||||
/// The queued events, oldest first, ending with the notification.
|
||||
pub fn notify(
|
||||
&mut self,
|
||||
level: NotificationLevel,
|
||||
message_key: Option<&str>,
|
||||
message: Option<String>,
|
||||
params: Option<serde_json::Map<String, Value>>,
|
||||
) -> Vec<crate::Event> {
|
||||
self.state.notify(level, message_key, message, params);
|
||||
self.state.take_events()
|
||||
}
|
||||
|
||||
/// Describes every command with its current enabled state. A command whose
|
||||
/// `enabled` check panics is listed as disabled.
|
||||
pub fn list_commands(&self) -> Vec<CommandInfo> {
|
||||
|
|
@ -218,6 +242,26 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn host_notifications_get_fresh_ids() {
|
||||
let mut engine = Engine::new().unwrap();
|
||||
let first = engine.notify(
|
||||
NotificationLevel::Error,
|
||||
Some("notification.project.openFailed"),
|
||||
Some("cannot open".into()),
|
||||
None,
|
||||
);
|
||||
let second = engine.notify(NotificationLevel::Info, None, Some("hi".into()), None);
|
||||
let id = |events: &[crate::Event]| match events.last() {
|
||||
Some(crate::Event::Notification { id, .. }) => id.clone(),
|
||||
other => panic!("not a notification: {other:?}"),
|
||||
};
|
||||
assert_eq!(first.len(), 1);
|
||||
assert_eq!(id(&first), "n1");
|
||||
assert_eq!(id(&second), "n2");
|
||||
assert!(engine.take_events().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn about_reports_product_information() {
|
||||
let mut engine = Engine::new().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue