From c4291e6f44a1a48047c33a6801e75ed798862697 Mon Sep 17 00:00:00 2001 From: Alexander Horner <33007665+alexhorner@users.noreply.github.com> Date: Thu, 8 Dec 2022 19:04:43 +0000 Subject: [PATCH 1/9] Default to preventing multiple instances Allow multiple instances if overridden with command line parameter Allow starting minimised to tray with command line parameter --- ntfysh_client/MainForm.cs | 30 +++++++++++++++++++++++++++--- ntfysh_client/MainForm.resx | 10 +++++----- ntfysh_client/Program.cs | 31 ++++++++++++++++++++++++++----- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/ntfysh_client/MainForm.cs b/ntfysh_client/MainForm.cs index bd1bf9f..7aeb861 100644 --- a/ntfysh_client/MainForm.cs +++ b/ntfysh_client/MainForm.cs @@ -13,17 +13,43 @@ namespace ntfysh_client public partial class MainForm : Form { private readonly NotificationListener _notificationListener; + private bool _startInTray; private bool _trueExit; - public MainForm(NotificationListener notificationListener) + public MainForm(NotificationListener notificationListener, bool startInTray = false) { _notificationListener = notificationListener; + _startInTray = startInTray; _notificationListener.OnNotificationReceive += OnNotificationReceive; _notificationListener.OnConnectionMultiAttemptFailure += OnConnectionMultiAttemptFailure; _notificationListener.OnConnectionCredentialsFailure += OnConnectionCredentialsFailure; InitializeComponent(); } + + private void MainForm_Load(object sender, EventArgs e) => LoadTopics(); + + protected override void SetVisibleCore(bool value) + { + if (_startInTray) + { + _startInTray = false; + + /* + * TODO This little workaround prevents the window from appearing with a flash, but the taskbar icon appears for a moment. + * + * TODO This is because we must call SetVisibleCore(true) for the initial load events in the MainForm to fire, which is what triggers the listener + */ + Opacity = 0; + base.SetVisibleCore(true); + base.SetVisibleCore(false); + Opacity = 1; + + return; + } + + base.SetVisibleCore(value); + } private void OnNotificationReceive(object sender, NotificationReceiveEventArgs e) { @@ -42,8 +68,6 @@ namespace ntfysh_client MessageBox.Show($"Connecting to topic ID '{topic.TopicId}' on server '{topic.ServerUrl}' failed because {reason}.\n\nThis topic ID will be ignored and you will not receive notifications for it until you correct the credentials.", "Connection Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } - private void MainForm_Load(object sender, EventArgs e) => LoadTopics(); - private void subscribeNewTopic_Click(object sender, EventArgs e) { using SubscribeDialog dialog = new SubscribeDialog(notificationTopics); diff --git a/ntfysh_client/MainForm.resx b/ntfysh_client/MainForm.resx index dbf516e..85f0136 100644 --- a/ntfysh_client/MainForm.resx +++ b/ntfysh_client/MainForm.resx @@ -67,7 +67,7 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 - JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA6+AAAOvgHqQrHAAAAAiklE + JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA69AAAOvQFH+5CtAAAAiklE QVQ4T8WPQQqAIBBFvUOrXIhu3dcZOkqtu5R1ia4SdRDrxyyGGKmBIOGBDL6nmk9WCGE9yUpW0q9Ads7V GuCQ/kHAe79joAEO6dcLFmttpQEO6c+Bvpm2oZ0zwB4zVQBiF8cIsMdMDPCb+G2vA/wgP/z6C6WAhBgo fUFCDGi4BxIGShLpvy5jDoPes/0oNG3VAAAAAElFTkSuQmCC @@ -76,7 +76,7 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 - JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA6+AAAOvgHqQrHAAAAAgUlE + JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA69AAAOvQFH+5CtAAAAgUlE QVQ4T2OgGjjOLq4AZeIFWNWBBI9yib06zC3uABXCCkDyIHVYDTnMI2pzhEvs5VFucSeoEAo4wiNii08e DHAZQshwFICumCTNMADyK1gTl2gJiCYUNlgBSDPQ1v8gGipEPKDIBRSFAa6oIsoQQvGM1xCqpESsglgA seroBRgYAOoOWBJbfVcRAAAAAElFTkSuQmCC @@ -267,7 +267,7 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 - JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA6+AAAOvgHqQrHAAAAAgUlE + JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA69AAAOvQFH+5CtAAAAgUlE QVQ4T2OgGjjOLq4AZeIFWNWBBI9yib06zC3uABXCCkDyIHVYDTnMI2pzhEvs5VFucSeoEAo4wiNii08e DHAZQshwFICumCTNMADyK1gTl2gJiCYUNlgBSDPQ1v8gGipEPKDIBRSFAa6oIsoQQvGM1xCqpESsglgA seroBRgYAOoOWBJbfVcRAAAAAElFTkSuQmCC @@ -276,7 +276,7 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 - JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA6+AAAOvgHqQrHAAAABDElE + JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA69AAAOvQFH+5CtAAABDElE QVQ4T91RO3bCQAzUy3uhChdJnTVlCj5FcMsZsF1jmy4XycPrzl6fBLgEXMFp4srRiF0wcaBP5j0VI2m0 4zH9EwSq8gPP7ELPNFxtpxrbn9vVPkSsykOkqvHi2QxsWwAevhQTzG8eCb1yD7Glv2I5MlM+sLX0GqEq 6+jVPFl6QZz7lOgdJVnzuMq/sEepbsGln2YnR3AAm0IcIE71geJsTO9mcOWAOa3zicxxxGWApXMGabaH @@ -287,7 +287,7 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 - JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA6+AAAOvgHqQrHAAAAAwUlE + JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA69AAAOvQFH+5CtAAAAwUlE QVQ4T2OgClBUVHwAxP9JxA+g2sEG/JeTk5MkBYP0QLVTwQAFBYXHIAFSMEgPVDvYBfulpKSEScEgPVDt dDIA6OTNQHX/YXysBjAxMcUxMjKuBrGB9DIgPxqmARhwOUBD3sD4WA0QERGRBHLvCwoKygLpm6KiohIw DVBNz5HY2L0AtHkOEE8F4okgvoyMjDSSJsIGsLOzuwKFfnBycppJS0vLAJ39BUQTbQA6RnYBMkY3YAVI diff --git a/ntfysh_client/Program.cs b/ntfysh_client/Program.cs index 5841c89..a64b094 100644 --- a/ntfysh_client/Program.cs +++ b/ntfysh_client/Program.cs @@ -1,25 +1,46 @@ using System; -using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Linq; -using System.Threading.Tasks; +using System.Reflection; using System.Windows.Forms; namespace ntfysh_client { static class Program { - private static readonly NotificationListener NotificationListener = new NotificationListener(); + private static readonly NotificationListener NotificationListener = new(); /// /// The main entry point for the application. /// [STAThread] - static void Main() + private static void Main(string[] args) { + args = args.Select(a => a.ToLower()).ToArray(); + + if (args.Contains("-h") || args.Contains("--help")) + { + MessageBox.Show("Help:\n -h\n --help\n\nStart in tray:\n -t\n --start-in-tray\n\nAllow multiple instances:\n -m\n --allow-multiple-instances", "Help Menu", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; + } + + bool startInTray = args.Contains("-t") || args.Contains("--start-in-tray"); + bool allowMultipleInstances = args.Contains("-m") || args.Contains("--allow-multiple-instances"); + + if (Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly()!.Location)).Length > 1) + { + if (!allowMultipleInstances) + { + MessageBox.Show("Another instance is already running.\n\nUse -m or --allow-multiple-instances if you wish to start a second duplicate instance.\n\nThis instance will now close.", "Multiple Instances", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + } + Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm(NotificationListener)); + Application.Run(new MainForm(NotificationListener, startInTray)); } } } -- 2.49.1 From b64403543332bab570ceb0a3be965806d5f3fad9 Mon Sep 17 00:00:00 2001 From: Alexander Horner <33007665+alexhorner@users.noreply.github.com> Date: Thu, 8 Dec 2022 19:30:31 +0000 Subject: [PATCH 2/9] Add license to About box and fancy it up a little --- ntfysh_client/AboutBox.Designer.cs | 101 +++++++++++++++++++++++------ ntfysh_client/AboutBox.cs | 7 -- ntfysh_client/AboutBox.resx | 82 ++++++----------------- 3 files changed, 102 insertions(+), 88 deletions(-) diff --git a/ntfysh_client/AboutBox.Designer.cs b/ntfysh_client/AboutBox.Designer.cs index 368151c..97a9c3d 100644 --- a/ntfysh_client/AboutBox.Designer.cs +++ b/ntfysh_client/AboutBox.Designer.cs @@ -29,53 +29,107 @@ namespace ntfysh_client /// private void InitializeComponent() { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutBox)); this.button1 = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.aboutPage = new System.Windows.Forms.TabPage(); + this.richTextBox2 = new System.Windows.Forms.RichTextBox(); + this.licensePage = new System.Windows.Forms.TabPage(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.tabControl1.SuspendLayout(); + this.aboutPage.SuspendLayout(); + this.licensePage.SuspendLayout(); this.SuspendLayout(); // // button1 // - this.button1.Location = new System.Drawing.Point(299, 173); + this.button1.Location = new System.Drawing.Point(522, 243); + this.button1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.Size = new System.Drawing.Size(88, 27); this.button1.TabIndex = 0; this.button1.Text = "Close"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 49); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(358, 65); - this.label1.TabIndex = 1; - this.label1.Text = "Copyright © 2022 Lucas Bortoli\r\nAll rights reserved\r\n\r\nThe icons included in this" + - " application are property of Microsoft Corporation.\r\n(Visual Studio Image Librar" + - "y)"; // // label2 // this.label2.AutoSize = true; - this.label2.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label2.Location = new System.Drawing.Point(10, 9); + this.label2.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label2.Location = new System.Drawing.Point(12, 9); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(166, 30); this.label2.TabIndex = 2; this.label2.Text = "ntfy.sh Windows"; // + // tabControl1 + // + this.tabControl1.Controls.Add(this.aboutPage); + this.tabControl1.Controls.Add(this.licensePage); + this.tabControl1.Location = new System.Drawing.Point(12, 43); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(598, 194); + this.tabControl1.TabIndex = 3; + // + // aboutPage + // + this.aboutPage.Controls.Add(this.richTextBox2); + this.aboutPage.Location = new System.Drawing.Point(4, 24); + this.aboutPage.Name = "aboutPage"; + this.aboutPage.Padding = new System.Windows.Forms.Padding(3); + this.aboutPage.Size = new System.Drawing.Size(590, 166); + this.aboutPage.TabIndex = 0; + this.aboutPage.Text = "About"; + this.aboutPage.UseVisualStyleBackColor = true; + // + // richTextBox2 + // + this.richTextBox2.BackColor = System.Drawing.SystemColors.Window; + this.richTextBox2.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.richTextBox2.Location = new System.Drawing.Point(6, 6); + this.richTextBox2.Name = "richTextBox2"; + this.richTextBox2.ReadOnly = true; + this.richTextBox2.Size = new System.Drawing.Size(578, 154); + this.richTextBox2.TabIndex = 0; + this.richTextBox2.Text = resources.GetString("richTextBox2.Text"); + // + // licensePage + // + this.licensePage.Controls.Add(this.richTextBox1); + this.licensePage.Location = new System.Drawing.Point(4, 24); + this.licensePage.Name = "licensePage"; + this.licensePage.Padding = new System.Windows.Forms.Padding(3); + this.licensePage.Size = new System.Drawing.Size(590, 166); + this.licensePage.TabIndex = 1; + this.licensePage.Text = "MIT License\n\n"; + this.licensePage.UseVisualStyleBackColor = true; + // + // richTextBox1 + // + this.richTextBox1.BackColor = System.Drawing.SystemColors.Window; + this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.richTextBox1.Location = new System.Drawing.Point(6, 6); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.ReadOnly = true; + this.richTextBox1.Size = new System.Drawing.Size(578, 154); + this.richTextBox1.TabIndex = 0; + this.richTextBox1.Text = resources.GetString("richTextBox1.Text"); + // // AboutBox // this.AcceptButton = this.button1; - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.White; - this.ClientSize = new System.Drawing.Size(386, 208); + this.ClientSize = new System.Drawing.Size(622, 275); + this.Controls.Add(this.tabControl1); this.Controls.Add(this.label2); - this.Controls.Add(this.label1); this.Controls.Add(this.button1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "AboutBox"; @@ -83,6 +137,9 @@ namespace ntfysh_client this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "About"; + this.tabControl1.ResumeLayout(false); + this.aboutPage.ResumeLayout(false); + this.licensePage.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -91,7 +148,11 @@ namespace ntfysh_client #endregion private System.Windows.Forms.Button button1; - private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage aboutPage; + private System.Windows.Forms.TabPage licensePage; + private System.Windows.Forms.RichTextBox richTextBox1; + private System.Windows.Forms.RichTextBox richTextBox2; } } \ No newline at end of file diff --git a/ntfysh_client/AboutBox.cs b/ntfysh_client/AboutBox.cs index 6239921..5c9fb47 100644 --- a/ntfysh_client/AboutBox.cs +++ b/ntfysh_client/AboutBox.cs @@ -1,11 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace ntfysh_client diff --git a/ntfysh_client/AboutBox.resx b/ntfysh_client/AboutBox.resx index 1af7de1..76a0c8a 100644 --- a/ntfysh_client/AboutBox.resx +++ b/ntfysh_client/AboutBox.resx @@ -1,64 +1,4 @@ - - - + @@ -117,4 +57,24 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ntfy.sh Windows by Lucas Bortoli and Contributors + +ntfy.sh Windows is a small lightweight push notification client for notifications sent via https://ntfy.sh compatible servers. + +It is capable of receiving notifications from multiple ntfy.sh servers simultaneously via Websocket or HTTP and supports both unauthenticated and authenticated topics. + +Get the latest release and keep track of updates via GitHub at https://github.com/lucas-bortoli/ntfysh-windows + + + Copyright © 2022 Lucas Bortoli + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +The icons included in this application are property of Microsoft Corporation (Visual Studio Image Library) + \ No newline at end of file -- 2.49.1 From d90ddc3be48f6294e7095a79e42f1361b3895094 Mon Sep 17 00:00:00 2001 From: Alexander Horner <33007665+alexhorner@users.noreply.github.com> Date: Thu, 8 Dec 2022 19:33:08 +0000 Subject: [PATCH 3/9] Solution cleanup --- ntfysh_client/App.config | 6 ------ ntfysh_client/MainForm.cs | 1 + ntfysh_client/{ => Notifications}/NotificationListener.cs | 6 +++--- .../{ => Notifications}/NotificationReceiveEventArgs.cs | 2 +- ntfysh_client/{ => Notifications}/NtfyEvent.cs | 2 +- ntfysh_client/{ => Notifications}/SubscribedTopic.cs | 2 +- ntfysh_client/Program.cs | 1 + ntfysh_client/packages.config | 4 ---- 8 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 ntfysh_client/App.config rename ntfysh_client/{ => Notifications}/NotificationListener.cs (99%) rename ntfysh_client/{ => Notifications}/NotificationReceiveEventArgs.cs (89%) rename ntfysh_client/{ => Notifications}/NtfyEvent.cs (93%) rename ntfysh_client/{ => Notifications}/SubscribedTopic.cs (96%) delete mode 100644 ntfysh_client/packages.config diff --git a/ntfysh_client/App.config b/ntfysh_client/App.config deleted file mode 100644 index 56efbc7..0000000 --- a/ntfysh_client/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/ntfysh_client/MainForm.cs b/ntfysh_client/MainForm.cs index 7aeb861..895ffee 100644 --- a/ntfysh_client/MainForm.cs +++ b/ntfysh_client/MainForm.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Reflection; using System.Windows.Forms; using Newtonsoft.Json; +using ntfysh_client.Notifications; namespace ntfysh_client { diff --git a/ntfysh_client/NotificationListener.cs b/ntfysh_client/Notifications/NotificationListener.cs similarity index 99% rename from ntfysh_client/NotificationListener.cs rename to ntfysh_client/Notifications/NotificationListener.cs index 5e4d58c..ef39467 100644 --- a/ntfysh_client/NotificationListener.cs +++ b/ntfysh_client/Notifications/NotificationListener.cs @@ -1,5 +1,4 @@ -using Newtonsoft.Json; -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -12,8 +11,9 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using System.Web; +using Newtonsoft.Json; -namespace ntfysh_client +namespace ntfysh_client.Notifications { public class NotificationListener { diff --git a/ntfysh_client/NotificationReceiveEventArgs.cs b/ntfysh_client/Notifications/NotificationReceiveEventArgs.cs similarity index 89% rename from ntfysh_client/NotificationReceiveEventArgs.cs rename to ntfysh_client/Notifications/NotificationReceiveEventArgs.cs index 87d932e..6590e67 100644 --- a/ntfysh_client/NotificationReceiveEventArgs.cs +++ b/ntfysh_client/Notifications/NotificationReceiveEventArgs.cs @@ -1,6 +1,6 @@ using System; -namespace ntfysh_client +namespace ntfysh_client.Notifications { public class NotificationReceiveEventArgs : EventArgs { diff --git a/ntfysh_client/NtfyEvent.cs b/ntfysh_client/Notifications/NtfyEvent.cs similarity index 93% rename from ntfysh_client/NtfyEvent.cs rename to ntfysh_client/Notifications/NtfyEvent.cs index ef4ee82..6cada12 100644 --- a/ntfysh_client/NtfyEvent.cs +++ b/ntfysh_client/Notifications/NtfyEvent.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace ntfysh_client +namespace ntfysh_client.Notifications { public class NtfyEvent { diff --git a/ntfysh_client/SubscribedTopic.cs b/ntfysh_client/Notifications/SubscribedTopic.cs similarity index 96% rename from ntfysh_client/SubscribedTopic.cs rename to ntfysh_client/Notifications/SubscribedTopic.cs index b0593e1..9189c4f 100644 --- a/ntfysh_client/SubscribedTopic.cs +++ b/ntfysh_client/Notifications/SubscribedTopic.cs @@ -3,7 +3,7 @@ using System.Threading; using System.Threading.Tasks; using Newtonsoft.Json; -namespace ntfysh_client +namespace ntfysh_client.Notifications { public class SubscribedTopic { diff --git a/ntfysh_client/Program.cs b/ntfysh_client/Program.cs index a64b094..5942747 100644 --- a/ntfysh_client/Program.cs +++ b/ntfysh_client/Program.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Reflection; using System.Windows.Forms; +using ntfysh_client.Notifications; namespace ntfysh_client { diff --git a/ntfysh_client/packages.config b/ntfysh_client/packages.config deleted file mode 100644 index 5eaa239..0000000 --- a/ntfysh_client/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file -- 2.49.1 From 7f73bd2cd1e82af7404c27fddd77d09fdb5d0cbc Mon Sep 17 00:00:00 2001 From: Alexander Horner <33007665+alexhorner@users.noreply.github.com> Date: Thu, 8 Dec 2022 19:54:14 +0000 Subject: [PATCH 4/9] Add support for priority Set default title to topic unique, as displayed in subscriptions list, if not provided Increase toast timeout to 5 seconds --- ntfysh_client/MainForm.cs | 14 +++++++++++++- .../Notifications/NotificationListener.cs | 8 ++++---- .../Notifications/NotificationPriority.cs | 11 +++++++++++ .../Notifications/NotificationReceiveEventArgs.cs | 6 +++++- ntfysh_client/Notifications/NtfyEvent.cs | 5 ++++- 5 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 ntfysh_client/Notifications/NotificationPriority.cs diff --git a/ntfysh_client/MainForm.cs b/ntfysh_client/MainForm.cs index 895ffee..ce77083 100644 --- a/ntfysh_client/MainForm.cs +++ b/ntfysh_client/MainForm.cs @@ -54,7 +54,19 @@ namespace ntfysh_client private void OnNotificationReceive(object sender, NotificationReceiveEventArgs e) { - notifyIcon.ShowBalloonTip(3000, e.Title, e.Message, ToolTipIcon.Info); + ToolTipIcon priorityIcon = e.Priority switch + { + NotificationPriority.Max => ToolTipIcon.Error, + NotificationPriority.High => ToolTipIcon.Warning, + NotificationPriority.Default => ToolTipIcon.Info, + NotificationPriority.Low => ToolTipIcon.Info, + NotificationPriority.Min => ToolTipIcon.None, + _ => throw new ArgumentOutOfRangeException("Unknown priority received") + }; + + string finalTitle = string.IsNullOrWhiteSpace(e.Title) ? $"{e.Sender.TopicId}@{e.Sender.ServerUrl}" : e.Title; + + notifyIcon.ShowBalloonTip(5000, finalTitle, e.Message, priorityIcon); } private void OnConnectionMultiAttemptFailure(NotificationListener sender, SubscribedTopic topic) diff --git a/ntfysh_client/Notifications/NotificationListener.cs b/ntfysh_client/Notifications/NotificationListener.cs index ef39467..f0acaa6 100644 --- a/ntfysh_client/Notifications/NotificationListener.cs +++ b/ntfysh_client/Notifications/NotificationListener.cs @@ -85,7 +85,7 @@ namespace ntfysh_client.Notifications lines.RemoveAt(partialLineIndex); //Process the full lines - foreach (string line in lines) ProcessMessage(line); + foreach (string line in lines) ProcessMessage(topic, line); //Write back the partial line mainBuffer.Clear(); @@ -189,7 +189,7 @@ namespace ntfysh_client.Notifications lines.RemoveAt(partialLineIndex); //Process the full lines - foreach (string line in lines) ProcessMessage(line); + foreach (string line in lines) ProcessMessage(topic, line); //Write back the partial line mainBuffer.Clear(); @@ -244,7 +244,7 @@ namespace ntfysh_client.Notifications } } - private void ProcessMessage(string message) + private void ProcessMessage(SubscribedTopic topic, string message) { #if DEBUG Debug.WriteLine(message); @@ -257,7 +257,7 @@ namespace ntfysh_client.Notifications if (evt.Event == "message") { - OnNotificationReceive?.Invoke(this, new NotificationReceiveEventArgs(evt.Title, evt.Message)); + OnNotificationReceive?.Invoke(this, new NotificationReceiveEventArgs(topic, evt.Title ?? "", evt.Message, evt.Priority ?? NotificationPriority.Default)); } } diff --git a/ntfysh_client/Notifications/NotificationPriority.cs b/ntfysh_client/Notifications/NotificationPriority.cs new file mode 100644 index 0000000..cf82d9c --- /dev/null +++ b/ntfysh_client/Notifications/NotificationPriority.cs @@ -0,0 +1,11 @@ +namespace ntfysh_client.Notifications +{ + public enum NotificationPriority + { + Min = 1, + Low = 2, + Default = 3, + High = 4, + Max = 5 + } +} \ No newline at end of file diff --git a/ntfysh_client/Notifications/NotificationReceiveEventArgs.cs b/ntfysh_client/Notifications/NotificationReceiveEventArgs.cs index 6590e67..d87363d 100644 --- a/ntfysh_client/Notifications/NotificationReceiveEventArgs.cs +++ b/ntfysh_client/Notifications/NotificationReceiveEventArgs.cs @@ -4,13 +4,17 @@ namespace ntfysh_client.Notifications { public class NotificationReceiveEventArgs : EventArgs { + public SubscribedTopic Sender { get; } public string Title { get; } public string Message { get; } + public NotificationPriority Priority { get; set; } - public NotificationReceiveEventArgs(string title, string message) + public NotificationReceiveEventArgs(SubscribedTopic sender, string title, string message, NotificationPriority priority) { + Sender = sender; Title = title; Message = message; + Priority = priority; } } } \ No newline at end of file diff --git a/ntfysh_client/Notifications/NtfyEvent.cs b/ntfysh_client/Notifications/NtfyEvent.cs index 6cada12..de54962 100644 --- a/ntfysh_client/Notifications/NtfyEvent.cs +++ b/ntfysh_client/Notifications/NtfyEvent.cs @@ -20,6 +20,9 @@ namespace ntfysh_client.Notifications public string Message { get; set; } = null!; [JsonProperty("title")] - public string Title { get; set; } = null!; + public string? Title { get; set; } + + [JsonProperty("priority")] + public NotificationPriority? Priority { get; set; } } } \ No newline at end of file -- 2.49.1 From 617f1e658ac021058b2037275e0b2ef44282ec61 Mon Sep 17 00:00:00 2001 From: Alexander Horner <33007665+alexhorner@users.noreply.github.com> Date: Thu, 8 Dec 2022 20:12:29 +0000 Subject: [PATCH 5/9] Add publish config and adjust app publish name --- .run/Publish ntfysh_client to folder.run.xml | 6 ++++++ ntfysh_client/ntfysh_client.csproj | 1 + 2 files changed, 7 insertions(+) create mode 100644 .run/Publish ntfysh_client to folder.run.xml diff --git a/.run/Publish ntfysh_client to folder.run.xml b/.run/Publish ntfysh_client to folder.run.xml new file mode 100644 index 0000000..bc84932 --- /dev/null +++ b/.run/Publish ntfysh_client to folder.run.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ntfysh_client/ntfysh_client.csproj b/ntfysh_client/ntfysh_client.csproj index 5b9a3a3..e909f92 100644 --- a/ntfysh_client/ntfysh_client.csproj +++ b/ntfysh_client/ntfysh_client.csproj @@ -8,6 +8,7 @@ enable NotificationHub.ico ntfysh_client.Program + ntfy.sh -- 2.49.1 From 79d04b4a58da121ad2da5822469cd107ca748e43 Mon Sep 17 00:00:00 2001 From: Alexander Horner <33007665+alexhorner@users.noreply.github.com> Date: Thu, 8 Dec 2022 20:21:51 +0000 Subject: [PATCH 6/9] New screenshots and text --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ab52659..fda19e2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,16 @@ # ntfy.sh Windows -![Application screenshot](https://i.imgur.com/C9BFTCJ.png) +ntfy.sh Windows is a small lightweight push notification client for notifications sent via https://ntfy.sh compatible servers. -![Notification example screenshot](https://i.imgur.com/ZmfJ8Wm.png) +It is capable of receiving notifications from multiple ntfy.sh servers simultaneously via Websocket or HTTP and supports both unauthenticated and authenticated topics. -A [ntfy.sh](https://ntfy.sh/) client for Windows. \ No newline at end of file +## Screenshots +### Main Application +![Application screenshot](https://user-images.githubusercontent.com/33007665/206556170-962fd699-988c-477e-941e-5179b9f4a67c.png) +![Topic Subscribe screenshot](https://user-images.githubusercontent.com/33007665/206556398-5ee95cee-6fc8-4234-b46e-6380cdfc94dd.png) + +### Example Notifications +![Default toast](https://user-images.githubusercontent.com/33007665/206558550-9903b9e3-7f6b-418d-8a46-1311708b5b3e.png) +![High priority toast](https://user-images.githubusercontent.com/33007665/206558687-92a6c6ae-2583-400b-952b-3cdb7fe38c07.png) +![Medium priority toast](https://user-images.githubusercontent.com/33007665/206559209-2f052fc2-4e8a-4ccb-b6cd-4a8066f9c8d7.png) +![image](https://user-images.githubusercontent.com/33007665/206559650-b6b961cc-c764-4d0a-bc49-84e51b23c86f.png) -- 2.49.1 From 1a73981d200cfe48f585909ce1f501f1cd401cae Mon Sep 17 00:00:00 2001 From: Alexander Horner <33007665+alexhorner@users.noreply.github.com> Date: Thu, 8 Dec 2022 20:28:26 +0000 Subject: [PATCH 7/9] Add command line parameters --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index fda19e2..abb9e32 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,13 @@ It is capable of receiving notifications from multiple ntfy.sh servers simultane ![High priority toast](https://user-images.githubusercontent.com/33007665/206558687-92a6c6ae-2583-400b-952b-3cdb7fe38c07.png) ![Medium priority toast](https://user-images.githubusercontent.com/33007665/206559209-2f052fc2-4e8a-4ccb-b6cd-4a8066f9c8d7.png) ![image](https://user-images.githubusercontent.com/33007665/206559650-b6b961cc-c764-4d0a-bc49-84e51b23c86f.png) + +## Command Line Parameters +### -h and --help +Show the help menu + +### -t and --start-in-tray +Start ntfy.sh Windows in the tray, useful for starting with Windows when logging in + +### -m and --allow-multiple-instances +Bypass the instance check to allow multiple instances of ntfy.sh Windows to start simultaneously -- 2.49.1 From 67b6e5b607f79be97c03087951cde1ecbbad483e Mon Sep 17 00:00:00 2001 From: Alexander Horner <33007665+alexhorner@users.noreply.github.com> Date: Mon, 12 Dec 2022 21:32:46 +0000 Subject: [PATCH 8/9] Add new timeout option and supporting settings infrastructure --- ntfysh_client/MainForm.Designer.cs | 15 ++- ntfysh_client/MainForm.cs | 96 +++++++++++++++-- ntfysh_client/MainForm.resx | 22 +++- ntfysh_client/Program.cs | 3 +- ntfysh_client/SettingsDialog.Designer.cs | 129 +++++++++++++++++++++++ ntfysh_client/SettingsDialog.cs | 29 +++++ ntfysh_client/SettingsDialog.resx | 60 +++++++++++ ntfysh_client/SettingsModel.cs | 7 ++ 8 files changed, 345 insertions(+), 16 deletions(-) create mode 100644 ntfysh_client/SettingsDialog.Designer.cs create mode 100644 ntfysh_client/SettingsDialog.cs create mode 100644 ntfysh_client/SettingsDialog.resx create mode 100644 ntfysh_client/SettingsModel.cs diff --git a/ntfysh_client/MainForm.Designer.cs b/ntfysh_client/MainForm.Designer.cs index 83e8285..7961c23 100644 --- a/ntfysh_client/MainForm.Designer.cs +++ b/ntfysh_client/MainForm.Designer.cs @@ -46,6 +46,7 @@ namespace ntfysh_client this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.label1 = new System.Windows.Forms.Label(); + this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.trayContextMenu.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -138,7 +139,8 @@ namespace ntfysh_client // fileToolStripMenuItem // this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.exitToolStripMenuItem1}); + this.exitToolStripMenuItem1, + this.settingsToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); this.fileToolStripMenuItem.Text = "File"; @@ -147,7 +149,7 @@ namespace ntfysh_client // this.exitToolStripMenuItem1.Image = ((System.Drawing.Image)(resources.GetObject("exitToolStripMenuItem1.Image"))); this.exitToolStripMenuItem1.Name = "exitToolStripMenuItem1"; - this.exitToolStripMenuItem1.Size = new System.Drawing.Size(93, 22); + this.exitToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); this.exitToolStripMenuItem1.Text = "Exit"; this.exitToolStripMenuItem1.Click += new System.EventHandler(this.exitToolStripMenuItem1_Click); // @@ -192,6 +194,14 @@ namespace ntfysh_client this.label1.TabIndex = 1; this.label1.Text = "Subscribed Notification Topics:"; // + // settingsToolStripMenuItem + // + this.settingsToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("settingsToolStripMenuItem.Image"))); + this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem"; + this.settingsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.settingsToolStripMenuItem.Text = "Settings"; + this.settingsToolStripMenuItem.Click += new System.EventHandler(this.settingsToolStripMenuItem_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -240,6 +250,7 @@ namespace ntfysh_client private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem ntfyshWebsiteToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem; } } diff --git a/ntfysh_client/MainForm.cs b/ntfysh_client/MainForm.cs index ce77083..469618c 100644 --- a/ntfysh_client/MainForm.cs +++ b/ntfysh_client/MainForm.cs @@ -28,8 +28,12 @@ namespace ntfysh_client InitializeComponent(); } - private void MainForm_Load(object sender, EventArgs e) => LoadTopics(); - + private void MainForm_Load(object sender, EventArgs e) + { + LoadSettings(); + LoadTopics(); + } + protected override void SetVisibleCore(bool value) { if (_startInTray) @@ -66,7 +70,7 @@ namespace ntfysh_client string finalTitle = string.IsNullOrWhiteSpace(e.Title) ? $"{e.Sender.TopicId}@{e.Sender.ServerUrl}" : e.Title; - notifyIcon.ShowBalloonTip(5000, finalTitle, e.Message, priorityIcon); + notifyIcon.ShowBalloonTip((int)TimeSpan.FromSeconds((double)Program.Settings.Timeout).TotalMilliseconds, finalTitle, e.Message, priorityIcon); } private void OnConnectionMultiAttemptFailure(NotificationListener sender, SubscribedTopic topic) @@ -118,6 +122,26 @@ namespace ntfysh_client SaveTopicsToFile(); } + + private void settingsToolStripMenuItem_Click(object sender, EventArgs e) + { + using SettingsDialog dialog = new(); + + //Load current settings into dialog + dialog.Timeout = Program.Settings.Timeout; + + //Show dialog + DialogResult result = dialog.ShowDialog(); + + //Do not save on cancelled dialog + if (result != DialogResult.OK) return; + + //Read new settings from dialog + Program.Settings.Timeout = dialog.Timeout; + + //Save new settings persistently + SaveSettingsToFile(); + } private void notificationTopics_SelectedValueChanged(object sender, EventArgs e) { @@ -132,11 +156,6 @@ namespace ntfysh_client if (clickedItemIndex == -1) notificationTopics.ClearSelected(); } - private void button1_Click(object sender, EventArgs e) - { - Visible = false; - } - private void notifyIcon_Click(object sender, EventArgs e) { MouseEventArgs mouseEv = (MouseEventArgs)e; @@ -171,6 +190,19 @@ namespace ntfysh_client File.WriteAllText(GetTopicsFilePath(), topicsSerialised); } + + private string GetSettingsFilePath() + { + string binaryDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? throw new InvalidOperationException("Unable to determine path for application"); + return Path.Combine(binaryDirectory ?? throw new InvalidOperationException("Unable to determine path for settings file"), "settings.json"); + } + + private void SaveSettingsToFile() + { + string settingsSerialised = JsonConvert.SerializeObject(Program.Settings, Formatting.Indented); + + File.WriteAllText(GetSettingsFilePath(), settingsSerialised); + } private void LoadTopics() { @@ -252,6 +284,54 @@ namespace ntfysh_client } } + private SettingsModel GetDefaultSettings() => new() + { + Timeout = 5 + }; + + private void LoadSettings() + { + string settingsFilePath = GetSettingsFilePath(); + + //Check if we have any settings file on disk to load. If we don't, initialise defaults + if (!File.Exists(settingsFilePath)) + { + Program.Settings = GetDefaultSettings(); + + SaveSettingsToFile(); + + return; + } + + //We have a settings file. Load it! + string settingsSerialised = File.ReadAllText(settingsFilePath); + + //Check if the file is empty. If it is, initialise default settings + if (string.IsNullOrWhiteSpace(settingsSerialised)) + { + Program.Settings = GetDefaultSettings(); + + SaveSettingsToFile(); + + return; + } + + //Deserialise the settings + SettingsModel? settings = JsonConvert.DeserializeObject(settingsSerialised); + + //Check if the deserialise succeeded. If it didn't, initialise default settings + if (settings is null) + { + Program.Settings = GetDefaultSettings(); + + SaveSettingsToFile(); + + return; + } + + Program.Settings = settings; + } + private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { notifyIcon.Dispose(); diff --git a/ntfysh_client/MainForm.resx b/ntfysh_client/MainForm.resx index 85f0136..ceabbf2 100644 --- a/ntfysh_client/MainForm.resx +++ b/ntfysh_client/MainForm.resx @@ -67,7 +67,7 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 - JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA69AAAOvQFH+5CtAAAAiklE + JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAAAiklE QVQ4T8WPQQqAIBBFvUOrXIhu3dcZOkqtu5R1ia4SdRDrxyyGGKmBIOGBDL6nmk9WCGE9yUpW0q9Ads7V GuCQ/kHAe79joAEO6dcLFmttpQEO6c+Bvpm2oZ0zwB4zVQBiF8cIsMdMDPCb+G2vA/wgP/z6C6WAhBgo fUFCDGi4BxIGShLpvy5jDoPes/0oNG3VAAAAAElFTkSuQmCC @@ -76,7 +76,7 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 - JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA69AAAOvQFH+5CtAAAAgUlE + JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAAAgUlE QVQ4T2OgGjjOLq4AZeIFWNWBBI9yib06zC3uABXCCkDyIHVYDTnMI2pzhEvs5VFucSeoEAo4wiNii08e DHAZQshwFICumCTNMADyK1gTl2gJiCYUNlgBSDPQ1v8gGipEPKDIBRSFAa6oIsoQQvGM1xCqpESsglgA seroBRgYAOoOWBJbfVcRAAAAAElFTkSuQmCC @@ -267,16 +267,28 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 - JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA69AAAOvQFH+5CtAAAAgUlE + JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAAAgUlE QVQ4T2OgGjjOLq4AZeIFWNWBBI9yib06zC3uABXCCkDyIHVYDTnMI2pzhEvs5VFucSeoEAo4wiNii08e DHAZQshwFICumCTNMADyK1gTl2gJiCYUNlgBSDPQ1v8gGipEPKDIBRSFAa6oIsoQQvGM1xCqpESsglgA seroBRgYAOoOWBJbfVcRAAAAAElFTkSuQmCC + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 + JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA7CAAAOwgEVKEqAAAABT0lE + QVQ4T7WTzU3DUBCEXQICcSAYx5bdgKkDEuggF37aIJwJVBBfsCsAux+iII6hgvCNM5GV8HeBlUa73tnZ + fe9lE/ybJUlyC5bG2OmfLY7jK1CGYbiLr/v9/kigQeNcqRqXbxrEJXgBBYJX/DviPE3TY8Xk5vgpmIHP + TUhWKoii6AA/RPygWFBMbmCuAKVlnVG0AzHDnzH1iPheJ/HkiXLEp/rWdSxbGckxRTVYeNoEPFF4mGVZ + CC9uYm4BamksbxssIUe6r46pKRKaDjx97uvkqpXGdNdA5G8NNOSrBmPQcDS9fHsFvms1sVjcnTn9Io00 + lq8Mcv2I5xK5yVxQrBwnOCF+o/G+ZZ1BaEkKHRM/0DTFgicPzWkXKss6I7lepClT20XyfXPFzmkHdMpr + yzYN8gJUvV5vD/9M4fYqP34r3jZEetj1n+nG6b+2IPgAzHGHcFUSC1YAAAAASUVORK5CYII= iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 - JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA69AAAOvQFH+5CtAAABDElE + JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAABDElE QVQ4T91RO3bCQAzUy3uhChdJnTVlCj5FcMsZsF1jmy4XycPrzl6fBLgEXMFp4srRiF0wcaBP5j0VI2m0 4zH9EwSq8gPP7ELPNFxtpxrbn9vVPkSsykOkqvHi2QxsWwAevhQTzG8eCb1yD7Glv2I5MlM+sLX0GqEq 6+jVPFl6QZz7lOgdJVnzuMq/sEepbsGln2YnR3AAm0IcIE71geJsTO9mcOWAOa3zicxxxGWApXMGabaH @@ -287,7 +299,7 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 - JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA69AAAOvQFH+5CtAAAAwUlE + JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAAAwUlE QVQ4T2OgClBUVHwAxP9JxA+g2sEG/JeTk5MkBYP0QLVTwQAFBYXHIAFSMEgPVDvYBfulpKSEScEgPVDt dDIA6OTNQHX/YXysBjAxMcUxMjKuBrGB9DIgPxqmARhwOUBD3sD4WA0QERGRBHLvCwoKygLpm6KiohIw DVBNz5HY2L0AtHkOEE8F4okgvoyMjDSSJsIGsLOzuwKFfnBycppJS0vLAJ39BUQTbQA6RnYBMkY3YAVI diff --git a/ntfysh_client/Program.cs b/ntfysh_client/Program.cs index 5942747..9880e89 100644 --- a/ntfysh_client/Program.cs +++ b/ntfysh_client/Program.cs @@ -11,7 +11,8 @@ namespace ntfysh_client static class Program { private static readonly NotificationListener NotificationListener = new(); - + public static SettingsModel Settings { get; set; } = null!; + /// /// The main entry point for the application. /// diff --git a/ntfysh_client/SettingsDialog.Designer.cs b/ntfysh_client/SettingsDialog.Designer.cs new file mode 100644 index 0000000..c7eb2d5 --- /dev/null +++ b/ntfysh_client/SettingsDialog.Designer.cs @@ -0,0 +1,129 @@ + +namespace ntfysh_client +{ + partial class SettingsDialog + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panel1 = new System.Windows.Forms.Panel(); + this.cancelButton = new System.Windows.Forms.Button(); + this.saveButton = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.timeout = new System.Windows.Forms.NumericUpDown(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.timeout)).BeginInit(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.SystemColors.Control; + this.panel1.Controls.Add(this.cancelButton); + this.panel1.Controls.Add(this.saveButton); + this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel1.Location = new System.Drawing.Point(0, 61); + this.panel1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(531, 51); + this.panel1.TabIndex = 9; + // + // cancelButton + // + this.cancelButton.Location = new System.Drawing.Point(363, 16); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 23); + this.cancelButton.TabIndex = 1; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); + // + // saveButton + // + this.saveButton.Location = new System.Drawing.Point(444, 16); + this.saveButton.Name = "saveButton"; + this.saveButton.Size = new System.Drawing.Size(75, 23); + this.saveButton.TabIndex = 0; + this.saveButton.Text = "Save"; + this.saveButton.UseVisualStyleBackColor = true; + this.saveButton.Click += new System.EventHandler(this.saveButton_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 9); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(488, 15); + this.label1.TabIndex = 11; + this.label1.Text = "Notification Toast Timeout (seconds, may be ignored by OS based on accessibility " + + "settings):"; + // + // timeout + // + this.timeout.Location = new System.Drawing.Point(13, 27); + this.timeout.Maximum = new decimal(new int[] { + -1981284353, + -1966660860, + 0, + 0}); + this.timeout.Name = "timeout"; + this.timeout.Size = new System.Drawing.Size(506, 23); + this.timeout.TabIndex = 12; + // + // SettingsDialog + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.White; + this.ClientSize = new System.Drawing.Size(531, 112); + this.Controls.Add(this.timeout); + this.Controls.Add(this.label1); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "SettingsDialog"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Settings"; + this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.timeout)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.NumericUpDown timeout; + private System.Windows.Forms.Button cancelButton; + private System.Windows.Forms.Button saveButton; + } +} \ No newline at end of file diff --git a/ntfysh_client/SettingsDialog.cs b/ntfysh_client/SettingsDialog.cs new file mode 100644 index 0000000..a456fc7 --- /dev/null +++ b/ntfysh_client/SettingsDialog.cs @@ -0,0 +1,29 @@ +using System; +using System.Windows.Forms; + +namespace ntfysh_client +{ + public partial class SettingsDialog : Form + { + public decimal Timeout + { + get => timeout.Value; + set => timeout.Value = value; + } + + public SettingsDialog() + { + InitializeComponent(); + } + + private void saveButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.OK; + } + + private void cancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + } + } +} diff --git a/ntfysh_client/SettingsDialog.resx b/ntfysh_client/SettingsDialog.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ntfysh_client/SettingsDialog.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ntfysh_client/SettingsModel.cs b/ntfysh_client/SettingsModel.cs new file mode 100644 index 0000000..f349748 --- /dev/null +++ b/ntfysh_client/SettingsModel.cs @@ -0,0 +1,7 @@ +namespace ntfysh_client +{ + public class SettingsModel + { + public decimal Timeout { get; set; } + } +} \ No newline at end of file -- 2.49.1 From c2c21e720f2435105b121792290d0283075bc0ec Mon Sep 17 00:00:00 2001 From: Alexander Horner <33007665+alexhorner@users.noreply.github.com> Date: Mon, 12 Dec 2022 21:36:36 +0000 Subject: [PATCH 9/9] Added Settings screenshot --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index abb9e32..5f2034e 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ It is capable of receiving notifications from multiple ntfy.sh servers simultane ### Main Application ![Application screenshot](https://user-images.githubusercontent.com/33007665/206556170-962fd699-988c-477e-941e-5179b9f4a67c.png) ![Topic Subscribe screenshot](https://user-images.githubusercontent.com/33007665/206556398-5ee95cee-6fc8-4234-b46e-6380cdfc94dd.png) +![Settings screenshot](https://user-images.githubusercontent.com/33007665/207159693-40542c12-1669-4f32-b1c6-4a8542ac1539.png) ### Example Notifications ![Default toast](https://user-images.githubusercontent.com/33007665/206558550-9903b9e3-7f6b-418d-8a46-1311708b5b3e.png) -- 2.49.1