Compare commits
44 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d80e5bb756 | ||
|
e91c329feb | ||
|
d8cbe96875 | ||
|
4fbc4ca4e4 | ||
|
2add8ad2d6 | ||
|
1acd970af6 | ||
|
52f315e4e3 | ||
|
582eef1b9d | ||
|
1b51a06eb6 | ||
|
5f57898f9b | ||
|
025a7d04f8 | ||
|
c448de2c17 | ||
|
f187cd8ea6 | ||
|
7a5d067343 | ||
|
1ae481b434 | ||
|
c4e5a9059d | ||
|
ed13382e46 | ||
|
5977501b91 | ||
|
859a8938c0 | ||
|
f8dacac5a6 | ||
|
5b456c14a7 | ||
|
fc3275442c | ||
|
be0db848dc | ||
|
2cf458beae | ||
|
fa455baa57 | ||
|
934edb79eb | ||
|
8203e6c112 | ||
|
5414aa4996 | ||
|
42421d9820 | ||
|
93ac99dd7c | ||
|
7c5bb6f862 | ||
|
65f27c7c42 | ||
|
f908e9c4b0 | ||
|
9b902f1d38 | ||
|
a8af6ce48e | ||
|
c8ba64f5d8 | ||
|
8c04e82dac | ||
|
8ec1a89941 | ||
|
e24ef645ac | ||
|
f5298e1a4e | ||
|
3e43002b47 | ||
|
a7dcf3611c | ||
|
cb55d0148d | ||
|
0155cfb8fc |
@@ -16,6 +16,7 @@ namespace ntfysh_client
|
|||||||
private readonly NotificationListener _notificationListener;
|
private readonly NotificationListener _notificationListener;
|
||||||
private bool _startInTray;
|
private bool _startInTray;
|
||||||
private bool _trueExit;
|
private bool _trueExit;
|
||||||
|
private NotificationDialog _notificationDialog;
|
||||||
|
|
||||||
public MainForm(NotificationListener notificationListener, bool startInTray = false)
|
public MainForm(NotificationListener notificationListener, bool startInTray = false)
|
||||||
{
|
{
|
||||||
@@ -32,6 +33,8 @@ namespace ntfysh_client
|
|||||||
{
|
{
|
||||||
LoadSettings();
|
LoadSettings();
|
||||||
LoadTopics();
|
LoadTopics();
|
||||||
|
|
||||||
|
_notificationDialog = new NotificationDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SetVisibleCore(bool value)
|
protected override void SetVisibleCore(bool value)
|
||||||
@@ -70,8 +73,24 @@ 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.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);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
_notificationDialog.ShowNotification(
|
||||||
|
title: finalTitle,
|
||||||
|
message: e.Message,
|
||||||
|
timeoutSeconds: (int)Program.Settings.Timeout,
|
||||||
|
icon: priorityIcon,
|
||||||
|
showTimeOutBar: Program.Settings.CustomTrayNotificationsShowTimeoutBar,
|
||||||
|
showInDarkMode: Program.Settings.CustomTrayNotificationsShowInDarkMode,
|
||||||
|
playNotificationSound: Program.Settings.CustomTrayNotificationsPlayDefaultWindowsSound
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnConnectionMultiAttemptFailure(NotificationListener sender, SubscribedTopic topic)
|
private void OnConnectionMultiAttemptFailure(NotificationListener sender, SubscribedTopic topic)
|
||||||
{
|
{
|
||||||
@@ -93,14 +112,18 @@ namespace ntfysh_client
|
|||||||
//Do not subscribe on cancelled dialog
|
//Do not subscribe on cancelled dialog
|
||||||
if (result != DialogResult.OK) return;
|
if (result != DialogResult.OK) return;
|
||||||
|
|
||||||
|
//Convert the reconnection values to ints
|
||||||
|
int reconnectAttempts = Convert.ToInt32(Math.Ceiling(Program.Settings.ReconnectAttempts));
|
||||||
|
int reconnectAttemptDelay = Convert.ToInt32(Math.Ceiling(Program.Settings.ReconnectAttemptDelay));
|
||||||
|
|
||||||
//Subscribe
|
//Subscribe
|
||||||
if (dialog.UseWebsockets)
|
if (dialog.UseWebsockets)
|
||||||
{
|
{
|
||||||
_notificationListener.SubscribeToTopicUsingWebsocket(dialog.Unique, dialog.TopicId, dialog.ServerUrl, dialog.Username, dialog.Password);
|
_notificationListener.SubscribeToTopicUsingWebsocket(dialog.Unique, dialog.TopicId, dialog.ServerUrl, dialog.Username, dialog.Password, reconnectAttempts, reconnectAttemptDelay);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_notificationListener.SubscribeToTopicUsingLongHttpJson(dialog.Unique, dialog.TopicId, dialog.ServerUrl, dialog.Username, dialog.Password);
|
_notificationListener.SubscribeToTopicUsingLongHttpJson(dialog.Unique, dialog.TopicId, dialog.ServerUrl, dialog.Username, dialog.Password, reconnectAttempts, reconnectAttemptDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add to the user visible list
|
//Add to the user visible list
|
||||||
@@ -128,7 +151,14 @@ namespace ntfysh_client
|
|||||||
using SettingsDialog dialog = new();
|
using SettingsDialog dialog = new();
|
||||||
|
|
||||||
//Load current settings into dialog
|
//Load current settings into dialog
|
||||||
dialog.Timeout = Program.Settings.Timeout;
|
dialog.ReconnectAttempts = Program.Settings.ReconnectAttempts;
|
||||||
|
dialog.ReconnectAttemptDelay = Program.Settings.ReconnectAttemptDelay;
|
||||||
|
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.CustomTrayNotificationsPlayDefaultWindowsSound = Program.Settings.CustomTrayNotificationsPlayDefaultWindowsSound;
|
||||||
|
dialog.Timeout = Program.Settings.Timeout; // set timeout last so bounds are setup before setting value
|
||||||
|
|
||||||
//Show dialog
|
//Show dialog
|
||||||
DialogResult result = dialog.ShowDialog();
|
DialogResult result = dialog.ShowDialog();
|
||||||
@@ -138,6 +168,12 @@ namespace ntfysh_client
|
|||||||
|
|
||||||
//Read new settings from dialog
|
//Read new settings from dialog
|
||||||
Program.Settings.Timeout = dialog.Timeout;
|
Program.Settings.Timeout = dialog.Timeout;
|
||||||
|
Program.Settings.ReconnectAttempts = dialog.ReconnectAttempts;
|
||||||
|
Program.Settings.ReconnectAttemptDelay = dialog.ReconnectAttemptDelay;
|
||||||
|
Program.Settings.NotificationsMethod = (dialog.UseNativeWindowsNotifications)? SettingsModel.NotificationsType.NativeWindows : SettingsModel.NotificationsType.CustomTray;
|
||||||
|
Program.Settings.CustomTrayNotificationsShowTimeoutBar = dialog.CustomTrayNotificationsShowTimeoutBar;
|
||||||
|
Program.Settings.CustomTrayNotificationsShowInDarkMode = dialog.CustomTrayNotificationsShowInDarkMode;
|
||||||
|
Program.Settings.CustomTrayNotificationsPlayDefaultWindowsSound = dialog.CustomTrayNotificationsPlayDefaultWindowsSound;
|
||||||
|
|
||||||
//Save new settings persistently
|
//Save new settings persistently
|
||||||
SaveSettingsToFile();
|
SaveSettingsToFile();
|
||||||
@@ -259,6 +295,10 @@ namespace ntfysh_client
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Convert the reconnection values to ints
|
||||||
|
int reconnectAttempts = Convert.ToInt32(Math.Ceiling(Program.Settings.ReconnectAttempts));
|
||||||
|
int reconnectAttemptDelay = Convert.ToInt32(Math.Ceiling(Program.Settings.ReconnectAttemptDelay));
|
||||||
|
|
||||||
//Load them in
|
//Load them in
|
||||||
foreach (SubscribedTopic topic in topics)
|
foreach (SubscribedTopic topic in topics)
|
||||||
{
|
{
|
||||||
@@ -268,12 +308,12 @@ namespace ntfysh_client
|
|||||||
{
|
{
|
||||||
case "ws":
|
case "ws":
|
||||||
case "wss":
|
case "wss":
|
||||||
_notificationListener.SubscribeToTopicUsingWebsocket($"{topic.TopicId}@{topic.ServerUrl}", topic.TopicId, topic.ServerUrl, topic.Username, topic.Password);
|
_notificationListener.SubscribeToTopicUsingWebsocket($"{topic.TopicId}@{topic.ServerUrl}", topic.TopicId, topic.ServerUrl, topic.Username, topic.Password, reconnectAttempts, reconnectAttemptDelay);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "http":
|
case "http":
|
||||||
case "https":
|
case "https":
|
||||||
_notificationListener.SubscribeToTopicUsingLongHttpJson($"{topic.TopicId}@{topic.ServerUrl}", topic.TopicId, topic.ServerUrl, topic.Username, topic.Password);
|
_notificationListener.SubscribeToTopicUsingLongHttpJson($"{topic.TopicId}@{topic.ServerUrl}", topic.TopicId, topic.ServerUrl, topic.Username, topic.Password, reconnectAttempts, reconnectAttemptDelay);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -286,17 +326,47 @@ namespace ntfysh_client
|
|||||||
|
|
||||||
private SettingsModel GetDefaultSettings() => new()
|
private SettingsModel GetDefaultSettings() => new()
|
||||||
{
|
{
|
||||||
Timeout = 5
|
Revision = 2,
|
||||||
|
Timeout = 5,
|
||||||
|
ReconnectAttempts = 10,
|
||||||
|
ReconnectAttemptDelay = 3,
|
||||||
|
NotificationsMethod = SettingsModel.NotificationsType.NativeWindows,
|
||||||
|
CustomTrayNotificationsShowTimeoutBar = true,
|
||||||
|
CustomTrayNotificationsShowInDarkMode = false,
|
||||||
|
CustomTrayNotificationsPlayDefaultWindowsSound = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private void MergeSettingsRevisions(SettingsModel older, SettingsModel newer)
|
||||||
|
{
|
||||||
|
//Apply settings introduced in Revision 1
|
||||||
|
if (older.Revision < 1)
|
||||||
|
{
|
||||||
|
older.ReconnectAttempts = newer.ReconnectAttempts;
|
||||||
|
older.ReconnectAttemptDelay = newer.ReconnectAttemptDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Apply settings introduced in Revision 2 (Native vs custom notifications)
|
||||||
|
if (older.Revision < 2)
|
||||||
|
{
|
||||||
|
older.NotificationsMethod = newer.NotificationsMethod;
|
||||||
|
older.CustomTrayNotificationsShowTimeoutBar = newer.CustomTrayNotificationsShowTimeoutBar;
|
||||||
|
older.CustomTrayNotificationsShowInDarkMode = newer.CustomTrayNotificationsShowInDarkMode;
|
||||||
|
older.CustomTrayNotificationsPlayDefaultWindowsSound = newer.CustomTrayNotificationsPlayDefaultWindowsSound;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Update the revision
|
||||||
|
older.Revision = newer.Revision;
|
||||||
|
}
|
||||||
|
|
||||||
private void LoadSettings()
|
private void LoadSettings()
|
||||||
{
|
{
|
||||||
string settingsFilePath = GetSettingsFilePath();
|
string settingsFilePath = GetSettingsFilePath();
|
||||||
|
SettingsModel defaultSettings = GetDefaultSettings();
|
||||||
|
|
||||||
//Check if we have any settings file on disk to load. If we don't, initialise defaults
|
//Check if we have any settings file on disk to load. If we don't, initialise defaults
|
||||||
if (!File.Exists(settingsFilePath))
|
if (!File.Exists(settingsFilePath))
|
||||||
{
|
{
|
||||||
Program.Settings = GetDefaultSettings();
|
Program.Settings = defaultSettings;
|
||||||
|
|
||||||
SaveSettingsToFile();
|
SaveSettingsToFile();
|
||||||
|
|
||||||
@@ -309,7 +379,7 @@ namespace ntfysh_client
|
|||||||
//Check if the file is empty. If it is, initialise default settings
|
//Check if the file is empty. If it is, initialise default settings
|
||||||
if (string.IsNullOrWhiteSpace(settingsSerialised))
|
if (string.IsNullOrWhiteSpace(settingsSerialised))
|
||||||
{
|
{
|
||||||
Program.Settings = GetDefaultSettings();
|
Program.Settings = defaultSettings;
|
||||||
|
|
||||||
SaveSettingsToFile();
|
SaveSettingsToFile();
|
||||||
|
|
||||||
@@ -322,7 +392,7 @@ namespace ntfysh_client
|
|||||||
//Check if the deserialise succeeded. If it didn't, initialise default settings
|
//Check if the deserialise succeeded. If it didn't, initialise default settings
|
||||||
if (settings is null)
|
if (settings is null)
|
||||||
{
|
{
|
||||||
Program.Settings = GetDefaultSettings();
|
Program.Settings = defaultSettings;
|
||||||
|
|
||||||
SaveSettingsToFile();
|
SaveSettingsToFile();
|
||||||
|
|
||||||
@@ -330,6 +400,13 @@ namespace ntfysh_client
|
|||||||
}
|
}
|
||||||
|
|
||||||
Program.Settings = settings;
|
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.Revision)
|
||||||
|
{
|
||||||
|
MergeSettingsRevisions(Program.Settings, defaultSettings);
|
||||||
|
SaveSettingsToFile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
|
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
|
||||||
|
146
ntfysh_client/NotificationDialog.Designer.cs
generated
Normal file
146
ntfysh_client/NotificationDialog.Designer.cs
generated
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
namespace ntfysh_client
|
||||||
|
{
|
||||||
|
partial class NotificationDialog
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
TxBTitle = new System.Windows.Forms.TextBox();
|
||||||
|
ButtonClose = new System.Windows.Forms.Button();
|
||||||
|
TxBMessage = new System.Windows.Forms.RichTextBox();
|
||||||
|
IconBox = new System.Windows.Forms.PictureBox();
|
||||||
|
ProgressBar1 = new System.Windows.Forms.ProgressBar();
|
||||||
|
LblTimeout = new System.Windows.Forms.Label();
|
||||||
|
((System.ComponentModel.ISupportInitialize)IconBox).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// TxBTitle
|
||||||
|
//
|
||||||
|
TxBTitle.BackColor = System.Drawing.SystemColors.ControlDark;
|
||||||
|
TxBTitle.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||||
|
TxBTitle.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
TxBTitle.ForeColor = System.Drawing.SystemColors.ControlLightLight;
|
||||||
|
TxBTitle.Location = new System.Drawing.Point(54, 13);
|
||||||
|
TxBTitle.Name = "TxBTitle";
|
||||||
|
TxBTitle.ReadOnly = true;
|
||||||
|
TxBTitle.Size = new System.Drawing.Size(683, 32);
|
||||||
|
TxBTitle.TabIndex = 0;
|
||||||
|
TxBTitle.MouseDown += window_MouseDown;
|
||||||
|
//
|
||||||
|
// ButtonClose
|
||||||
|
//
|
||||||
|
ButtonClose.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
|
||||||
|
ButtonClose.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
|
||||||
|
ButtonClose.FlatAppearance.BorderSize = 0;
|
||||||
|
ButtonClose.FlatAppearance.MouseOverBackColor = System.Drawing.Color.DimGray;
|
||||||
|
ButtonClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||||
|
ButtonClose.ForeColor = System.Drawing.SystemColors.ButtonFace;
|
||||||
|
ButtonClose.Location = new System.Drawing.Point(759, 7);
|
||||||
|
ButtonClose.Name = "ButtonClose";
|
||||||
|
ButtonClose.Size = new System.Drawing.Size(29, 38);
|
||||||
|
ButtonClose.TabIndex = 1;
|
||||||
|
ButtonClose.Text = "X";
|
||||||
|
ButtonClose.UseVisualStyleBackColor = false;
|
||||||
|
ButtonClose.Click += ButtonClose_ClickHandler;
|
||||||
|
//
|
||||||
|
// TxBMessage
|
||||||
|
//
|
||||||
|
TxBMessage.BackColor = System.Drawing.SystemColors.ControlDark;
|
||||||
|
TxBMessage.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||||
|
TxBMessage.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
TxBMessage.ForeColor = System.Drawing.SystemColors.ControlLightLight;
|
||||||
|
TxBMessage.Location = new System.Drawing.Point(12, 57);
|
||||||
|
TxBMessage.Name = "TxBMessage";
|
||||||
|
TxBMessage.ReadOnly = true;
|
||||||
|
TxBMessage.Size = new System.Drawing.Size(776, 191);
|
||||||
|
TxBMessage.TabIndex = 2;
|
||||||
|
TxBMessage.Text = "";
|
||||||
|
TxBMessage.MouseDown += window_MouseDown;
|
||||||
|
//
|
||||||
|
// IconBox
|
||||||
|
//
|
||||||
|
IconBox.Location = new System.Drawing.Point(12, 12);
|
||||||
|
IconBox.Name = "IconBox";
|
||||||
|
IconBox.Size = new System.Drawing.Size(36, 39);
|
||||||
|
IconBox.TabIndex = 3;
|
||||||
|
IconBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// ProgressBar1
|
||||||
|
//
|
||||||
|
ProgressBar1.BackColor = System.Drawing.SystemColors.ControlDarkDark;
|
||||||
|
ProgressBar1.Enabled = false;
|
||||||
|
ProgressBar1.ForeColor = System.Drawing.SystemColors.WindowFrame;
|
||||||
|
ProgressBar1.Location = new System.Drawing.Point(70, 254);
|
||||||
|
ProgressBar1.MarqueeAnimationSpeed = 1;
|
||||||
|
ProgressBar1.Name = "ProgressBar1";
|
||||||
|
ProgressBar1.Size = new System.Drawing.Size(718, 23);
|
||||||
|
ProgressBar1.Step = 1;
|
||||||
|
ProgressBar1.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
|
||||||
|
ProgressBar1.TabIndex = 4;
|
||||||
|
ProgressBar1.Value = 100;
|
||||||
|
//
|
||||||
|
// LblTimeout
|
||||||
|
//
|
||||||
|
LblTimeout.AutoSize = true;
|
||||||
|
LblTimeout.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
LblTimeout.Location = new System.Drawing.Point(21, 254);
|
||||||
|
LblTimeout.Name = "LblTimeout";
|
||||||
|
LblTimeout.Size = new System.Drawing.Size(43, 17);
|
||||||
|
LblTimeout.TabIndex = 5;
|
||||||
|
LblTimeout.Text = "label1";
|
||||||
|
LblTimeout.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
||||||
|
//
|
||||||
|
// NotificationDialog
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
BackColor = System.Drawing.SystemColors.ControlDark;
|
||||||
|
ClientSize = new System.Drawing.Size(800, 289);
|
||||||
|
Controls.Add(LblTimeout);
|
||||||
|
Controls.Add(ProgressBar1);
|
||||||
|
Controls.Add(IconBox);
|
||||||
|
Controls.Add(TxBMessage);
|
||||||
|
Controls.Add(ButtonClose);
|
||||||
|
Controls.Add(TxBTitle);
|
||||||
|
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
||||||
|
Name = "NotificationDialog";
|
||||||
|
Text = "NotificationDialog";
|
||||||
|
Click += window_MouseDown;
|
||||||
|
((System.ComponentModel.ISupportInitialize)IconBox).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.TextBox TxBTitle;
|
||||||
|
private System.Windows.Forms.Button ButtonClose;
|
||||||
|
private System.Windows.Forms.RichTextBox TxBMessage;
|
||||||
|
private System.Windows.Forms.PictureBox IconBox;
|
||||||
|
private System.Windows.Forms.ProgressBar ProgressBar1;
|
||||||
|
private System.Windows.Forms.Label LblTimeout;
|
||||||
|
}
|
||||||
|
}
|
295
ntfysh_client/NotificationDialog.cs
Normal file
295
ntfysh_client/NotificationDialog.cs
Normal file
@@ -0,0 +1,295 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using ntfysh_client.Themes;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using System.Media;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ntfysh_client
|
||||||
|
{
|
||||||
|
public partial class NotificationDialog : Form
|
||||||
|
{
|
||||||
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||||
|
private static extern bool AnimateWindow(IntPtr hWnd, int time, int flags);
|
||||||
|
|
||||||
|
private const int ScreenMargin = 20;
|
||||||
|
|
||||||
|
private int _timeoutSeconds = 0;
|
||||||
|
private System.Timers.Timer? _displayTimeoutTimer = null;
|
||||||
|
private System.Windows.Forms.Timer? _updateTimer = null;
|
||||||
|
private Stopwatch? _shownStopwatch = null;
|
||||||
|
|
||||||
|
private readonly BaseTheme _darkModeTheme = new DarkModeTheme();
|
||||||
|
private readonly BaseTheme _defaultTheme = new DefaultTheme();
|
||||||
|
private BaseTheme? _theme = null;
|
||||||
|
|
||||||
|
public NotificationDialog()
|
||||||
|
{
|
||||||
|
ShowInTaskbar = false;
|
||||||
|
Visible = false;
|
||||||
|
TopMost = true;
|
||||||
|
InitializeComponent();
|
||||||
|
InitializeWindowHidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowNotification(string title, string message, int timeoutSeconds = 0, ToolTipIcon? icon = null, bool showTimeOutBar = true, bool showInDarkMode = true, bool playNotificationSound = false)
|
||||||
|
{
|
||||||
|
if (Visible)
|
||||||
|
{
|
||||||
|
// close the current notification
|
||||||
|
HandleTimeout(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
_theme = showInDarkMode ? _darkModeTheme : _defaultTheme;
|
||||||
|
|
||||||
|
ApplyTheme();
|
||||||
|
|
||||||
|
// setup data
|
||||||
|
IconBox.Image = (icon is null) ? null : ConvertToolTipIconToImage(icon.Value);
|
||||||
|
|
||||||
|
TxBTitle.Text = title;
|
||||||
|
TxBMessage.Text = message;
|
||||||
|
|
||||||
|
// setup timers
|
||||||
|
if (_displayTimeoutTimer != null)
|
||||||
|
{
|
||||||
|
_displayTimeoutTimer.Stop();
|
||||||
|
_displayTimeoutTimer.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_updateTimer != null)
|
||||||
|
{
|
||||||
|
_updateTimer.Stop();
|
||||||
|
_updateTimer.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeoutSeconds > 0)
|
||||||
|
{
|
||||||
|
_displayTimeoutTimer = new System.Timers.Timer(timeoutSeconds * 1000);
|
||||||
|
_displayTimeoutTimer.Elapsed += HandleTimeout;
|
||||||
|
_displayTimeoutTimer.Start();
|
||||||
|
|
||||||
|
if (showTimeOutBar)
|
||||||
|
{
|
||||||
|
ProgressBar1.Value = 100;
|
||||||
|
_updateTimer = new System.Windows.Forms.Timer();
|
||||||
|
_updateTimer.Interval = 100;
|
||||||
|
_updateTimer.Tick += UpdateProgress;
|
||||||
|
_updateTimer.Start();
|
||||||
|
|
||||||
|
_shownStopwatch = new Stopwatch();
|
||||||
|
_shownStopwatch.Start();
|
||||||
|
|
||||||
|
ProgressBar1.Visible = true;
|
||||||
|
LblTimeout.Visible = true;
|
||||||
|
_timeoutSeconds = timeoutSeconds;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProgressBar1.Visible = false;
|
||||||
|
LblTimeout.Visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProgressBar1.Visible = false;
|
||||||
|
LblTimeout.Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ok, show the window
|
||||||
|
Show();
|
||||||
|
ButtonClose.Focus(); // make sure the window is focused, not the title box.
|
||||||
|
SetWindowPosition();
|
||||||
|
|
||||||
|
if (playNotificationSound) PlayNotificationSound();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyTheme()
|
||||||
|
{
|
||||||
|
_theme ??= _defaultTheme;
|
||||||
|
|
||||||
|
// back colors
|
||||||
|
BackColor = _theme.BackgroundColor;
|
||||||
|
TxBTitle.BackColor = _theme.BackgroundColor;
|
||||||
|
TxBMessage.BackColor = _theme.BackgroundColor;
|
||||||
|
LblTimeout.BackColor = _theme.BackgroundColor;
|
||||||
|
ProgressBar1.BackColor = _theme.BackgroundColor;
|
||||||
|
|
||||||
|
// this one is not "hiding"
|
||||||
|
ButtonClose.BackColor = _theme.ControlBackGroundColor;
|
||||||
|
ButtonClose.ForeColor = _theme.BackgroundColor;
|
||||||
|
// handle mouse over
|
||||||
|
ButtonClose.FlatAppearance.MouseOverBackColor = _theme.ControlMouseOverBackgroundColor;
|
||||||
|
|
||||||
|
// fore colors
|
||||||
|
ForeColor = _theme.ForegroundColor;
|
||||||
|
TxBTitle.ForeColor = _theme.ForegroundColor;
|
||||||
|
TxBMessage.ForeColor = _theme.ForegroundColor;
|
||||||
|
LblTimeout.ForeColor = _theme.ForegroundColor;
|
||||||
|
ProgressBar1.ForeColor = _theme.ForegroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateProgress(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_shownStopwatch is null) return;
|
||||||
|
|
||||||
|
ProgressBar1.Value = (_timeoutSeconds - _shownStopwatch.Elapsed.Seconds) * 100 / _timeoutSeconds;
|
||||||
|
LblTimeout.Text = $@"{_timeoutSeconds - _shownStopwatch.Elapsed.Seconds}";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void SetVisibleCore(bool value)
|
||||||
|
{
|
||||||
|
SetWindowPosition();
|
||||||
|
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
BringToFront();
|
||||||
|
|
||||||
|
AnimateWindow(
|
||||||
|
Handle,
|
||||||
|
time: 250,
|
||||||
|
flags: NFWinUserAnimateWindowConstants.AW_SLIDE | NFWinUserAnimateWindowConstants.AW_VER_NEGATIVE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
base.SetVisibleCore(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetWindowPosition()
|
||||||
|
{
|
||||||
|
var workingTop = Screen.PrimaryScreen.WorkingArea.Height - Height;
|
||||||
|
Top = workingTop - NotificationDialog.ScreenMargin;
|
||||||
|
|
||||||
|
var workingLeft = Screen.PrimaryScreen.WorkingArea.Width - Width;
|
||||||
|
Left = workingLeft - NotificationDialog.ScreenMargin;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UIThreadAnimatedHideWindow(object? sender, EventArgs? e)
|
||||||
|
{
|
||||||
|
|
||||||
|
AnimateWindow(
|
||||||
|
Handle,
|
||||||
|
time: 250,
|
||||||
|
flags: NFWinUserAnimateWindowConstants.AW_SLIDE | NFWinUserAnimateWindowConstants.AW_VER_POSITIVE | NFWinUserAnimateWindowConstants.AW_HIDE
|
||||||
|
);
|
||||||
|
|
||||||
|
Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleTimeout(object? sender, EventArgs? e)
|
||||||
|
{
|
||||||
|
CancelTimer();
|
||||||
|
|
||||||
|
if (InvokeRequired)
|
||||||
|
{
|
||||||
|
// on a background thread, so invoke on the UI thread
|
||||||
|
Invoke(new Action(() => UIThreadAnimatedHideWindow(sender, e)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// in the UI thread, invoke directly
|
||||||
|
UIThreadAnimatedHideWindow(sender, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Image? ConvertToolTipIconToImage(ToolTipIcon icon) => icon switch
|
||||||
|
{
|
||||||
|
ToolTipIcon.Info => SystemIcons.Information.ToBitmap(),
|
||||||
|
ToolTipIcon.Warning => SystemIcons.Warning.ToBitmap(),
|
||||||
|
ToolTipIcon.Error => SystemIcons.Error.ToBitmap(),
|
||||||
|
_ => null
|
||||||
|
};
|
||||||
|
|
||||||
|
private void InitializeWindowHidden()
|
||||||
|
{
|
||||||
|
Opacity = 0;
|
||||||
|
ShowNotification("Title", "Message");
|
||||||
|
ButtonClose.Focus();
|
||||||
|
Visible = false;
|
||||||
|
Opacity = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonClose_ClickHandler(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// don't animate, immediately "close"
|
||||||
|
Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NFWinUserAnimateWindowConstants
|
||||||
|
{
|
||||||
|
public const int AW_HOR_POSITIVE = 0x00000001;
|
||||||
|
public const int AW_HOR_NEGATIVE = 0x00000002;
|
||||||
|
public const int AW_VER_POSITIVE = 0x00000004;
|
||||||
|
public const int AW_VER_NEGATIVE = 0x00000008;
|
||||||
|
public const int AW_CENTER = 0x00000010;
|
||||||
|
public const int AW_HIDE = 0x00010000;
|
||||||
|
public const int AW_ACTIVATE = 0x00020000;
|
||||||
|
public const int AW_SLIDE = 0x00040000;
|
||||||
|
public const int AW_BLEND = 0x00080000;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void window_MouseDown(object sender, EventArgs e) => CancelTimer();
|
||||||
|
|
||||||
|
private void CancelTimer()
|
||||||
|
{
|
||||||
|
if (InvokeRequired)
|
||||||
|
{
|
||||||
|
// on a background thread, so invoke on the UI thread
|
||||||
|
Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
LblTimeout.Visible = false;
|
||||||
|
ProgressBar1.Visible = false;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// in the UI thread, invoke directly
|
||||||
|
LblTimeout.Visible = false;
|
||||||
|
ProgressBar1.Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_displayTimeoutTimer != null) // check if the timer has already been disposed
|
||||||
|
{
|
||||||
|
_displayTimeoutTimer.Stop();
|
||||||
|
_displayTimeoutTimer.Dispose();
|
||||||
|
_displayTimeoutTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_updateTimer != null)
|
||||||
|
{
|
||||||
|
_updateTimer.Stop();
|
||||||
|
_updateTimer.Dispose();
|
||||||
|
_updateTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_shownStopwatch != null)
|
||||||
|
{
|
||||||
|
_shownStopwatch.Stop();
|
||||||
|
_shownStopwatch = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PlayNotificationSound()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using RegistryKey? defaultSoundPathKey = Registry.CurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\.Default\Notification.Default\.Current");
|
||||||
|
|
||||||
|
if (defaultSoundPathKey is null) throw new Exception();
|
||||||
|
|
||||||
|
if (defaultSoundPathKey.GetValue(null) is not string defaultSoundPath) throw new Exception();
|
||||||
|
|
||||||
|
SoundPlayer loadedSound = new(defaultSoundPath);
|
||||||
|
|
||||||
|
loadedSound.Play();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
SystemSounds.Beep.Play(); // consolation prize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ntfysh_client/NotificationDialog.resx
Normal file
120
ntfysh_client/NotificationDialog.resx
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@@ -31,16 +31,16 @@ namespace ntfysh_client.Notifications
|
|||||||
ServicePointManager.DefaultConnectionLimit = 100;
|
ServicePointManager.DefaultConnectionLimit = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ListenToTopicWithHttpLongJsonAsync(HttpRequestMessage message, CancellationToken cancellationToken, SubscribedTopic topic)
|
private async Task ListenToTopicWithHttpLongJsonAsync(HttpRequestMessage message, SubscribedTopic topic, int reconnectAttempts = 10, int reconnectAttemptDelay = 3, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
int connectionAttempts = 0;
|
int connectionAttempts = 0;
|
||||||
|
|
||||||
while (!cancellationToken.IsCancellationRequested)
|
while (!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
//See if we have exceeded maximum attempts
|
//See if we have exceeded maximum attempts
|
||||||
if (connectionAttempts >= 10)
|
if (reconnectAttempts != 0 && connectionAttempts >= reconnectAttempts)
|
||||||
{
|
{
|
||||||
//10 connection failures (1 initial + 9 reattempts)! Do not retry
|
//<reconnectAttempts> connection failures (1 initial + (<reconnectAttempts> - 1) reattempts)! Do not retry
|
||||||
OnConnectionMultiAttemptFailure?.Invoke(this, topic);
|
OnConnectionMultiAttemptFailure?.Invoke(this, topic);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -119,16 +119,16 @@ namespace ntfysh_client.Notifications
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
//We land here if we fail to connect or our connection gets closed (and if we are canceeling, but that gets ignored)
|
//We land here if we fail to connect or our connection gets closed (and if we are canceling, but that gets ignored)
|
||||||
|
|
||||||
if (!cancellationToken.IsCancellationRequested)
|
if (!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
//Not cancelling, legitimate connection failure or termination
|
//Not cancelling, legitimate connection failure or termination
|
||||||
|
|
||||||
if (connectionAttempts != 0)
|
if (reconnectAttempts == 0 || connectionAttempts != 0)
|
||||||
{
|
{
|
||||||
//On our first reconnect attempt, try instantly. On consecutive, wait 3 seconds before each attempt
|
//On our first reconnect attempt, try instantly (unless we have infinite retries). On consecutive, wait <reconnectAttemptDelay> seconds before each attempt
|
||||||
await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken);
|
await Task.Delay(TimeSpan.FromSeconds(reconnectAttemptDelay), cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Increment attempts
|
//Increment attempts
|
||||||
@@ -140,16 +140,16 @@ namespace ntfysh_client.Notifications
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ListenToTopicWithWebsocketAsync(Uri uri, string? credentials, CancellationToken cancellationToken, SubscribedTopic topic)
|
private async Task ListenToTopicWithWebsocketAsync(Uri uri, string? credentials, SubscribedTopic topic, int reconnectAttempts = 10, int reconnectAttemptDelay = 3, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
int connectionAttempts = 0;
|
int connectionAttempts = 0;
|
||||||
|
|
||||||
while (!cancellationToken.IsCancellationRequested)
|
while (!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
//See if we have exceeded maximum attempts
|
//See if we have exceeded maximum attempts
|
||||||
if (connectionAttempts >= 10)
|
if (reconnectAttempts != 0 && connectionAttempts >= reconnectAttempts)
|
||||||
{
|
{
|
||||||
//10 connection failures (1 initial + 9 reattempts)! Do not retry
|
//<reconnectAttempts> connection failures (1 initial + (<reconnectAttempts> - 1) reattempts)! Do not retry
|
||||||
OnConnectionMultiAttemptFailure?.Invoke(this, topic);
|
OnConnectionMultiAttemptFailure?.Invoke(this, topic);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -223,16 +223,16 @@ namespace ntfysh_client.Notifications
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
//We land here if we fail to connect or our connection gets closed (and if we are canceeling, but that gets ignored)
|
//We land here if we fail to connect or our connection gets closed (and if we are canceling, but that gets ignored)
|
||||||
|
|
||||||
if (!cancellationToken.IsCancellationRequested)
|
if (!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
//Not cancelling, legitimate connection failure or termination
|
//Not cancelling, legitimate connection failure or termination
|
||||||
|
|
||||||
if (connectionAttempts != 0)
|
if (reconnectAttempts == 0 || connectionAttempts != 0)
|
||||||
{
|
{
|
||||||
//On our first reconnect attempt, try instantly. On consecutive, wait 3 seconds before each attempt
|
//On our first reconnect attempt, try instantly (unless we have infinite retries). On consecutive, wait <reconnectAttemptDelay> seconds before each attempt
|
||||||
await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken);
|
await Task.Delay(TimeSpan.FromSeconds(reconnectAttemptDelay), cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Increment attempts
|
//Increment attempts
|
||||||
@@ -261,13 +261,16 @@ namespace ntfysh_client.Notifications
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SubscribeToTopicUsingLongHttpJson(string unique, string topicId, string serverUrl, string? username, string? password)
|
public void SubscribeToTopicUsingLongHttpJson(string unique, string topicId, string serverUrl, string? username, string? password, int reconnectAttempts, int reconnectAttemptDelay)
|
||||||
{
|
{
|
||||||
if (SubscribedTopicsByUnique.ContainsKey(unique)) throw new InvalidOperationException("A topic with this unique already exists");
|
if (SubscribedTopicsByUnique.ContainsKey(unique)) throw new ArgumentException("A topic with this unique already exists", nameof(unique));
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(username)) username = null;
|
if (string.IsNullOrWhiteSpace(username)) username = null;
|
||||||
if (string.IsNullOrWhiteSpace(password)) password = null;
|
if (string.IsNullOrWhiteSpace(password)) password = null;
|
||||||
|
|
||||||
|
if (reconnectAttempts < 0) throw new ArgumentException("Reconnect attempts must be 0 or more", nameof(reconnectAttempts));
|
||||||
|
if (reconnectAttemptDelay < 0) throw new ArgumentException("Reconnect attempt delay; must be 0 or more", nameof(reconnectAttemptDelay));
|
||||||
|
|
||||||
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, $"{serverUrl}/{HttpUtility.UrlEncode(topicId)}/json");
|
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, $"{serverUrl}/{HttpUtility.UrlEncode(topicId)}/json");
|
||||||
|
|
||||||
if (username is not null && password is not null)
|
if (username is not null && password is not null)
|
||||||
@@ -280,20 +283,23 @@ namespace ntfysh_client.Notifications
|
|||||||
SubscribedTopic newTopic = new(topicId, serverUrl, username, password);
|
SubscribedTopic newTopic = new(topicId, serverUrl, username, password);
|
||||||
|
|
||||||
CancellationTokenSource listenCanceller = new();
|
CancellationTokenSource listenCanceller = new();
|
||||||
Task listenTask = ListenToTopicWithHttpLongJsonAsync(message, listenCanceller.Token, newTopic);
|
Task listenTask = ListenToTopicWithHttpLongJsonAsync(message, newTopic, reconnectAttempts, reconnectAttemptDelay, listenCanceller.Token);
|
||||||
|
|
||||||
newTopic.SetAssociatedRunner(listenTask, listenCanceller);
|
newTopic.SetAssociatedRunner(listenTask, listenCanceller);
|
||||||
|
|
||||||
SubscribedTopicsByUnique.Add(unique, newTopic);
|
SubscribedTopicsByUnique.Add(unique, newTopic);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SubscribeToTopicUsingWebsocket(string unique, string topicId, string serverUrl, string? username, string? password)
|
public void SubscribeToTopicUsingWebsocket(string unique, string topicId, string serverUrl, string? username, string? password, int reconnectAttempts, int reconnectAttemptDelay)
|
||||||
{
|
{
|
||||||
if (SubscribedTopicsByUnique.ContainsKey(unique)) throw new InvalidOperationException("A topic with this unique already exists");
|
if (SubscribedTopicsByUnique.ContainsKey(unique)) throw new ArgumentException("A topic with this unique already exists", nameof(unique));
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(username)) username = null;
|
if (string.IsNullOrWhiteSpace(username)) username = null;
|
||||||
if (string.IsNullOrWhiteSpace(password)) password = null;
|
if (string.IsNullOrWhiteSpace(password)) password = null;
|
||||||
|
|
||||||
|
if (reconnectAttempts < 0) throw new ArgumentException("Reconnect attempts must be 0 or more", nameof(reconnectAttempts));
|
||||||
|
if (reconnectAttemptDelay < 0) throw new ArgumentException("Reconnect attempt delay; must be 0 or more", nameof(reconnectAttemptDelay));
|
||||||
|
|
||||||
SubscribedTopic newTopic = new(topicId, serverUrl, username, password);
|
SubscribedTopic newTopic = new(topicId, serverUrl, username, password);
|
||||||
|
|
||||||
string? credentials = null;
|
string? credentials = null;
|
||||||
@@ -306,7 +312,7 @@ namespace ntfysh_client.Notifications
|
|||||||
}
|
}
|
||||||
|
|
||||||
CancellationTokenSource listenCanceller = new();
|
CancellationTokenSource listenCanceller = new();
|
||||||
Task listenTask = ListenToTopicWithWebsocketAsync(new Uri($"{serverUrl}/{HttpUtility.UrlEncode(topicId)}/ws"), credentials, listenCanceller.Token, newTopic);
|
Task listenTask = ListenToTopicWithWebsocketAsync(new Uri($"{serverUrl}/{HttpUtility.UrlEncode(topicId)}/ws"), credentials, newTopic, reconnectAttempts, reconnectAttemptDelay, listenCanceller.Token);
|
||||||
|
|
||||||
newTopic.SetAssociatedRunner(listenTask, listenCanceller);
|
newTopic.SetAssociatedRunner(listenTask, listenCanceller);
|
||||||
|
|
||||||
|
300
ntfysh_client/SettingsDialog.Designer.cs
generated
300
ntfysh_client/SettingsDialog.Designer.cs
generated
@@ -29,101 +29,255 @@ namespace ntfysh_client
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.panel1 = new System.Windows.Forms.Panel();
|
buttonPanel = new System.Windows.Forms.Panel();
|
||||||
this.cancelButton = new System.Windows.Forms.Button();
|
cancelButton = new System.Windows.Forms.Button();
|
||||||
this.saveButton = new System.Windows.Forms.Button();
|
saveButton = new System.Windows.Forms.Button();
|
||||||
this.label1 = new System.Windows.Forms.Label();
|
timeoutLabel = new System.Windows.Forms.Label();
|
||||||
this.timeout = new System.Windows.Forms.NumericUpDown();
|
timeout = new System.Windows.Forms.NumericUpDown();
|
||||||
this.panel1.SuspendLayout();
|
reconnectAttempts = new System.Windows.Forms.NumericUpDown();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.timeout)).BeginInit();
|
reconnectAttemptsLabel = new System.Windows.Forms.Label();
|
||||||
this.SuspendLayout();
|
reconnectAttemptDelay = new System.Windows.Forms.NumericUpDown();
|
||||||
|
reconnectAttemptDelayLabel = new System.Windows.Forms.Label();
|
||||||
|
nativeVersusCustomNotificationsGroupBox = new System.Windows.Forms.GroupBox();
|
||||||
|
useCustomTrayNotifications = new System.Windows.Forms.RadioButton();
|
||||||
|
useNativeWindowsNotifications = new System.Windows.Forms.RadioButton();
|
||||||
|
groupCustomNotificationSettings = new System.Windows.Forms.GroupBox();
|
||||||
|
customNotificationsPlayWindowsNotificationAudio = new System.Windows.Forms.CheckBox();
|
||||||
|
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();
|
||||||
|
nativeVersusCustomNotificationsGroupBox.SuspendLayout();
|
||||||
|
groupCustomNotificationSettings.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// panel1
|
// buttonPanel
|
||||||
//
|
//
|
||||||
this.panel1.BackColor = System.Drawing.SystemColors.Control;
|
buttonPanel.BackColor = System.Drawing.SystemColors.Control;
|
||||||
this.panel1.Controls.Add(this.cancelButton);
|
buttonPanel.Controls.Add(cancelButton);
|
||||||
this.panel1.Controls.Add(this.saveButton);
|
buttonPanel.Controls.Add(saveButton);
|
||||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
|
buttonPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||||
this.panel1.Location = new System.Drawing.Point(0, 61);
|
buttonPanel.Location = new System.Drawing.Point(0, 336);
|
||||||
this.panel1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
buttonPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.panel1.Name = "panel1";
|
buttonPanel.Name = "buttonPanel";
|
||||||
this.panel1.Size = new System.Drawing.Size(531, 51);
|
buttonPanel.Size = new System.Drawing.Size(531, 51);
|
||||||
this.panel1.TabIndex = 9;
|
buttonPanel.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// cancelButton
|
// cancelButton
|
||||||
//
|
//
|
||||||
this.cancelButton.Location = new System.Drawing.Point(363, 16);
|
cancelButton.Location = new System.Drawing.Point(363, 16);
|
||||||
this.cancelButton.Name = "cancelButton";
|
cancelButton.Name = "cancelButton";
|
||||||
this.cancelButton.Size = new System.Drawing.Size(75, 23);
|
cancelButton.Size = new System.Drawing.Size(75, 23);
|
||||||
this.cancelButton.TabIndex = 1;
|
cancelButton.TabIndex = 2;
|
||||||
this.cancelButton.Text = "Cancel";
|
cancelButton.Text = "Cancel";
|
||||||
this.cancelButton.UseVisualStyleBackColor = true;
|
cancelButton.UseVisualStyleBackColor = true;
|
||||||
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
|
cancelButton.Click += cancelButton_Click;
|
||||||
//
|
//
|
||||||
// saveButton
|
// saveButton
|
||||||
//
|
//
|
||||||
this.saveButton.Location = new System.Drawing.Point(444, 16);
|
saveButton.Location = new System.Drawing.Point(444, 16);
|
||||||
this.saveButton.Name = "saveButton";
|
saveButton.Name = "saveButton";
|
||||||
this.saveButton.Size = new System.Drawing.Size(75, 23);
|
saveButton.Size = new System.Drawing.Size(75, 23);
|
||||||
this.saveButton.TabIndex = 0;
|
saveButton.TabIndex = 1;
|
||||||
this.saveButton.Text = "Save";
|
saveButton.Text = "Save";
|
||||||
this.saveButton.UseVisualStyleBackColor = true;
|
saveButton.UseVisualStyleBackColor = true;
|
||||||
this.saveButton.Click += new System.EventHandler(this.saveButton_Click);
|
saveButton.Click += saveButton_Click;
|
||||||
//
|
//
|
||||||
// label1
|
// timeoutLabel
|
||||||
//
|
//
|
||||||
this.label1.AutoSize = true;
|
timeoutLabel.AutoSize = true;
|
||||||
this.label1.Location = new System.Drawing.Point(13, 9);
|
timeoutLabel.Location = new System.Drawing.Point(13, 9);
|
||||||
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
timeoutLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
this.label1.Name = "label1";
|
timeoutLabel.Name = "timeoutLabel";
|
||||||
this.label1.Size = new System.Drawing.Size(488, 15);
|
timeoutLabel.Size = new System.Drawing.Size(401, 15);
|
||||||
this.label1.TabIndex = 11;
|
timeoutLabel.TabIndex = 3;
|
||||||
this.label1.Text = "Notification Toast Timeout (seconds, may be ignored by OS based on accessibility " +
|
timeoutLabel.Text = "Notification Toast Timeout (seconds, use -1 to require closing notification):";
|
||||||
"settings):";
|
|
||||||
//
|
//
|
||||||
// timeout
|
// timeout
|
||||||
//
|
//
|
||||||
this.timeout.Location = new System.Drawing.Point(13, 27);
|
timeout.Location = new System.Drawing.Point(13, 28);
|
||||||
this.timeout.Maximum = new decimal(new int[] {
|
timeout.Maximum = new decimal(new int[] { -1981284353, -1966660860, 0, 0 });
|
||||||
-1981284353,
|
timeout.Name = "timeout";
|
||||||
-1966660860,
|
timeout.Size = new System.Drawing.Size(506, 23);
|
||||||
0,
|
timeout.TabIndex = 4;
|
||||||
0});
|
//
|
||||||
this.timeout.Name = "timeout";
|
// reconnectAttempts
|
||||||
this.timeout.Size = new System.Drawing.Size(506, 23);
|
//
|
||||||
this.timeout.TabIndex = 12;
|
reconnectAttempts.Location = new System.Drawing.Point(12, 73);
|
||||||
|
reconnectAttempts.Maximum = new decimal(new int[] { -1981284353, -1966660860, 0, 0 });
|
||||||
|
reconnectAttempts.Name = "reconnectAttempts";
|
||||||
|
reconnectAttempts.Size = new System.Drawing.Size(506, 23);
|
||||||
|
reconnectAttempts.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// reconnectAttemptsLabel
|
||||||
|
//
|
||||||
|
reconnectAttemptsLabel.AutoSize = true;
|
||||||
|
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(287, 15);
|
||||||
|
reconnectAttemptsLabel.TabIndex = 5;
|
||||||
|
reconnectAttemptsLabel.Text = "Maximum reconnect retry attempts (requires restart):";
|
||||||
|
//
|
||||||
|
// reconnectAttemptDelay
|
||||||
|
//
|
||||||
|
reconnectAttemptDelay.Location = new System.Drawing.Point(12, 118);
|
||||||
|
reconnectAttemptDelay.Maximum = new decimal(new int[] { -1981284353, -1966660860, 0, 0 });
|
||||||
|
reconnectAttemptDelay.Name = "reconnectAttemptDelay";
|
||||||
|
reconnectAttemptDelay.Size = new System.Drawing.Size(506, 23);
|
||||||
|
reconnectAttemptDelay.TabIndex = 8;
|
||||||
|
//
|
||||||
|
// reconnectAttemptDelayLabel
|
||||||
|
//
|
||||||
|
reconnectAttemptDelayLabel.AutoSize = true;
|
||||||
|
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(275, 15);
|
||||||
|
reconnectAttemptDelayLabel.TabIndex = 7;
|
||||||
|
reconnectAttemptDelayLabel.Text = "Delay between attempts (seconds, requires restart):";
|
||||||
|
//
|
||||||
|
// nativeVersusCustomNotificationsGroupBox
|
||||||
|
//
|
||||||
|
nativeVersusCustomNotificationsGroupBox.Controls.Add(useCustomTrayNotifications);
|
||||||
|
nativeVersusCustomNotificationsGroupBox.Controls.Add(useNativeWindowsNotifications);
|
||||||
|
nativeVersusCustomNotificationsGroupBox.Location = new System.Drawing.Point(12, 147);
|
||||||
|
nativeVersusCustomNotificationsGroupBox.Name = "nativeVersusCustomNotificationsGroupBox";
|
||||||
|
nativeVersusCustomNotificationsGroupBox.Size = new System.Drawing.Size(506, 67);
|
||||||
|
nativeVersusCustomNotificationsGroupBox.TabIndex = 9;
|
||||||
|
nativeVersusCustomNotificationsGroupBox.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(customNotificationsPlayWindowsNotificationAudio);
|
||||||
|
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, 87);
|
||||||
|
groupCustomNotificationSettings.TabIndex = 10;
|
||||||
|
groupCustomNotificationSettings.TabStop = false;
|
||||||
|
//
|
||||||
|
// customNotificationsPlayWindowsNotificationAudio
|
||||||
|
//
|
||||||
|
customNotificationsPlayWindowsNotificationAudio.AutoSize = true;
|
||||||
|
customNotificationsPlayWindowsNotificationAudio.Location = new System.Drawing.Point(4, 59);
|
||||||
|
customNotificationsPlayWindowsNotificationAudio.Name = "customNotificationsPlayWindowsNotificationAudio";
|
||||||
|
customNotificationsPlayWindowsNotificationAudio.Size = new System.Drawing.Size(200, 19);
|
||||||
|
customNotificationsPlayWindowsNotificationAudio.TabIndex = 2;
|
||||||
|
customNotificationsPlayWindowsNotificationAudio.Text = "Play Windows notification sound";
|
||||||
|
customNotificationsPlayWindowsNotificationAudio.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// 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
|
// SettingsDialog
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.BackColor = System.Drawing.Color.White;
|
BackColor = System.Drawing.Color.White;
|
||||||
this.ClientSize = new System.Drawing.Size(531, 112);
|
ClientSize = new System.Drawing.Size(531, 387);
|
||||||
this.Controls.Add(this.timeout);
|
Controls.Add(label1);
|
||||||
this.Controls.Add(this.label1);
|
Controls.Add(groupCustomNotificationSettings);
|
||||||
this.Controls.Add(this.panel1);
|
Controls.Add(nativeVersusCustomNotificationsGroupBox);
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
Controls.Add(reconnectAttemptDelay);
|
||||||
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
Controls.Add(reconnectAttemptDelayLabel);
|
||||||
this.MaximizeBox = false;
|
Controls.Add(reconnectAttempts);
|
||||||
this.MinimizeBox = false;
|
Controls.Add(reconnectAttemptsLabel);
|
||||||
this.Name = "SettingsDialog";
|
Controls.Add(timeout);
|
||||||
this.ShowIcon = false;
|
Controls.Add(timeoutLabel);
|
||||||
this.ShowInTaskbar = false;
|
Controls.Add(buttonPanel);
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||||
this.Text = "Settings";
|
Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.panel1.ResumeLayout(false);
|
MaximizeBox = false;
|
||||||
((System.ComponentModel.ISupportInitialize)(this.timeout)).EndInit();
|
MinimizeBox = false;
|
||||||
this.ResumeLayout(false);
|
Name = "SettingsDialog";
|
||||||
this.PerformLayout();
|
ShowIcon = false;
|
||||||
|
ShowInTaskbar = false;
|
||||||
|
StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||||
|
Text = "Settings";
|
||||||
|
buttonPanel.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)timeout).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)reconnectAttempts).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)reconnectAttemptDelay).EndInit();
|
||||||
|
nativeVersusCustomNotificationsGroupBox.ResumeLayout(false);
|
||||||
|
nativeVersusCustomNotificationsGroupBox.PerformLayout();
|
||||||
|
groupCustomNotificationSettings.ResumeLayout(false);
|
||||||
|
groupCustomNotificationSettings.PerformLayout();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.Panel panel1;
|
private System.Windows.Forms.Panel buttonPanel;
|
||||||
private System.Windows.Forms.Label label1;
|
private System.Windows.Forms.Label timeoutLabel;
|
||||||
private System.Windows.Forms.NumericUpDown timeout;
|
private System.Windows.Forms.NumericUpDown timeout;
|
||||||
private System.Windows.Forms.Button cancelButton;
|
private System.Windows.Forms.Button cancelButton;
|
||||||
private System.Windows.Forms.Button saveButton;
|
private System.Windows.Forms.Button saveButton;
|
||||||
|
private System.Windows.Forms.NumericUpDown reconnectAttempts;
|
||||||
|
private System.Windows.Forms.Label reconnectAttemptsLabel;
|
||||||
|
private System.Windows.Forms.NumericUpDown reconnectAttemptDelay;
|
||||||
|
private System.Windows.Forms.Label reconnectAttemptDelayLabel;
|
||||||
|
private System.Windows.Forms.GroupBox nativeVersusCustomNotificationsGroupBox;
|
||||||
|
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;
|
||||||
|
private System.Windows.Forms.CheckBox customNotificationsPlayWindowsNotificationAudio;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,19 +1,78 @@
|
|||||||
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;
|
||||||
set => timeout.Value = value;
|
set => timeout.Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public decimal ReconnectAttempts
|
||||||
|
{
|
||||||
|
get => reconnectAttempts.Value;
|
||||||
|
set => reconnectAttempts.Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public decimal ReconnectAttemptDelay
|
||||||
|
{
|
||||||
|
get => reconnectAttemptDelay.Value;
|
||||||
|
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;
|
||||||
|
NotificationsMethod = (value) ? NotificationsType.NativeWindows : NotificationsType.CustomTray;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UseCustomTrayNotifications
|
||||||
|
{
|
||||||
|
get => useCustomTrayNotifications.Checked;
|
||||||
|
set {
|
||||||
|
useCustomTrayNotifications.Checked = value;
|
||||||
|
groupCustomNotificationSettings.Enabled = value;
|
||||||
|
NotificationsMethod = (value) ? NotificationsType.NativeWindows : NotificationsType.CustomTray;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CustomTrayNotificationsPlayDefaultWindowsSound
|
||||||
|
{
|
||||||
|
get => customNotificationsPlayWindowsNotificationAudio.Checked;
|
||||||
|
set => customNotificationsPlayWindowsNotificationAudio.Checked = value;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
public SettingsDialog()
|
public SettingsDialog()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
SetNotificationsUiElements();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveButton_Click(object sender, EventArgs e)
|
private void saveButton_Click(object sender, EventArgs e)
|
||||||
@@ -25,5 +84,19 @@ namespace ntfysh_client
|
|||||||
{
|
{
|
||||||
DialogResult = DialogResult.Cancel;
|
DialogResult = DialogResult.Cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetNotificationsUiElements()
|
||||||
|
{
|
||||||
|
groupCustomNotificationSettings.Enabled = useCustomTrayNotifications.Checked;
|
||||||
|
timeoutLabel.Text = useCustomTrayNotifications.Checked ? _customNotificationsTimeout : _windowsNotificationsTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 0 to require closing notification):";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,64 @@
|
|||||||
<root>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
@@ -2,6 +2,19 @@
|
|||||||
{
|
{
|
||||||
public class SettingsModel
|
public class SettingsModel
|
||||||
{
|
{
|
||||||
|
public enum NotificationsType
|
||||||
|
{
|
||||||
|
NativeWindows,
|
||||||
|
CustomTray
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint Revision { get; set; }
|
||||||
public decimal Timeout { get; set; }
|
public decimal Timeout { get; set; }
|
||||||
|
public decimal ReconnectAttempts { get; set; }
|
||||||
|
public decimal ReconnectAttemptDelay { get; set; }
|
||||||
|
public NotificationsType NotificationsMethod { get; set; }
|
||||||
|
public bool CustomTrayNotificationsShowTimeoutBar { get; set; }
|
||||||
|
public bool CustomTrayNotificationsShowInDarkMode { get; set; }
|
||||||
|
public bool CustomTrayNotificationsPlayDefaultWindowsSound { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
12
ntfysh_client/Themes/BaseTheme.cs
Normal file
12
ntfysh_client/Themes/BaseTheme.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace ntfysh_client.Themes
|
||||||
|
{
|
||||||
|
internal abstract class BaseTheme
|
||||||
|
{
|
||||||
|
public abstract Color BackgroundColor {get; }
|
||||||
|
public abstract Color ControlBackGroundColor {get; }
|
||||||
|
public abstract Color ControlMouseOverBackgroundColor { get; }
|
||||||
|
public abstract Color ForegroundColor { get; }
|
||||||
|
}
|
||||||
|
}
|
12
ntfysh_client/Themes/DarkModeTheme.cs
Normal file
12
ntfysh_client/Themes/DarkModeTheme.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace ntfysh_client.Themes
|
||||||
|
{
|
||||||
|
internal class DarkModeTheme: BaseTheme
|
||||||
|
{
|
||||||
|
public override Color BackgroundColor { get => SystemColors.ControlDark; }
|
||||||
|
public override Color ControlBackGroundColor { get => Color.Black; }
|
||||||
|
public override Color ControlMouseOverBackgroundColor { get => Color.Silver; }
|
||||||
|
public override Color ForegroundColor { get => SystemColors.WindowText; }
|
||||||
|
}
|
||||||
|
}
|
12
ntfysh_client/Themes/DefaultTheme.cs
Normal file
12
ntfysh_client/Themes/DefaultTheme.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace ntfysh_client.Themes
|
||||||
|
{
|
||||||
|
internal class DefaultTheme: BaseTheme
|
||||||
|
{
|
||||||
|
public override Color BackgroundColor { get => Color.White; }
|
||||||
|
public override Color ControlBackGroundColor { get => SystemColors.ControlDark; }
|
||||||
|
public override Color ControlMouseOverBackgroundColor { get => Color.CadetBlue; }
|
||||||
|
public override Color ForegroundColor { get => SystemColors.WindowText; }
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user