From 8896c134426dfe4c6fd581c678865179d86dc4be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Marchal?= Date: Fri, 27 Aug 2021 18:45:53 +0200 Subject: [PATCH] Misc. fixes, added volume offset option --- App.xaml.cs | 6 ---- Handlers/HotkeyHandler.cs | 21 ++++++++--- Handlers/MPDHandler.cs | 9 +++-- Properties/Settings.Designer.cs | 12 +++++++ Properties/Settings.settings | 3 ++ Views/MainWindow.xaml.cs | 2 +- Views/Settings.xaml | 62 +++++++++++++++++++-------------- Views/Settings.xaml.cs | 15 +++++++- unison.csproj | 10 ++++++ 9 files changed, 99 insertions(+), 41 deletions(-) diff --git a/App.xaml.cs b/App.xaml.cs index efe2d6f..31095d5 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,12 +1,6 @@ using System.Windows; using Hardcodet.Wpf.TaskbarNotification; -// todo: -// -// * show mpd version -// * change volume offset -// * fix window resize (if it still happens?) - namespace unison { public partial class App : Application diff --git a/Handlers/HotkeyHandler.cs b/Handlers/HotkeyHandler.cs index e00d99c..9200173 100644 --- a/Handlers/HotkeyHandler.cs +++ b/Handlers/HotkeyHandler.cs @@ -75,11 +75,15 @@ namespace unison mpd.Prev(); break; case VK_VOLUME_DOWN: - mpd._currentVolume -= 5; + mpd._currentVolume -= Properties.Settings.Default.volume_offset; + if (mpd._currentVolume < 0) + mpd._currentVolume = 0; mpd.SetVolume(mpd._currentVolume); break; case VK_VOLUME_UP: - mpd._currentVolume += 5; + mpd._currentVolume += Properties.Settings.Default.volume_offset; + if (mpd._currentVolume > 100) + mpd._currentVolume = 100; mpd.SetVolume(mpd._currentVolume); break; case VK_MEDIA_PLAY_PAUSE: @@ -94,8 +98,17 @@ namespace unison } else { - AppWindow.Hide(); - AppWindow.WindowState = WindowState.Minimized; + if (AppWindow.IsActive) + { + AppWindow.Hide(); + AppWindow.WindowState = WindowState.Minimized; + } + else // not minimized but not in front + { + AppWindow.Show(); + AppWindow.Activate(); + AppWindow.WindowState = WindowState.Normal; + } } break; } diff --git a/Handlers/MPDHandler.cs b/Handlers/MPDHandler.cs index 85aa1c1..01f740f 100644 --- a/Handlers/MPDHandler.cs +++ b/Handlers/MPDHandler.cs @@ -59,7 +59,6 @@ namespace unison _elapsedTimer = new System.Timers.Timer(500); _elapsedTimer.Elapsed += new System.Timers.ElapsedEventHandler(ElapsedTimer); - DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(2); timer.Tick += QueryStatus; @@ -228,7 +227,8 @@ namespace unison _elapsedTimer.Stop(); } - await _mpd.MpdQueryAlbumArt(_currentSong.File, false); + if (_currentSong != null) + await _mpd.MpdQueryAlbumArt(_currentSong.File, false); } public SongInfoEx GetCurrentSong() => _currentSong; @@ -291,5 +291,10 @@ namespace unison { return _currentStatus?.MpdState == MPDCtrl.Models.Status.MpdPlayState.Play; } + + public string GetVersion() + { + return _mpd.MpdVerText; + } } } diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index 78e8bdf..a00c48a 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -94,5 +94,17 @@ namespace unison.Properties { this["snapcast_port"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("5")] + public int volume_offset { + get { + return ((int)(this["volume_offset"])); + } + set { + this["volume_offset"] = value; + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 24940ea..409e1b7 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -20,5 +20,8 @@ 1704 + + 5 + \ No newline at end of file diff --git a/Views/MainWindow.xaml.cs b/Views/MainWindow.xaml.cs index 5cc72d7..ad0d27b 100644 --- a/Views/MainWindow.xaml.cs +++ b/Views/MainWindow.xaml.cs @@ -9,7 +9,7 @@ namespace unison { public partial class MainWindow : Window, INotifyPropertyChanged { - private readonly Settings SettingsWindow = new Settings(); + public readonly Settings SettingsWindow = new Settings(); private MPDHandler mpd; diff --git a/Views/Settings.xaml b/Views/Settings.xaml index 1bdfbae..0af2144 100644 --- a/Views/Settings.xaml +++ b/Views/Settings.xaml @@ -34,7 +34,9 @@ -