From 52f315e4e35b4b883c823d23e7fe66ceea7b772d Mon Sep 17 00:00:00 2001 From: mshafer1 <2565361+mshafer1@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:23:15 -0600 Subject: [PATCH] use an enum --- ntfysh_client/MainForm.cs | 15 ++++++--------- ntfysh_client/SettingsDialog.cs | 5 +++++ ntfysh_client/SettingsModel.cs | 9 +++++++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ntfysh_client/MainForm.cs b/ntfysh_client/MainForm.cs index 24fe6ce..c9c6a70 100644 --- a/ntfysh_client/MainForm.cs +++ b/ntfysh_client/MainForm.cs @@ -73,7 +73,7 @@ namespace ntfysh_client string finalTitle = string.IsNullOrWhiteSpace(e.Title) ? $"{e.Sender.TopicId}@{e.Sender.ServerUrl}" : e.Title; - if (Program.Settings.UseNativeWindowsNotifications) + if (Program.Settings.NotificationsMethod == SettingsModel.NotificationsType.NativeWindows) { notifyIcon.ShowBalloonTip((int)TimeSpan.FromSeconds((double)Program.Settings.Timeout).TotalMilliseconds, finalTitle, e.Message, priorityIcon); } @@ -152,8 +152,8 @@ namespace ntfysh_client //Load current settings into dialog dialog.ReconnectAttempts = Program.Settings.ReconnectAttempts; dialog.ReconnectAttemptDelay = Program.Settings.ReconnectAttemptDelay; - dialog.UseNativeWindowsNotifications = Program.Settings.UseNativeWindowsNotifications; - dialog.UseCustomTrayNotifications = Program.Settings.UseCustomTrayNotifications; + dialog.UseNativeWindowsNotifications = Program.Settings.NotificationsMethod == SettingsModel.NotificationsType.NativeWindows; + dialog.UseCustomTrayNotifications = Program.Settings.NotificationsMethod == SettingsModel.NotificationsType.CustomTray; dialog.CustomTrayNotificationsShowTimeoutBar = Program.Settings.CustomTrayNotificationsShowTimeoutBar; dialog.CustomTrayNotificationsShowInDarkMode = Program.Settings.CustomTrayNotificationsShowInDarkMode; dialog.Timeout = Program.Settings.Timeout; // set timeout last so bounds are setup before setting value @@ -168,8 +168,7 @@ namespace ntfysh_client Program.Settings.Timeout = dialog.Timeout; Program.Settings.ReconnectAttempts = dialog.ReconnectAttempts; Program.Settings.ReconnectAttemptDelay = dialog.ReconnectAttemptDelay; - Program.Settings.UseNativeWindowsNotifications = dialog.UseNativeWindowsNotifications; - Program.Settings.UseCustomTrayNotifications = dialog.UseCustomTrayNotifications; + Program.Settings.NotificationsMethod = (dialog.UseNativeWindowsNotifications)? SettingsModel.NotificationsType.NativeWindows : SettingsModel.NotificationsType.CustomTray; Program.Settings.CustomTrayNotificationsShowTimeoutBar = dialog.CustomTrayNotificationsShowTimeoutBar; Program.Settings.CustomTrayNotificationsShowInDarkMode = dialog.CustomTrayNotificationsShowInDarkMode; @@ -328,8 +327,7 @@ namespace ntfysh_client Timeout = 5, ReconnectAttempts = 10, ReconnectAttemptDelay = 3, - UseNativeWindowsNotifications = true, - UseCustomTrayNotifications = false, + NotificationsMethod = SettingsModel.NotificationsType.NativeWindows, CustomTrayNotificationsShowTimeoutBar = true, CustomTrayNotificationsShowInDarkMode = false, }; @@ -346,8 +344,7 @@ namespace ntfysh_client //Apply settings introduced in Revision 2 (Native vs custom notifications) if (older.Revision < 2) { - older.UseNativeWindowsNotifications = newer.UseNativeWindowsNotifications; - older.UseCustomTrayNotifications = newer.UseCustomTrayNotifications; + older.NotificationsMethod = newer.NotificationsMethod; older.CustomTrayNotificationsShowTimeoutBar = newer.CustomTrayNotificationsShowTimeoutBar; older.CustomTrayNotificationsShowInDarkMode = newer.CustomTrayNotificationsShowInDarkMode; } diff --git a/ntfysh_client/SettingsDialog.cs b/ntfysh_client/SettingsDialog.cs index c2626e8..754c551 100644 --- a/ntfysh_client/SettingsDialog.cs +++ b/ntfysh_client/SettingsDialog.cs @@ -1,10 +1,13 @@ using System; using System.Windows.Forms; +using static ntfysh_client.SettingsModel; namespace ntfysh_client { public partial class SettingsDialog : Form { + public NotificationsType NotificationsMethod { get; set; } + public decimal Timeout { get => timeout.Value; @@ -31,6 +34,7 @@ namespace ntfysh_client { useNativeWindowsNotifications.Checked = value; groupCustomNotificationSettings.Enabled = !value; + NotificationsMethod = (value) ? NotificationsType.NativeWindows : NotificationsType.CustomTray; } } @@ -40,6 +44,7 @@ namespace ntfysh_client set { useCustomTrayNotifications.Checked = value; groupCustomNotificationSettings.Enabled = value; + NotificationsMethod = (value) ? NotificationsType.NativeWindows : NotificationsType.CustomTray; } } #endregion diff --git a/ntfysh_client/SettingsModel.cs b/ntfysh_client/SettingsModel.cs index b370db0..198580f 100644 --- a/ntfysh_client/SettingsModel.cs +++ b/ntfysh_client/SettingsModel.cs @@ -2,12 +2,17 @@ { public class SettingsModel { + public enum NotificationsType + { + NativeWindows, + CustomTray + } + public uint Revision { get; set; } public decimal Timeout { get; set; } public decimal ReconnectAttempts { get; set; } public decimal ReconnectAttemptDelay { get; set; } - public bool UseNativeWindowsNotifications { get; set; } - public bool UseCustomTrayNotifications { get; set; } + public NotificationsType NotificationsMethod { get; set; } public bool CustomTrayNotificationsShowTimeoutBar { get; set; } public bool CustomTrayNotificationsShowInDarkMode { get; set; } }