fix(linux): restore notification lifecycle
cx
This commit is contained in:
2 files changed
+20
-7
No files matched your search
@@ -272,9 +272,15 @@ pub async fn show_track_notification(meta: NotificationMeta, offline: bool) {
|
||||
.fetch_add(1, Ordering::AcqRel)
|
||||
.wrapping_add(1);
|
||||
|
||||
// One stable id intentionally replaces the previous track toast. The
|
||||
// portal normally treats that as an in-place update, which Plasma does
|
||||
// not animate as a new banner after the first track. `show-as-new` is
|
||||
// the portal's explicit contract for a replacement that must be
|
||||
// presented again. It must not be combined with `transient`; stop,
|
||||
// opt-out and shutdown withdraw the replaceable notification below.
|
||||
let mut notification = PortalNotification::new(&meta.title)
|
||||
.body(Some(body.as_str()))
|
||||
.display_hint([DisplayHint::Transient]);
|
||||
.display_hint([DisplayHint::ShowAsNew]);
|
||||
|
||||
if let Some(url) = meta.art_url.clone() {
|
||||
let prepared = tokio::task::spawn_blocking(move || -> Result<Vec<u8>, String> {
|
||||
@@ -299,11 +305,12 @@ pub async fn show_track_notification(meta: NotificationMeta, offline: bool) {
|
||||
log::debug!("[notify] stale track notification discarded");
|
||||
return;
|
||||
}
|
||||
if let Err(e) = proxy
|
||||
match proxy
|
||||
.add_notification(PORTAL_NOTIFICATION_ID, notification)
|
||||
.await
|
||||
{
|
||||
log::warn!("[notify] XDG portal add_notification failed: {e}");
|
||||
Ok(()) => log::debug!("[notify] XDG portal notification published"),
|
||||
Err(e) => log::warn!("[notify] XDG portal add_notification failed: {e}"),
|
||||
}
|
||||
}
|
||||
Err(e) => log::warn!("[notify] XDG notification portal unavailable: {e}"),
|
||||
|
||||
@@ -3481,12 +3481,18 @@ fn main() {
|
||||
// playing for two seconds longer is a far smaller failure than an app
|
||||
// that cannot be closed, so the timeout wins the tie.
|
||||
if let Some(rt) = TOKIO.get() {
|
||||
let notification_withdrawn = rt
|
||||
.block_on(tokio::time::timeout(
|
||||
// Construct the timer *inside* the runtime. Building
|
||||
// `tokio::time::timeout` as the argument to `block_on` happens
|
||||
// before the runtime is entered and panics with "no reactor
|
||||
// running" during every normal quit.
|
||||
let notification_withdrawn = rt.block_on(async {
|
||||
tokio::time::timeout(
|
||||
std::time::Duration::from_secs(1),
|
||||
qbz_media_controls::withdraw_track_notification(),
|
||||
))
|
||||
.is_ok();
|
||||
)
|
||||
.await
|
||||
});
|
||||
let notification_withdrawn = notification_withdrawn.is_ok();
|
||||
if !notification_withdrawn {
|
||||
log::warn!(
|
||||
"[qbz-qt] notification withdrawal did not finish within 1s; exiting anyway"
|
||||
|
||||
Reference in new issue
Block a user