Repository: aome510/spotify-player (language: rust)

Issue:
Make notification timeout configurable
**Is your feature already implemented in the latest `master`?**

No.

**Is your feature request related to a problem? Please describe.**

Sort of. The notifications just keep piling up and I wish they would disappear after a while.

![Screenshot-2024-04-16-095958](https://github.com/aome510/spotify-player/assets/51264/f746f9ca-352b-4427-b072-62ba3588dfa9)

**Describe the solution you'd like**

It would be great if the notification timeout would be configurable. The [crate itself](https://docs.rs/notify-rust/latest/notify_rust/#example-1-simple-notification) does have support for it.

**Describe alternatives you've considered**

None yet. I could just watch for the notifications and dismiss them via a script. :grin: 

**Additional context**

Using version 0.15.2 on a Sway desktop with Mako notifications.


Discussion / hints:

Fix patch:
diff --git a/docs/config.md b/docs/config.md
index 5f586ec6..842ff770 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -28,6 +28,7 @@ All configuration files should be placed inside the application's configuration
 | `tracks_playback_limit`           | the limit for the number of tracks played in a **tracks** playback                       | `50`                                                                                                             |
 | `playback_format`                 | the format of the text in the playback's window                                          | `{track} • {artists}\n{album}\n{metadata}`                                                                       |
 | `notify_format`                   | the format of a notification (`notify` feature only)                                     | `{ summary = "{track} • {artists}", body = "{album}" }`                                                          |
+| `notify_timeout_in_secs`          | the timeout (in seconds) of a notification (`notify` feature only)                       | `0` (no timeout)                                                                                                 |
 | `copy_command`                    | the command used to execute a copy-to-clipboard action                                   | depends on the OS, see [example config](https://github.com/aome510/spotify-player/blob/master/examples/app.toml) |
 | `paste_command`                   | the command used to get clipboard's content                                              | depends on the OS, see [example config](https://github.com/aome510/spotify-player/blob/master/examples/app.toml) |
 | `player_event_hook_command`       | the hook command executed when there is a new player event                               | `None`                                                                                                           |
diff --git a/examples/app.toml b/examples/app.toml
index c35f3128..3e9c40a9 100644
--- a/examples/app.toml
+++ b/examples/app.toml
@@ -4,6 +4,7 @@ client_port = 8080
 tracks_playback_limit = 50
 playback_format = "{track} • {artists}\n{album}\n{metadata}"
 notify_format = { summary = "{track} • {artists}", body = "{album}" }
+notify_timeout_in_secs = 0
 # the default `copy_command` is based on the OS
 # copy_command = { command = "pbcopy" } # macos
 # copy_command = { command = "xclip", args = ["-sel", "c"] } # linux
diff --git a/spotify_player/src/client/mod.rs b/spotify_player/src/client/mod.rs
index 854c1493..a2af442c 100644
--- a/spotify_player/src/client/mod.rs
+++ b/spotify_player/src/client/mod.rs
@@ -1525,6 +1525,12 @@ impl Client {
                 &state.configs.app_config.notify_format.body,
             ));
 
+        if state.configs.app_config.notify_timeout_in_secs > 0 {
+            n.timeout(std::time::Duration::from_secs(
+                state.configs.app_config.notify_timeout_in_secs,
+            ));
+        }
+
         n.show()?;
 
         Ok(())
diff --git a/spotify_player/src/config/mod.rs b/spotify_player/src/config/mod.rs
index 1ad2c106..086b022c 100644
--- a/spotify_player/src/config/mod.rs
+++ b/spotify_player/src/config/mod.rs
@@ -33,6 +33,8 @@ pub struct AppConfig {
     pub playback_format: String,
     #[cfg(feature = "notify")]
     pub notify_format: NotifyFormat,
+    #[cfg(feature = "notify")]
+    pub notify_timeout_in_secs: u64,
 
     pub tracks_playback_limit: usize,
 
@@ -187,6 +189,8 @@ impl Default for AppConfig {
                 summary: String::from("{track} • {artists}"),
                 body: String::from("{album}"),
             },
+            #[cfg(feature = "notify")]
+            notify_timeout_in_secs: 0,
 
             #[cfg(target_os = "macos")]
             copy_command: Command {
diff --git a/spotify_player/src/ui/playback.rs b/spotify_player/src/ui/playback.rs
index 090c20cc..dffcc4d8 100644
--- a/spotify_player/src/ui/playback.rs
+++ b/spotify_player/src/ui/playback.rs
@@ -228,7 +228,7 @@ fn render_playback_text(
         playback_text.lines.push(Line::from(spans));
     }
 
-    let playback_desc = Paragraph::new(playback_text).wrap(Wrap { trim: true });
+    let playback_desc = Paragraph::new(playback_text).wrap(Wrap { trim: false });
 
     frame.render_widget(playback_desc, rect);
 }


Test patch: