diff --git a/Toastify/src/App.xaml.cs b/Toastify/src/App.xaml.cs index be14c6a0..2cdad564 100644 --- a/Toastify/src/App.xaml.cs +++ b/Toastify/src/App.xaml.cs @@ -73,7 +73,7 @@ public static void Main(string[] args) catch (Exception e) { App.EmergencyLog(e); - Debug.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {e}\n"); + Debug.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {e}{Environment.NewLine}"); } logger.Info($"Architecture: IntPtr = {IntPtr.Size * 8}bit, Is64BitProcess = {Environment.Is64BitProcess}, Is64BitOS = {Environment.Is64BitOperatingSystem}"); @@ -89,7 +89,7 @@ public static void Main(string[] args) { logger.Error("Unhandled exception while preparing to run.", e); Analytics.TrackException(e); - MessageBox.Show($"Unhandled exception while preparing to run.\n{e.Message}", "Unhandled exception", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show($"Unhandled exception while preparing to run.{Environment.NewLine}{e.Message}", "Unhandled exception", MessageBoxButton.OK, MessageBoxImage.Error); } RunApp(); @@ -715,7 +715,7 @@ private void Application_DispatcherUnhandledException(object sender, DispatcherU { logger.Error("Unhandled exception.", e.Exception); Analytics.TrackException(e.Exception); - MessageBox.Show($"Unhandled exception.\n{e.Exception.Message}", "Unhandled exception", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show($"Unhandled exception.{Environment.NewLine}{e.Exception.Message}", "Unhandled exception", MessageBoxButton.OK, MessageBoxImage.Error); } private void App_OnStartup(object sender, StartupEventArgs e) diff --git a/Toastify/src/Common/ConstraintFailedException.cs b/Toastify/src/Common/ConstraintFailedException.cs index 88af5cc5..d4f15680 100644 --- a/Toastify/src/Common/ConstraintFailedException.cs +++ b/Toastify/src/Common/ConstraintFailedException.cs @@ -5,7 +5,7 @@ namespace Toastify.Common { public class ConstraintFailedException : ApplicationException { - public ConstraintFailedException(Expression constraint) : base($"Constraint failed:\n {constraint}\n") + public ConstraintFailedException(Expression constraint) : base($"Constraint failed:{Environment.NewLine} {constraint}{Environment.NewLine}") { } } diff --git a/Toastify/src/Core/Spotify.cs b/Toastify/src/Core/Spotify.cs index 78ae9c18..ede7833d 100644 --- a/Toastify/src/Core/Spotify.cs +++ b/Toastify/src/Core/Spotify.cs @@ -184,7 +184,7 @@ private void StartSpotify_WorkerTaskCompleted(object sender, RunWorkerCompletedE logger.Error("Error while starting Spotify.", applicationStartupException); string errorMsg = Properties.Resources.ERROR_STARTUP_SPOTIFY; - MessageBox.Show($"{errorMsg}\n{applicationStartupException.Message}", "Toastify", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show($"{errorMsg}{Environment.NewLine}{applicationStartupException.Message}", "Toastify", MessageBoxButton.OK, MessageBoxImage.Error); Analytics.TrackException(applicationStartupException, true); } @@ -196,8 +196,8 @@ private void StartSpotify_WorkerTaskCompleted(object sender, RunWorkerCompletedE string status = $"{webException.Status}"; if (webException.Status == WebExceptionStatus.ProtocolError) status += $" ({(webException.Response as HttpWebResponse)?.StatusCode}, \"{(webException.Response as HttpWebResponse)?.StatusDescription}\")"; - string techDetails = $"Technical details: {webException.Message}\n{webException.HResult}, {status}"; - MessageBox.Show($"{errorMsg}\n{techDetails}", "Toastify", MessageBoxButton.OK, MessageBoxImage.Error); + string techDetails = $"Technical details: {webException.Message}{Environment.NewLine}{webException.HResult}, {status}"; + MessageBox.Show($"{errorMsg}{Environment.NewLine}{techDetails}", "Toastify", MessageBoxButton.OK, MessageBoxImage.Error); Analytics.TrackException(webException, true); } @@ -206,8 +206,8 @@ private void StartSpotify_WorkerTaskCompleted(object sender, RunWorkerCompletedE logger.Error("Unknown error while starting Spotify.", e.Error); string errorMsg = Properties.Resources.ERROR_UNKNOWN; - string techDetails = $"Technical Details: {e.Error.Message}\n{e.Error.StackTrace}"; - MessageBox.Show($"{errorMsg}\n{techDetails}", "Toastify", MessageBoxButton.OK, MessageBoxImage.Error); + string techDetails = $"Technical Details: {e.Error.Message}{Environment.NewLine}{e.Error.StackTrace}"; + MessageBox.Show($"{errorMsg}{Environment.NewLine}{techDetails}", "Toastify", MessageBoxButton.OK, MessageBoxImage.Error); Analytics.TrackException(e.Error, true); } @@ -221,7 +221,7 @@ private void StartSpotify_WorkerTaskCompleted(object sender, RunWorkerCompletedE App.CallInSTAThread(() => { choice = CustomMessageBox.ShowYesNo( - $"{errorMsg}\nDo you need to set up or change your proxy details?\n\nToastify will terminate regardless of your choice.", + $"{errorMsg}{Environment.NewLine}Do you need to set up or change your proxy details?{Environment.NewLine}{Environment.NewLine}Toastify will terminate regardless of your choice.", "Toastify", "Yes", // Yes "No", // No @@ -495,7 +495,7 @@ private void HandleConnectWithSpotifyException(WebException ex, ref bool proxySe App.CallInSTAThread(() => { choice = CustomMessageBox.ShowYesNoCancel( - $"Invalid proxy settings. {(errorCode != null ? $"Returned error code: {errorCode}" : "")}\nDo you want to retry?", + $"Invalid proxy settings. {(errorCode != null ? $"Returned error code: {errorCode}" : "")}{Environment.NewLine}Do you want to retry?", "Toastify", "Retry", // Yes "Change settings", // No diff --git a/Toastify/src/Model/Settings.cs b/Toastify/src/Model/Settings.cs index e21f5d4a..2c129540 100644 --- a/Toastify/src/Model/Settings.cs +++ b/Toastify/src/Model/Settings.cs @@ -414,7 +414,7 @@ internal static string PrintSettings(int indentLevel = 0) { var sb = new StringBuilder(); for (int i = 0; i < indentLevel; ++i) - sb.Append("\t"); + sb.Append(" "); string indent = sb.ToString(); sb.Clear(); @@ -425,7 +425,7 @@ internal static string PrintSettings(int indentLevel = 0) { object current = property.GetValue(Current); if (property.PropertyType.GetInterfaces().Contains(typeof(ISettingValue))) - sb.Append($"{indent}{property.Name}: {current}\n"); + sb.Append($"{indent}{property.Name}: {current}{Environment.NewLine}"); else { if (property.PropertyType.GetInterfaces().Contains(typeof(ICollection))) @@ -434,7 +434,7 @@ internal static string PrintSettings(int indentLevel = 0) if (property.PropertyType == typeof(ProxyConfigAdapter)) { var proxy = (ProxyConfigAdapter)current; - sb.Append($"{indent}{property.Name}: {proxy.ToString(true)}\n"); + sb.Append($"{indent}{property.Name}: {proxy.ToString(true)}{Environment.NewLine}"); } } } diff --git a/Toastify/src/View/ToastView.xaml.cs b/Toastify/src/View/ToastView.xaml.cs index 733f3c43..c428e4ab 100644 --- a/Toastify/src/View/ToastView.xaml.cs +++ b/Toastify/src/View/ToastView.xaml.cs @@ -148,7 +148,7 @@ public ToastView() private void Init() { if (logger.IsDebugEnabled) - logger.Debug($"Current Settings:\n{Settings.PrintSettings(2)}"); + logger.Debug($"Current Settings:{Environment.NewLine}{Settings.PrintSettings(2)}"); this.InitToast(); this.InitTrayIcon(); @@ -191,7 +191,8 @@ private void FinalizeInit() // Subscribe to actions' events var playPauseAction = this.ActionRegistry.GetAction(ToastifyActionEnum.PlayPause); - playPauseAction.ActionPerformed += this.ActionPlayPause_ActionPerformed; + if (playPauseAction != null) + playPauseAction.ActionPerformed += this.ActionPlayPause_ActionPerformed; this.IsInitComplete = true; } @@ -897,8 +898,8 @@ internal void PrintInternalDebugInfo() StringBuilder sb = new StringBuilder(); List strings = new List(); - sb.Append("Internal Info:\n"); - sb.Append($"\thWnd[{this.WindowHandle}]\n"); + sb.Append($"Internal Info:{Environment.NewLine}"); + sb.Append($"\thWnd[{this.WindowHandle}]{Environment.NewLine}"); // minimizeTimer strings.Clear(); @@ -909,7 +910,7 @@ internal void PrintInternalDebugInfo() strings.Add(this.minimizeTimer.Enabled ? "enabled" : "disabled"); strings.Add($"{this.minimizeTimer.Interval}"); } - sb.Append($"\tminimizeTimer: {string.Join(",", strings)}\n"); + sb.Append($"\tminimizeTimer: {string.Join(",", strings)}{Environment.NewLine}"); // track strings.Clear(); @@ -917,7 +918,7 @@ internal void PrintInternalDebugInfo() strings.Add("null"); else strings.Add(this.currentSong.IsValid() ? "valid" : "invalid"); - sb.Append($"\ttrack: {string.Join(",", strings)}\n"); + sb.Append($"\ttrack: {string.Join(",", strings)}{Environment.NewLine}"); // state strings.Clear(); @@ -926,7 +927,7 @@ internal void PrintInternalDebugInfo() strings.Add(this.dragging ? "dragging" : string.Empty); strings.Add(this.paused ? "paused" : "playing"); strings.RemoveAll(string.IsNullOrWhiteSpace); - sb.Append($"\tstate: {string.Join(",", strings)}\n"); + sb.Append($"\tstate: {string.Join(",", strings)}{Environment.NewLine}"); // visibility strings.Clear(); @@ -936,7 +937,7 @@ internal void PrintInternalDebugInfo() strings.Add(this.Topmost ? "topmost" : string.Empty); strings.Add($"{{{wPlacement}}}"); strings.RemoveAll(string.IsNullOrWhiteSpace); - sb.Append($"\tvisibility: {string.Join(",", strings)}\n"); + sb.Append($"\tvisibility: {string.Join(",", strings)}{Environment.NewLine}"); // dispatcher strings.Clear(); @@ -947,7 +948,7 @@ internal void PrintInternalDebugInfo() strings.Add(this.Dispatcher.HasShutdownStarted ? "shutdown-started" : string.Empty); strings.RemoveAll(string.IsNullOrWhiteSpace); } - sb.Append($"\tdispatcher: {string.Join(",", strings)}\n"); + sb.Append($"\tdispatcher: {string.Join(",", strings)}{Environment.NewLine}"); // settings strings.Clear(); @@ -955,10 +956,10 @@ internal void PrintInternalDebugInfo() strings.Add(this.Settings.OnlyShowToastOnHotkey ? "only-show-toast-on-hotkey" : string.Empty); strings.Add($"{this.Settings.DisplayTime}"); strings.RemoveAll(string.IsNullOrWhiteSpace); - sb.Append($"\tsettings: {string.Join(",", strings)}\n"); + sb.Append($"\tsettings: {string.Join(",", strings)}{Environment.NewLine}"); string internalInfo = sb.ToString(); - logger.Debug($"{internalInfo}\tStack Trace:\n{Environment.StackTrace}"); + logger.Debug($"{internalInfo}\tStack Trace:{Environment.NewLine}{Environment.StackTrace}"); } } @@ -1006,7 +1007,7 @@ public void DisplayAction(ToastifyActionEnum action) string visibility = $"visibility[{(this.ShownOrFading ? '1' : '0')}{(this.IsVisible ? '1' : '0')}{this.Visibility.ToString().Substring(0, 1)}{(this.Topmost ? '1' : '0')}, {{{wPlacement}}}]"; string dispatcher = $"dispatcher[{(this.Dispatcher == null ? "null" : $"{(this.Dispatcher.HasShutdownStarted ? '1' : '0')}")}]"; string settings = $"settings[{(this.Settings.DisableToast ? '1' : '0')}{(this.Settings.OnlyShowToastOnHotkey ? '1' : '0')}, {this.Settings.DisplayTime}]"; - logger.Info($"{hWnd}, {timer}, {song}, {state}, {visibility}, {dispatcher}, {settings}\n Stack Trace:\n{Environment.StackTrace}"); + logger.Info($"{hWnd}, {timer}, {song}, {state}, {visibility}, {dispatcher}, {settings}{Environment.NewLine} Stack Trace:{Environment.NewLine}{Environment.StackTrace}"); } #endif this.ShowOrHideToast(force: true);