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

Issue:
Configuration option to disable notifications
**Is your feature request related to a problem? Please describe.**
No way to disable notifications in the configuration.

**Describe the solution you'd like**
Would be great to have a configuration option that would allow to disable all notifications from spotify_player.

**Describe alternatives you've considered**
Manually installing using cargo without `notify` feature is an alternative, however, it's not very convenient.

**Additional context**
spotify_player notifications on MacOS are a bit ugly (using Finder icon). Also, I try to limit to a minimum the amount of the notifications I get.



Discussion / hints:
Related: https://github.com/aome510/spotify-player/issues/292. This issue seems to be specific to the brew package manager as it installs the application with `notify` feature when the feature is disabled by default.
@aome510 thanks for reply!
is it disabled by default specifically because it has some issues?
Generally, I feel like hiding features behind compilation flags instead of configurations is a bit inconvenient, since you either have to rely on defaults provided by the packager or resort to compiling the project yourself. Is there a specific reason for this?
> @aome510 thanks for reply! is it disabled by default specifically because it has some issues? Generally, I feel like hiding features behind compilation flags instead of configurations is a bit inconvenient, since you either have to rely on defaults provided by the packager or resort to compiling the project yourself. Is there a specific reason for this?

The main reason is to avoid redundant dependencies when building the application if people don't need the notification feature, not because it has some issues. This "feature-behind-compilation-flag" pattern is quite common in rust ecosystem (and possibly c++). That said, I agree that it's inconvenient to hide features behind compilation flags instead of configurations.

Fix patch:
diff --git a/docs/config.md b/docs/config.md
index e398dd2d..0a7267e0 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -21,37 +21,38 @@ All configuration files should be placed inside the application's configuration
 
 `spotify_player` uses `app.toml` to configure general application configurations:
 
-| Option                               | Description                                                                   | Default                                                    |
-| ------------------------------------ | ----------------------------------------------------------------------------- | ---------------------------------------------------------- |
-| `client_id`                          | the Spotify client's ID                                                       | `65b708073fc0480ea92a077233ca87bd`                         |
-| `client_port`                        | the port that the application's client is running on to handle CLI commands   | `8080`                                                     |
-| `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}" }`    |
-| `copy_command`                       | the command used to execute a copy-to-clipboard action                        | `xclip -sel c` (Linux), `pbcopy` (MacOS), `clip` (Windows) |
-| `player_event_hook_command`          | the hook command executed when there is a new player event                    | `None`                                                     |
-| `ap_port`                            | the application's Spotify session connection port                             | `None`                                                     |
-| `proxy`                              | the application's Spotify session connection proxy                            | `None`                                                     |
-| `theme`                              | the application's theme                                                       | `default`                                                  |
-| `app_refresh_duration_in_ms`         | the duration (in ms) between two consecutive application refreshes            | `32`                                                       |
-| `playback_refresh_duration_in_ms`    | the duration (in ms) between two consecutive playback refreshes               | `0`                                                        |
-| `cover_image_refresh_duration_in_ms` | the duration (in ms) between two cover image refreshes (`image` feature only) | `2000`                                                     |
-| `page_size_in_rows`                  | a page's size expressed as a number of rows (for page-navigation commands)    | `20`                                                       |
-| `enable_media_control`               | enable application media control support (`media-control` feature only)       | `true` (Linux), `false` (Windows and MacOS)                |
-| `enable_streaming`                   | create a device for streaming (`streaming` feature only)                      | `Always`                                                   |
-| `enable_cover_image_cache`           | store album's cover images in the cache folder                                | `true`                                                     |
-| `notify_streaming_only`              | only notify when client is streaming (`streaming` and `notify` feature only)  | `false`                                                    |
-| `default_device`                     | the default device to connect to on startup if no playing device found        | `spotify-player`                                           |
-| `play_icon`                          | the icon to indicate playing state of a Spotify item                          | `▶`                                                       |
-| `pause_icon`                         | the icon to indicate pause state of a Spotify item                            | `▌▌`                                                       |
-| `liked_icon`                         | the icon to indicate the liked state of a song                                | `♥`                                                       |
-| `border_type`                        | the type of the application's borders                                         | `Plain`                                                    |
-| `progress_bar_type`                  | the type of the playback progress bar                                         | `Rectangle`                                                |
-| `playback_window_position`           | the position of the playback window                                           | `Top`                                                      |
-| `playback_window_width`              | the width of the playback window                                              | `6`                                                        |
-| `cover_img_width`                    | the width of the cover image (`image` feature only)                           | `5`                                                        |
-| `cover_img_length`                   | the length of the cover image (`image` feature only)                          | `9`                                                        |
-| `cover_img_scale`                    | the scale of the cover image (`image` feature only)                           | `1.0`                                                      |
+| Option                               | Description                                                                              | Default                                                    |
+| ------------------------------------ | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
+| `client_id`                          | the Spotify client's ID                                                                  | `65b708073fc0480ea92a077233ca87bd`                         |
+| `client_port`                        | the port that the application's client is running on to handle CLI commands              | `8080`                                                     |
+| `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}" }`    |
+| `copy_command`                       | the command used to execute a copy-to-clipboard action                                   | `xclip -sel c` (Linux), `pbcopy` (MacOS), `clip` (Windows) |
+| `player_event_hook_command`          | the hook command executed when there is a new player event                               | `None`                                                     |
+| `ap_port`                            | the application's Spotify session connection port                                        | `None`                                                     |
+| `proxy`                              | the application's Spotify session connection proxy                                       | `None`                                                     |
+| `theme`                              | the application's theme                                                                  | `default`                                                  |
+| `app_refresh_duration_in_ms`         | the duration (in ms) between two consecutive application refreshes                       | `32`                                                       |
+| `playback_refresh_duration_in_ms`    | the duration (in ms) between two consecutive playback refreshes                          | `0`                                                        |
+| `cover_image_refresh_duration_in_ms` | the duration (in ms) between two cover image refreshes (`image` feature only)            | `2000`                                                     |
+| `page_size_in_rows`                  | a page's size expressed as a number of rows (for page-navigation commands)               | `20`                                                       |
+| `enable_media_control`               | enable application media control support (`media-control` feature only)                  | `true` (Linux), `false` (Windows and MacOS)                |
+| `enable_streaming`                   | enable streaming (`streaming` feature only)                                              | `Always`                                                   |
+| `enable_notify`                      | enable notification (`notify` feature only)                                              | `true`                                                     |
+| `enable_cover_image_cache`           | store album's cover images in the cache folder                                           | `true`                                                     |
+| `notify_streaming_only`              | only send notification when streaming is enabled (`streaming` and `notify` feature only) | `false`                                                    |
+| `default_device`                     | the default device to connect to on startup if no playing device found                   | `spotify-player`                                           |
+| `play_icon`                          | the icon to indicate playing state of a Spotify item                                     | `▶`                                                       |
+| `pause_icon`                         | the icon to indicate pause state of a Spotify item                                       | `▌▌`                                                       |
+| `liked_icon`                         | the icon to indicate the liked state of a song                                           | `♥`                                                       |
+| `border_type`                        | the type of the application's borders                                                    | `Plain`                                                    |
+| `progress_bar_type`                  | the type of the playback progress bar                                                    | `Rectangle`                                                |
+| `playback_window_position`           | the position of the playback window                                                      | `Top`                                                      |
+| `playback_window_width`              | the width of the playback window                                                         | `6`                                                        |
+| `cover_img_width`                    | the width of the cover image (`image` feature only)                                      | `5`                                                        |
+| `cover_img_length`                   | the length of the cover image (`image` feature only)                                     | `9`                                                        |
+| `cover_img_scale`                    | the scale of the cover image (`image` feature only)                                      | `1.0`                                                      |
 
 ### Notes
 
