diff --git a/ntfysh_client/MainForm.cs b/ntfysh_client/MainForm.cs index 465c960..332dfe6 100644 --- a/ntfysh_client/MainForm.cs +++ b/ntfysh_client/MainForm.cs @@ -75,7 +75,7 @@ namespace ntfysh_client //notifyIcon.ShowBalloonTip((int)TimeSpan.FromSeconds((double)Program.Settings.Timeout).TotalMilliseconds, finalTitle, e.Message, priorityIcon); //this.notificationDialog.IsVisible = true; - this.notificationDialog.ShowNotification(finalTitle, e.Message); + this.notificationDialog.ShowNotification(finalTitle, e.Message, (int)TimeSpan.FromSeconds((double)Program.Settings.Timeout).TotalMilliseconds); } private void OnConnectionMultiAttemptFailure(NotificationListener sender, SubscribedTopic topic) diff --git a/ntfysh_client/NotificationDialog.cs b/ntfysh_client/NotificationDialog.cs index 81767e2..b790a4d 100644 --- a/ntfysh_client/NotificationDialog.cs +++ b/ntfysh_client/NotificationDialog.cs @@ -20,6 +20,8 @@ namespace ntfysh_client private const int ScreenMargin = 20; + private System.Timers.Timer? timer = null; + private void SetWindowPosition() { int workingtop = Screen.PrimaryScreen.WorkingArea.Height - this.Height; @@ -31,6 +33,7 @@ namespace ntfysh_client protected override void SetVisibleCore(bool value) { + //base.SetVisibleCore(false); this.SetWindowPosition(); if (value) @@ -41,8 +44,43 @@ namespace ntfysh_client base.SetVisibleCore(value); } - public void ShowNotification(string title, string message) + private void ui_hide_window(object? sender, EventArgs e) { + AnimateWindow(this.Handle, 250, 0x00040000 | 0x00000004 | 0x00010000); + this.IsVisible = false; + } + + private void handleTimeout(object? sender, EventArgs e) + { + if (this.timer != null) + { + this.timer.Stop(); + this.timer.Dispose(); + this.timer = null; + } + if (this.InvokeRequired) + { + this.Invoke(new Action(() => this.ui_hide_window(sender, e))); + } + else + { + this.ui_hide_window(sender, e); + } + } + + public void ShowNotification(string title, string message, int timeout_ms=-1) + { + if (this.timer != null) + { + this.timer.Stop(); + this.timer.Dispose(); + } + if (timeout_ms > 0) + { + this.timer = new System.Timers.Timer(timeout_ms); + timer.Elapsed += handleTimeout; + this.timer.Start(); + } this.tbTitle.Text = title; this.tbMessage.Text = message; this.Show(); @@ -57,13 +95,13 @@ namespace ntfysh_client protected override void OnShown(EventArgs e) { - base.OnShown(e); } public NotificationDialog() { this.IsVisible = false; + this.TopMost = true; InitializeComponent(); InitializeWindowHidden(); } @@ -78,6 +116,7 @@ namespace ntfysh_client private void btnClose_Click(object sender, EventArgs e) { + // immediate this.IsVisible = false; } } diff --git a/ntfysh_client/SettingsDialog.Designer.cs b/ntfysh_client/SettingsDialog.Designer.cs index 8f240fe..5d07b2a 100644 --- a/ntfysh_client/SettingsDialog.Designer.cs +++ b/ntfysh_client/SettingsDialog.Designer.cs @@ -84,7 +84,7 @@ namespace ntfysh_client timeoutLabel.Name = "timeoutLabel"; timeoutLabel.Size = new System.Drawing.Size(488, 15); timeoutLabel.TabIndex = 3; - timeoutLabel.Text = "Notification Toast Timeout (seconds, may be ignored by OS based on accessibility settings):"; + timeoutLabel.Text = "Notification Toast Timeout (seconds, use -1 to require closing notification):"; // // timeout //