forked from Furumi/furumi-tui
Show both keymap notice and logging warning at startup
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
78bf2cf583
commit
595c886303
3 files changed
+49
-8
No files matched your search
+38
-5
@@ -93,6 +93,17 @@ fn now_epoch_seconds() -> i64 {
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
/// Joins two optional startup status messages with `; `, keeping both.
|
||||
pub(crate) fn join_status_messages(
|
||||
first: Option<String>,
|
||||
second: Option<String>,
|
||||
) -> Option<String> {
|
||||
match (first, second) {
|
||||
(Some(left), Some(right)) => Some(format!("{left}; {right}")),
|
||||
(left, right) => left.or(right),
|
||||
}
|
||||
}
|
||||
|
||||
fn err_string(err: anyhow::Error) -> String {
|
||||
format!("{err:#}")
|
||||
}
|
||||
@@ -394,11 +405,7 @@ pub async fn run(
|
||||
tracing::info!(path = %db_path.display(), "library opened");
|
||||
|
||||
let (settings, settings_warning) = crate::config::settings::load();
|
||||
let status_message = match (startup_warning, settings_warning) {
|
||||
(Some(left), Some(right)) => Some(format!("{left}; {right}")),
|
||||
(Some(message), None) | (None, Some(message)) => Some(message),
|
||||
(None, None) => None,
|
||||
};
|
||||
let status_message = join_status_messages(startup_warning, settings_warning);
|
||||
let mut state = AppState {
|
||||
status_message,
|
||||
..AppState::default()
|
||||
@@ -4491,3 +4498,29 @@ fn push_media_metadata(state: &AppState, runtime: &Runtime) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod status_message_tests {
|
||||
use super::join_status_messages;
|
||||
|
||||
#[test]
|
||||
fn startup_messages_are_joined_not_dropped() {
|
||||
assert_eq!(
|
||||
join_status_messages(
|
||||
Some("keymap notice".into()),
|
||||
Some("logging disabled: x".into())
|
||||
)
|
||||
.as_deref(),
|
||||
Some("keymap notice; logging disabled: x")
|
||||
);
|
||||
assert_eq!(
|
||||
join_status_messages(None, Some("only".into())).as_deref(),
|
||||
Some("only")
|
||||
);
|
||||
assert_eq!(
|
||||
join_status_messages(Some("only".into()), None).as_deref(),
|
||||
Some("only")
|
||||
);
|
||||
assert_eq!(join_status_messages(None, None), None);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user