Emit bread.help.opened when the main window is shown
All checks were successful
dev release / build (push) Successful in 2m4s

Fail-silent via bread-utils BreadClient (ecosystem v0.7.1, bread-client).
No command verbs. Silent autostart and screenshot mode do not emit.
This commit is contained in:
Breadway 2026-08-15 22:16:30 +08:00
parent 3634edef0d
commit c9445fadcc
6 changed files with 90 additions and 6 deletions

View file

@ -1,6 +1,23 @@
//! Maps a `--suggest <id>` payload (sent by a breadd Lua module, e.g.
//! `breadhelp-suggest.lua` reacting to `bread.monitor.connected`) to Home
//! tab banner text.
//! Bread bus integration. `--suggest` banners stay local; `bread.help.*`
//! emits are optional and fail-silent. See `EVENTS.md`.
//!
//! `BreadClient::emit` never blocks or errors this process — a missing or
//! restarting breadd must not affect the help center itself.
use bread_utils::bread_client::BreadClient;
/// Sibling-app id in `bread_shared::apps::KNOWN_APPS`. Events publish as
/// `bread.help.*`. There is no command subscription.
pub const APP_ID: &str = "help";
/// Fire-and-forget `bread.help.opened` after the main window is actually
/// shown. Silent autostart (window built, not presented) does not call this.
pub fn emit_opened(autostart: bool) {
BreadClient::connect(APP_ID).emit(
"bread.help.opened",
serde_json::json!({ "autostart": autostart }),
);
}
pub struct Suggestion {
pub text: String,

View file

@ -63,7 +63,7 @@ pub fn present(app: &Application, action: Action) {
// (i.e. breadhelp wasn't already running) — a background daemon
// event shouldn't steal focus from whatever the user is doing.
if just_built {
handle.window.present();
show_window(&handle.window, action.autostart);
}
return;
}
@ -77,11 +77,19 @@ pub fn present(app: &Application, action: Action) {
}
let silent_autostart = action.autostart && State::load().onboarding_completed();
if !silent_autostart {
handle.window.present();
show_window(&handle.window, action.autostart);
}
});
}
/// Present the help window and publish `bread.help.opened`. Screenshot
/// mode calls `window.present()` itself and must not go through here —
/// that is capture, not a user-visible open.
fn show_window(window: &ApplicationWindow, autostart: bool) {
window.present();
crate::services::breadd::emit_opened(autostart);
}
fn build(app: &Application) -> Handle {
// First thing on every cold start: revert any keybind a previous,
// crashed run may have left temporarily rebound mid tour-step (see