@@ -79,6 +80,7 @@ All configuration files should be placed inside the application's configuration
 - `playback_window_position` can only be either `Top` or `Bottom`.
 - `border_type` can be either `Hidden`, `Plain`, `Rounded`, `Double` or `Thick`.
 - `progress_bar_type` can be either `Rectangle` or `Line`.
+- `notify_streaming_only=true` and `enable_streaming=DaemonOnly` can be set to avoid sending multiple notifications when both daemon and UI are running.
 
 #### Media control
 
diff --git a/examples/app.toml b/examples/app.toml
index 2b20bfdf..de46f1d0 100644
--- a/examples/app.toml
+++ b/examples/app.toml
@@ -14,6 +14,7 @@ cover_image_refresh_duration_in_ms = 2000
 page_size_in_rows = 20
 enable_media_control = false
 enable_streaming = "Always"
+enable_notify = true
 enable_cover_image_cache = true
 notify_streaming_only = false
 default_device = "spotify-player"
diff --git a/spotify_player/src/client/mod.rs b/spotify_player/src/client/mod.rs
index f998f7b2..fc2da57e 100644
--- a/spotify_player/src/client/mod.rs
+++ b/spotify_player/src/client/mod.rs
@@ -1334,7 +1334,7 @@ impl Client {
 
         // notify user about the playback's change if any
         #[cfg(feature = "notify")]
-        {
+        if state.configs.app_config.enable_notify {
             #[cfg(feature = "streaming")]
             if !state.configs.app_config.notify_streaming_only || self.stream_conn.lock().is_some()
             {
diff --git a/spotify_player/src/config/mod.rs b/spotify_player/src/config/mod.rs
index 3b171c53..188e0ff3 100644
--- a/spotify_player/src/config/mod.rs
+++ b/spotify_player/src/config/mod.rs
@@ -72,6 +72,9 @@ pub struct AppConfig {
     #[cfg(feature = "streaming")]
     pub enable_streaming: StreamingType,
 
+    #[cfg(feature = "notify")]
+    pub enable_notify: bool,
+
     pub enable_cover_image_cache: bool,
 
     pub default_device: String,
@@ -244,12 +247,16 @@ impl Default for AppConfig {
             #[cfg(feature = "streaming")]
             enable_streaming: StreamingType::Always,
 
+            #[cfg(feature = "notify")]
+            enable_notify: true,
+
             enable_cover_image_cache: true,
 
             default_device: "spotify-player".to_string(),
 
             device: DeviceConfig::default(),
 
+            #[cfg(all(feature = "streaming", feature = "notify"))]
             notify_streaming_only: false,
         }
     }


Test patch: