diff --git a/ntfysh_client/MainForm.cs b/ntfysh_client/MainForm.cs index d5906bd..b759705 100644 --- a/ntfysh_client/MainForm.cs +++ b/ntfysh_client/MainForm.cs @@ -135,10 +135,14 @@ namespace ntfysh_client using SettingsDialog dialog = new(); //Load current settings into dialog - dialog.Timeout = Program.Settings.Timeout; dialog.ReconnectAttempts = Program.Settings.ReconnectAttempts; dialog.ReconnectAttemptDelay = Program.Settings.ReconnectAttemptDelay; - + dialog.UseNativeWindowsNotifications = Program.Settings.UseNativeWindowsNotifications; + dialog.UseCustomTrayNotifications = Program.Settings.UseCustomTrayNotifications; + 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 + //Show dialog DialogResult result = dialog.ShowDialog(); @@ -149,7 +153,11 @@ 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.CustomTrayNotificationsShowTimeoutBar = dialog.CustomTrayNotificationsShowTimeoutBar; + Program.Settings.CustomTrayNotificationsShowInDarkMode = dialog.CustomTrayNotificationsShowInDarkMode; + //Save new settings persistently SaveSettingsToFile(); } @@ -301,10 +309,14 @@ namespace ntfysh_client private SettingsModel GetDefaultSettings() => new() { - Revision = 1, + Revision = 2, Timeout = 5, ReconnectAttempts = 10, - ReconnectAttemptDelay = 3 + ReconnectAttemptDelay = 3, + UseNativeWindowsNotifications = true, + UseCustomTrayNotifications = false, + CustomTrayNotificationsShowTimeoutBar = true, + CustomTrayNotificationsShowInDarkMode = true, }; private void MergeSettingsRevisions(SettingsModel older, SettingsModel newer) @@ -315,6 +327,13 @@ namespace ntfysh_client older.ReconnectAttempts = newer.ReconnectAttempts; older.ReconnectAttemptDelay = newer.ReconnectAttemptDelay; } + if (older.Revision < 2) + { + older.UseNativeWindowsNotifications = newer.UseNativeWindowsNotifications; + older.UseCustomTrayNotifications = newer.UseCustomTrayNotifications; + older.CustomTrayNotificationsShowTimeoutBar = newer.CustomTrayNotificationsShowTimeoutBar; + older.CustomTrayNotificationsShowInDarkMode = newer.CustomTrayNotificationsShowInDarkMode; + } //Update the revision older.Revision = newer.Revision; @@ -364,7 +383,7 @@ namespace ntfysh_client Program.Settings = settings; //Check the settings revision. If it is older than the current latest revision, apply the settings defaults missing from previous revision - if (Program.Settings.Revision < defaultSettings.ReconnectAttempts) + if (Program.Settings.Revision < defaultSettings.Revision) { MergeSettingsRevisions(Program.Settings, defaultSettings); SaveSettingsToFile(); diff --git a/ntfysh_client/SettingsDialog.Designer.cs b/ntfysh_client/SettingsDialog.Designer.cs index a9ccaa0..01d5f9f 100644 --- a/ntfysh_client/SettingsDialog.Designer.cs +++ b/ntfysh_client/SettingsDialog.Designer.cs @@ -38,10 +38,19 @@ namespace ntfysh_client reconnectAttemptsLabel = new System.Windows.Forms.Label(); reconnectAttemptDelay = new System.Windows.Forms.NumericUpDown(); reconnectAttemptDelayLabel = new System.Windows.Forms.Label(); + groupBox1 = new System.Windows.Forms.GroupBox(); + useCustomTrayNotifications = new System.Windows.Forms.RadioButton(); + useNativeWindowsNotifications = new System.Windows.Forms.RadioButton(); + groupCustomNotificationSettings = new System.Windows.Forms.GroupBox(); + customNotificationsShowInDarkMode = new System.Windows.Forms.CheckBox(); + customNotificationsShowTimeoutBar = new System.Windows.Forms.CheckBox(); + label1 = new System.Windows.Forms.Label(); buttonPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)timeout).BeginInit(); ((System.ComponentModel.ISupportInitialize)reconnectAttempts).BeginInit(); ((System.ComponentModel.ISupportInitialize)reconnectAttemptDelay).BeginInit(); + groupBox1.SuspendLayout(); + groupCustomNotificationSettings.SuspendLayout(); SuspendLayout(); // // buttonPanel @@ -50,7 +59,7 @@ namespace ntfysh_client buttonPanel.Controls.Add(cancelButton); buttonPanel.Controls.Add(saveButton); buttonPanel.Dock = System.Windows.Forms.DockStyle.Bottom; - buttonPanel.Location = new System.Drawing.Point(0, 150); + buttonPanel.Location = new System.Drawing.Point(0, 316); buttonPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); buttonPanel.Name = "buttonPanel"; buttonPanel.Size = new System.Drawing.Size(531, 51); @@ -82,7 +91,7 @@ namespace ntfysh_client timeoutLabel.Location = new System.Drawing.Point(13, 9); timeoutLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); timeoutLabel.Name = "timeoutLabel"; - timeoutLabel.Size = new System.Drawing.Size(488, 15); + timeoutLabel.Size = new System.Drawing.Size(401, 15); timeoutLabel.TabIndex = 3; timeoutLabel.Text = "Notification Toast Timeout (seconds, use -1 to require closing notification):"; // @@ -109,7 +118,7 @@ namespace ntfysh_client reconnectAttemptsLabel.Location = new System.Drawing.Point(12, 54); reconnectAttemptsLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); reconnectAttemptsLabel.Name = "reconnectAttemptsLabel"; - reconnectAttemptsLabel.Size = new System.Drawing.Size(198, 15); + reconnectAttemptsLabel.Size = new System.Drawing.Size(287, 15); reconnectAttemptsLabel.TabIndex = 5; reconnectAttemptsLabel.Text = "Maximum reconnect retry attempts (requires restart):"; // @@ -127,16 +136,91 @@ namespace ntfysh_client reconnectAttemptDelayLabel.Location = new System.Drawing.Point(12, 99); reconnectAttemptDelayLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); reconnectAttemptDelayLabel.Name = "reconnectAttemptDelayLabel"; - reconnectAttemptDelayLabel.Size = new System.Drawing.Size(191, 15); + reconnectAttemptDelayLabel.Size = new System.Drawing.Size(275, 15); reconnectAttemptDelayLabel.TabIndex = 7; reconnectAttemptDelayLabel.Text = "Delay between attempts (seconds, requires restart):"; // + // groupBox1 + // + groupBox1.Controls.Add(useCustomTrayNotifications); + groupBox1.Controls.Add(useNativeWindowsNotifications); + groupBox1.Location = new System.Drawing.Point(12, 147); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new System.Drawing.Size(506, 67); + groupBox1.TabIndex = 9; + groupBox1.TabStop = false; + // + // useCustomTrayNotifications + // + useCustomTrayNotifications.AutoSize = true; + useCustomTrayNotifications.Location = new System.Drawing.Point(6, 40); + useCustomTrayNotifications.Name = "useCustomTrayNotifications"; + useCustomTrayNotifications.Size = new System.Drawing.Size(267, 19); + useCustomTrayNotifications.TabIndex = 1; + useCustomTrayNotifications.TabStop = true; + useCustomTrayNotifications.Text = "Use ntfysh-windows custom tray notifications"; + useCustomTrayNotifications.UseVisualStyleBackColor = true; + useCustomTrayNotifications.CheckedChanged += useCustomTrayNotifications_CheckedChanged; + // + // useNativeWindowsNotifications + // + useNativeWindowsNotifications.AutoSize = true; + useNativeWindowsNotifications.Location = new System.Drawing.Point(6, 15); + useNativeWindowsNotifications.Name = "useNativeWindowsNotifications"; + useNativeWindowsNotifications.Size = new System.Drawing.Size(203, 19); + useNativeWindowsNotifications.TabIndex = 0; + useNativeWindowsNotifications.TabStop = true; + useNativeWindowsNotifications.Text = "Use Windows' native notifications"; + useNativeWindowsNotifications.UseVisualStyleBackColor = true; + // + // groupCustomNotificationSettings + // + groupCustomNotificationSettings.Controls.Add(customNotificationsShowInDarkMode); + groupCustomNotificationSettings.Controls.Add(customNotificationsShowTimeoutBar); + groupCustomNotificationSettings.Location = new System.Drawing.Point(12, 243); + groupCustomNotificationSettings.Name = "groupCustomNotificationSettings"; + groupCustomNotificationSettings.Size = new System.Drawing.Size(504, 67); + groupCustomNotificationSettings.TabIndex = 10; + groupCustomNotificationSettings.TabStop = false; + // + // customNotificationsShowInDarkMode + // + customNotificationsShowInDarkMode.AutoSize = true; + customNotificationsShowInDarkMode.Location = new System.Drawing.Point(6, 37); + customNotificationsShowInDarkMode.Name = "customNotificationsShowInDarkMode"; + customNotificationsShowInDarkMode.Size = new System.Drawing.Size(197, 19); + customNotificationsShowInDarkMode.TabIndex = 1; + customNotificationsShowInDarkMode.Text = "Show notifications in dark mode"; + customNotificationsShowInDarkMode.UseVisualStyleBackColor = true; + // + // customNotificationsShowTimeoutBar + // + customNotificationsShowTimeoutBar.AutoSize = true; + customNotificationsShowTimeoutBar.Location = new System.Drawing.Point(6, 14); + customNotificationsShowTimeoutBar.Name = "customNotificationsShowTimeoutBar"; + customNotificationsShowTimeoutBar.Size = new System.Drawing.Size(211, 19); + customNotificationsShowTimeoutBar.TabIndex = 0; + customNotificationsShowTimeoutBar.Text = "Show time-out bar on notifications"; + customNotificationsShowTimeoutBar.UseVisualStyleBackColor = true; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new System.Drawing.Point(12, 227); + label1.Name = "label1"; + label1.Size = new System.Drawing.Size(180, 15); + label1.TabIndex = 11; + label1.Text = "Custom tray notification settings"; + // // SettingsDialog // AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; BackColor = System.Drawing.Color.White; - ClientSize = new System.Drawing.Size(531, 201); + ClientSize = new System.Drawing.Size(531, 367); + Controls.Add(label1); + Controls.Add(groupCustomNotificationSettings); + Controls.Add(groupBox1); Controls.Add(reconnectAttemptDelay); Controls.Add(reconnectAttemptDelayLabel); Controls.Add(reconnectAttempts); @@ -157,6 +241,10 @@ namespace ntfysh_client ((System.ComponentModel.ISupportInitialize)timeout).EndInit(); ((System.ComponentModel.ISupportInitialize)reconnectAttempts).EndInit(); ((System.ComponentModel.ISupportInitialize)reconnectAttemptDelay).EndInit(); + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupCustomNotificationSettings.ResumeLayout(false); + groupCustomNotificationSettings.PerformLayout(); ResumeLayout(false); PerformLayout(); } @@ -172,5 +260,12 @@ namespace ntfysh_client private System.Windows.Forms.Label reconnectAttemptsLabel; private System.Windows.Forms.NumericUpDown reconnectAttemptDelay; private System.Windows.Forms.Label reconnectAttemptDelayLabel; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.RadioButton useCustomTrayNotifications; + private System.Windows.Forms.RadioButton useNativeWindowsNotifications; + private System.Windows.Forms.GroupBox groupCustomNotificationSettings; + private System.Windows.Forms.CheckBox customNotificationsShowTimeoutBar; + private System.Windows.Forms.CheckBox customNotificationsShowInDarkMode; + private System.Windows.Forms.Label label1; } } \ No newline at end of file diff --git a/ntfysh_client/SettingsDialog.cs b/ntfysh_client/SettingsDialog.cs index 6568d9d..e63036b 100644 --- a/ntfysh_client/SettingsDialog.cs +++ b/ntfysh_client/SettingsDialog.cs @@ -8,7 +8,7 @@ namespace ntfysh_client public decimal Timeout { get => timeout.Value; - set => timeout.Value = value; + set => timeout.Value = Math.Max(value, timeout.Minimum); // Ensure value is within bounds despite our changing minimum } public decimal ReconnectAttempts @@ -23,9 +23,45 @@ namespace ntfysh_client set => reconnectAttemptDelay.Value = value; } + #region: Native vs custom notifications options. Because these are in a group box, these are mutualy exclusive. + public bool UseNativeWindowsNotifications + { + get => useNativeWindowsNotifications.Checked; + set + { + useNativeWindowsNotifications.Checked = value; + groupCustomNotificationSettings.Enabled = !value; + } + } + + public bool UseCustomTrayNotifications + { + get => useCustomTrayNotifications.Checked; + set { + useCustomTrayNotifications.Checked = value; + groupCustomNotificationSettings.Enabled = value; + } + } + #endregion + + #region: Custom tray notification options + public bool CustomTrayNotificationsShowTimeoutBar + { + get => customNotificationsShowTimeoutBar.Checked; + set => customNotificationsShowTimeoutBar.Checked = value; + } + + public bool CustomTrayNotificationsShowInDarkMode + { + get => customNotificationsShowInDarkMode.Checked; + set => customNotificationsShowInDarkMode.Checked = value; + } + #endregion + public SettingsDialog() { InitializeComponent(); + setNotificationsUIElements(); } private void saveButton_Click(object sender, EventArgs e) @@ -37,5 +73,20 @@ namespace ntfysh_client { DialogResult = DialogResult.Cancel; } + + private void setNotificationsUIElements() + { + groupCustomNotificationSettings.Enabled = useCustomTrayNotifications.Checked; + timeoutLabel.Text = useCustomTrayNotifications.Checked ? _customNotificationsTimeout : _windowsNotificationsTimeout; + timeout.Minimum = useCustomTrayNotifications.Checked ? -1 : 0; + } + + private void useCustomTrayNotifications_CheckedChanged(object sender, EventArgs e) + { + setNotificationsUIElements(); + } + + private const string _windowsNotificationsTimeout = "Notification Toast Timeout (seconds, may be ignored by OS based on accessibility settings):"; + private const string _customNotificationsTimeout = "Notification Toast Timeout (seconds, use -1 to require closing notification):"; } } diff --git a/ntfysh_client/SettingsModel.cs b/ntfysh_client/SettingsModel.cs index ef67969..b370db0 100644 --- a/ntfysh_client/SettingsModel.cs +++ b/ntfysh_client/SettingsModel.cs @@ -6,5 +6,9 @@ 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 bool CustomTrayNotificationsShowTimeoutBar { get; set; } + public bool CustomTrayNotificationsShowInDarkMode { get; set; } } } \ No newline at end of file