use an enum

This commit is contained in:
mshafer1
2024-12-23 09:23:15 -06:00
parent 582eef1b9d
commit 52f315e4e3
3 changed files with 18 additions and 11 deletions

View File

@@ -73,7 +73,7 @@ namespace ntfysh_client
string finalTitle = string.IsNullOrWhiteSpace(e.Title) ? $"{e.Sender.TopicId}@{e.Sender.ServerUrl}" : e.Title; 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); 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 //Load current settings into dialog
dialog.ReconnectAttempts = Program.Settings.ReconnectAttempts; dialog.ReconnectAttempts = Program.Settings.ReconnectAttempts;
dialog.ReconnectAttemptDelay = Program.Settings.ReconnectAttemptDelay; dialog.ReconnectAttemptDelay = Program.Settings.ReconnectAttemptDelay;
dialog.UseNativeWindowsNotifications = Program.Settings.UseNativeWindowsNotifications; dialog.UseNativeWindowsNotifications = Program.Settings.NotificationsMethod == SettingsModel.NotificationsType.NativeWindows;
dialog.UseCustomTrayNotifications = Program.Settings.UseCustomTrayNotifications; dialog.UseCustomTrayNotifications = Program.Settings.NotificationsMethod == SettingsModel.NotificationsType.CustomTray;
dialog.CustomTrayNotificationsShowTimeoutBar = Program.Settings.CustomTrayNotificationsShowTimeoutBar; dialog.CustomTrayNotificationsShowTimeoutBar = Program.Settings.CustomTrayNotificationsShowTimeoutBar;
dialog.CustomTrayNotificationsShowInDarkMode = Program.Settings.CustomTrayNotificationsShowInDarkMode; dialog.CustomTrayNotificationsShowInDarkMode = Program.Settings.CustomTrayNotificationsShowInDarkMode;
dialog.Timeout = Program.Settings.Timeout; // set timeout last so bounds are setup before setting value 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.Timeout = dialog.Timeout;
Program.Settings.ReconnectAttempts = dialog.ReconnectAttempts; Program.Settings.ReconnectAttempts = dialog.ReconnectAttempts;
Program.Settings.ReconnectAttemptDelay = dialog.ReconnectAttemptDelay; Program.Settings.ReconnectAttemptDelay = dialog.ReconnectAttemptDelay;
Program.Settings.UseNativeWindowsNotifications = dialog.UseNativeWindowsNotifications; Program.Settings.NotificationsMethod = (dialog.UseNativeWindowsNotifications)? SettingsModel.NotificationsType.NativeWindows : SettingsModel.NotificationsType.CustomTray;
Program.Settings.UseCustomTrayNotifications = dialog.UseCustomTrayNotifications;
Program.Settings.CustomTrayNotificationsShowTimeoutBar = dialog.CustomTrayNotificationsShowTimeoutBar; Program.Settings.CustomTrayNotificationsShowTimeoutBar = dialog.CustomTrayNotificationsShowTimeoutBar;
Program.Settings.CustomTrayNotificationsShowInDarkMode = dialog.CustomTrayNotificationsShowInDarkMode; Program.Settings.CustomTrayNotificationsShowInDarkMode = dialog.CustomTrayNotificationsShowInDarkMode;
@@ -328,8 +327,7 @@ namespace ntfysh_client
Timeout = 5, Timeout = 5,
ReconnectAttempts = 10, ReconnectAttempts = 10,
ReconnectAttemptDelay = 3, ReconnectAttemptDelay = 3,
UseNativeWindowsNotifications = true, NotificationsMethod = SettingsModel.NotificationsType.NativeWindows,
UseCustomTrayNotifications = false,
CustomTrayNotificationsShowTimeoutBar = true, CustomTrayNotificationsShowTimeoutBar = true,
CustomTrayNotificationsShowInDarkMode = false, CustomTrayNotificationsShowInDarkMode = false,
}; };
@@ -346,8 +344,7 @@ namespace ntfysh_client
//Apply settings introduced in Revision 2 (Native vs custom notifications) //Apply settings introduced in Revision 2 (Native vs custom notifications)
if (older.Revision < 2) if (older.Revision < 2)
{ {
older.UseNativeWindowsNotifications = newer.UseNativeWindowsNotifications; older.NotificationsMethod = newer.NotificationsMethod;
older.UseCustomTrayNotifications = newer.UseCustomTrayNotifications;
older.CustomTrayNotificationsShowTimeoutBar = newer.CustomTrayNotificationsShowTimeoutBar; older.CustomTrayNotificationsShowTimeoutBar = newer.CustomTrayNotificationsShowTimeoutBar;
older.CustomTrayNotificationsShowInDarkMode = newer.CustomTrayNotificationsShowInDarkMode; older.CustomTrayNotificationsShowInDarkMode = newer.CustomTrayNotificationsShowInDarkMode;
} }

View File

@@ -1,10 +1,13 @@
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
using static ntfysh_client.SettingsModel;
namespace ntfysh_client namespace ntfysh_client
{ {
public partial class SettingsDialog : Form public partial class SettingsDialog : Form
{ {
public NotificationsType NotificationsMethod { get; set; }
public decimal Timeout public decimal Timeout
{ {
get => timeout.Value; get => timeout.Value;
@@ -31,6 +34,7 @@ namespace ntfysh_client
{ {
useNativeWindowsNotifications.Checked = value; useNativeWindowsNotifications.Checked = value;
groupCustomNotificationSettings.Enabled = !value; groupCustomNotificationSettings.Enabled = !value;
NotificationsMethod = (value) ? NotificationsType.NativeWindows : NotificationsType.CustomTray;
} }
} }
@@ -40,6 +44,7 @@ namespace ntfysh_client
set { set {
useCustomTrayNotifications.Checked = value; useCustomTrayNotifications.Checked = value;
groupCustomNotificationSettings.Enabled = value; groupCustomNotificationSettings.Enabled = value;
NotificationsMethod = (value) ? NotificationsType.NativeWindows : NotificationsType.CustomTray;
} }
} }
#endregion #endregion

View File

@@ -2,12 +2,17 @@
{ {
public class SettingsModel public class SettingsModel
{ {
public enum NotificationsType
{
NativeWindows,
CustomTray
}
public uint Revision { get; set; } public uint Revision { get; set; }
public decimal Timeout { get; set; } public decimal Timeout { get; set; }
public decimal ReconnectAttempts { get; set; } public decimal ReconnectAttempts { get; set; }
public decimal ReconnectAttemptDelay { get; set; } public decimal ReconnectAttemptDelay { get; set; }
public bool UseNativeWindowsNotifications { get; set; } public NotificationsType NotificationsMethod { get; set; }
public bool UseCustomTrayNotifications { get; set; }
public bool CustomTrayNotificationsShowTimeoutBar { get; set; } public bool CustomTrayNotificationsShowTimeoutBar { get; set; }
public bool CustomTrayNotificationsShowInDarkMode { get; set; } public bool CustomTrayNotificationsShowInDarkMode { get; set; }
} }