From 38a7856a0f0237f41f5b0b73181aaba65c11e283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Marchal?= Date: Thu, 17 Nov 2022 23:41:03 +0100 Subject: [PATCH] Code styling --- Handlers/MPDHandler.cs | 20 ++++++++++---------- Handlers/ShuffleHandler.cs | 2 +- Handlers/SnapcastHandler.cs | 3 ++- Handlers/UpdateHandler.cs | 9 ++++----- Views/MainWindow.xaml.cs | 6 +++--- Views/Radios.xaml.cs | 2 +- Views/Settings.xaml.cs | 16 ++++++++-------- Views/Shuffle.xaml.cs | 12 ++++++------ Views/SystrayViewModel.cs | 8 ++++---- 9 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Handlers/MPDHandler.cs b/Handlers/MPDHandler.cs index d5b9c6c..fe70ca7 100644 --- a/Handlers/MPDHandler.cs +++ b/Handlers/MPDHandler.cs @@ -49,12 +49,12 @@ namespace unison private MpdStatus _currentStatus; private IMpdFile _currentSong; private BitmapImage _cover; - public Statistics _stats; + private readonly Statistics _stats; private readonly System.Timers.Timer _elapsedTimer; - private DispatcherTimer _retryTimer; + private readonly DispatcherTimer _retryTimer; - bool _isUpdatingStatus = false; - bool _isUpdatingSong = false; + private bool _isUpdatingStatus = false; + private bool _isUpdatingSong = false; public IPAddress _ipAddress; @@ -70,6 +70,8 @@ namespace unison public CancellationTokenSource _cancelCommand; private CancellationTokenSource _cancelConnect; + private bool UpdateStarted = false; + public MPDHandler() { Startup(null, null); @@ -154,7 +156,7 @@ namespace unison if (_commandConnection == null || !IsConnected()) { Trace.WriteLine("[SafelySendCommandAsync] no command connection"); - return default(T); + return default; } try @@ -176,7 +178,7 @@ namespace unison Trace.WriteLine($"Sending {command.GetType().Name} failed: {e.Message}"); } - return default(T); + return default; } public async void Startup(object sender, EventArgs e) @@ -334,8 +336,6 @@ namespace unison }, token).ConfigureAwait(false); } - private bool UpdateStarted = false; - private async Task HandleIdleResponseAsync(string subsystems) { try @@ -637,12 +637,12 @@ namespace unison { if (_Playlist == null) return 0; - return _Playlist.ToArray().Count(); + return _Playlist.ToArray().Length; } public void UpdateDB() => SendCommand(new UpdateCommand()); - private string FormatTime(TimeSpan time) + private static string FormatTime(TimeSpan time) { string FormattedTime = ""; diff --git a/Handlers/ShuffleHandler.cs b/Handlers/ShuffleHandler.cs index 8d6f961..b3199d2 100644 --- a/Handlers/ShuffleHandler.cs +++ b/Handlers/ShuffleHandler.cs @@ -17,8 +17,8 @@ namespace unison class ShuffleHandler { private readonly MPDHandler _mpd; - public int AddedSongs = 0; + public int AddedSongs = 0; public List SongList { get; } public ShuffleHandler() diff --git a/Handlers/SnapcastHandler.cs b/Handlers/SnapcastHandler.cs index 5d7d0f9..f237647 100644 --- a/Handlers/SnapcastHandler.cs +++ b/Handlers/SnapcastHandler.cs @@ -8,6 +8,7 @@ namespace unison public class SnapcastHandler { private readonly Process _snapcast = new(); + public bool HasStarted { get; private set; } public void OnConnectionChanged(object sender, EventArgs e) @@ -30,7 +31,7 @@ namespace unison }); } - public void UpdateInterface() + public static void UpdateInterface() { TaskbarIcon Systray = (TaskbarIcon)Application.Current.Properties["systray"]; SystrayViewModel DataContext = Systray.DataContext as SystrayViewModel; diff --git a/Handlers/UpdateHandler.cs b/Handlers/UpdateHandler.cs index 1af30e8..3b85832 100644 --- a/Handlers/UpdateHandler.cs +++ b/Handlers/UpdateHandler.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using AutoUpdaterDotNET; namespace unison.Handlers @@ -9,10 +8,10 @@ namespace unison.Handlers readonly string xmlFile = "https://raw.githubusercontent.com/ZetaKebab/unison/main/Installer/unison.xml"; private bool _UpdateAvailable = false; - public bool UpdateAvailable() => _UpdateAvailable; - private bool _RequestedCheck = false; + public bool UpdateAvailable() => _UpdateAvailable; + public UpdateHandler() { AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent; @@ -25,7 +24,7 @@ namespace unison.Handlers AutoUpdater.Start(xmlFile); } - private string CutVersionNumber(string number) + private static string CutVersionNumber(string number) { return number.Substring(0, number.LastIndexOf(".")); } diff --git a/Views/MainWindow.xaml.cs b/Views/MainWindow.xaml.cs index aab718e..fbf25d9 100644 --- a/Views/MainWindow.xaml.cs +++ b/Views/MainWindow.xaml.cs @@ -224,12 +224,12 @@ namespace unison border.Style = b ? (Style)Resources["SelectedButton"] : (Style)Resources["UnselectedButton"]; } - public string FormatSeconds(int time) + public static string FormatSeconds(int time) { TimeSpan timespan = TimeSpan.FromSeconds(time); return timespan.ToString(@"mm\:ss"); } - public string FormatSeconds(double time) + public static string FormatSeconds(double time) { TimeSpan timespan = TimeSpan.FromSeconds(time); return timespan.ToString(@"mm\:ss"); @@ -244,7 +244,7 @@ namespace unison public void Consume_Clicked(object sender, RoutedEventArgs e) => _mpd.Consume(); public void ChangeVolume(int value) => _mpd.SetVolume(value); - public void Snapcast_Clicked(object sender, RoutedEventArgs e) + public static void Snapcast_Clicked(object sender, RoutedEventArgs e) { SnapcastHandler snapcast = (SnapcastHandler)Application.Current.Properties["snapcast"]; snapcast.LaunchOrExit(); diff --git a/Views/Radios.xaml.cs b/Views/Radios.xaml.cs index 3365f37..fce3c79 100644 --- a/Views/Radios.xaml.cs +++ b/Views/Radios.xaml.cs @@ -15,7 +15,7 @@ namespace unison public partial class Radios : Window { private MPDHandler _mpd; - RadioHandler _radio; + private RadioHandler _radio; public bool IsConnected() => _radio.IsConnected(); diff --git a/Views/Settings.xaml.cs b/Views/Settings.xaml.cs index bf2e57a..6773c1d 100644 --- a/Views/Settings.xaml.cs +++ b/Views/Settings.xaml.cs @@ -85,7 +85,7 @@ namespace unison } } - private void NumberValidationTextBox(object sender, TextCompositionEventArgs e) + private static void NumberValidationTextBox(object sender, TextCompositionEventArgs e) { Regex regex = new Regex("[^0-9]+"); e.Handled = regex.IsMatch(e.Text); @@ -105,7 +105,7 @@ namespace unison private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) { - ProcessStartInfo psi = new(e.Uri.AbsoluteUri); + ProcessStartInfo psi = new ProcessStartInfo(e.Uri.AbsoluteUri); psi.UseShellExecute = true; Process.Start(psi); e.Handled = true; @@ -149,7 +149,7 @@ namespace unison MPDConnect_Clicked(null, null); } - private void MPDDatabaseUpdate_Clicked(object sender, RoutedEventArgs e) + private static void MPDDatabaseUpdate_Clicked(object sender, RoutedEventArgs e) { MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"]; if (mpd.IsConnected()) @@ -180,7 +180,7 @@ namespace unison TimedText(UpdateDBMessage2, 2); } - private void CheckUpdates(object sender, RoutedEventArgs e) + private static void CheckUpdates(object sender, RoutedEventArgs e) { UpdateHandler updater = (UpdateHandler)Application.Current.Properties["updater"]; updater.Start(true); @@ -382,7 +382,7 @@ namespace unison HotkeyChanged(); } - private HotkeyHandler.VK GetVirtualKey(Key key) + private static HotkeyHandler.VK GetVirtualKey(Key key) { foreach (object value in System.Enum.GetValues(typeof(HotkeyHandler.VK))) { @@ -392,7 +392,7 @@ namespace unison return HotkeyHandler.VK.None; } - private HotkeyHandler.MOD GetMOD(string str) + private static HotkeyHandler.MOD GetMOD(string str) { foreach (object value in System.Enum.GetValues(typeof(HotkeyHandler.MOD))) { @@ -424,12 +424,12 @@ namespace unison InitializeShortcuts(); } - private uint GetMod(StackPanel stackPanel) + private static uint GetMod(StackPanel stackPanel) { return (uint)(GetMOD(stackPanel.Children.OfType().First().SelectedItem.ToString()) | GetMOD(stackPanel.Children.OfType().Last().SelectedItem.ToString())); } - private uint GetVk(StackPanel stackPanel) + private static uint GetVk(StackPanel stackPanel) { Button button = stackPanel.Children.OfType