From 1252ca0a1b261a9b3182cdfbcad97ad6ad45256c Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Fri, 30 May 2025 15:31:25 +0200 Subject: [PATCH] window: Inhibit system suspend during playback --- po/de.po | 16 ++++++++++------ po/template.pot | 16 ++++++++++------ src/window.rs | 25 ++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/po/de.po b/po/de.po index 57c58a9..f95d221 100644 --- a/po/de.po +++ b/po/de.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-04-27 17:54+0200\n" +"POT-Creation-Date: 2025-05-30 15:27+0200\n" "PO-Revision-Date: 2025-04-27 18:23+0200\n" "Last-Translator: elias@johrpan.de\n" "Language-Team: German \n" @@ -818,7 +818,7 @@ msgstr "Bibliothek exportieren" msgid "Exporting music library to {}" msgstr "Bibliothek wird nach {} exportiert" -#: src/library_manager.rs:234 src/window.rs:282 +#: src/library_manager.rs:234 src/window.rs:305 msgid "Updating metadata" msgstr "Metadaten werden aktualisiert" @@ -826,19 +826,23 @@ msgstr "Metadaten werden aktualisiert" msgid "Updating music library" msgstr "Musikbibliothek wird aktualisiert" -#: src/window.rs:167 +#: src/window.rs:166 +msgid "Currently playing music" +msgstr "Musik wird abgespielt" + +#: src/window.rs:190 msgid "Close window?" msgstr "Fenster schließen?" -#: src/window.rs:169 +#: src/window.rs:192 msgid "There are ongoing processes that will be canceled." msgstr "Es gibt laufende Prozesse, die abgebrochen werden." -#: src/window.rs:174 +#: src/window.rs:197 msgid "Keep open" msgstr "Nicht schließen" -#: src/window.rs:175 +#: src/window.rs:198 msgid "Close window" msgstr "Fenster schließen" diff --git a/po/template.pot b/po/template.pot index 03c8554..e47fe6b 100644 --- a/po/template.pot +++ b/po/template.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-04-27 17:54+0200\n" +"POT-Creation-Date: 2025-05-30 15:27+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -784,7 +784,7 @@ msgstr "" msgid "Exporting music library to {}" msgstr "" -#: src/library_manager.rs:234 src/window.rs:282 +#: src/library_manager.rs:234 src/window.rs:305 msgid "Updating metadata" msgstr "" @@ -792,18 +792,22 @@ msgstr "" msgid "Updating music library" msgstr "" -#: src/window.rs:167 +#: src/window.rs:166 +msgid "Currently playing music" +msgstr "" + +#: src/window.rs:190 msgid "Close window?" msgstr "" -#: src/window.rs:169 +#: src/window.rs:192 msgid "There are ongoing processes that will be canceled." msgstr "" -#: src/window.rs:174 +#: src/window.rs:197 msgid "Keep open" msgstr "" -#: src/window.rs:175 +#: src/window.rs:198 msgid "Close window" msgstr "" diff --git a/src/window.rs b/src/window.rs index ce2f4ab..b263423 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1,4 +1,7 @@ -use std::{cell::RefCell, path::Path}; +use std::{ + cell::{Cell, RefCell}, + path::Path, +}; use adw::{prelude::*, subclass::prelude::*}; use anyhow::{anyhow, Result}; @@ -31,6 +34,7 @@ mod imp { pub library: RefCell>, pub player: Player, pub process_manager: ProcessManager, + pub inhibitor_cookie: Cell>, #[template_child] pub toast_overlay: TemplateChild, @@ -148,6 +152,25 @@ mod imp { let obj = self.obj().to_owned(); self.player.connect_raise(move |_| obj.present()); + let obj = self.obj().to_owned(); + self.player.connect_playing_notify(move |player| { + if let Some(app) = obj.application() { + if let Some(cookie) = obj.imp().inhibitor_cookie.take() { + app.uninhibit(cookie); + }; + + if player.playing() { + let cookie = app.inhibit( + Some(&obj), + gtk::ApplicationInhibitFlags::SUSPEND, + Some(&gettext("Currently playing music")), + ); + + obj.imp().inhibitor_cookie.set(Some(cookie)); + } + } + }); + let settings = gio::Settings::new(config::APP_ID); let library_path = settings.string("library-path").to_string(); if !library_path.is_empty() {