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/README.md b/README.md
index ab52659..5f2034e 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,27 @@
# ntfy.sh Windows
-
+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.
-A [ntfy.sh](https://ntfy.sh/) client for Windows.
\ No newline at end of file
+## Screenshots
+### Main Application
+
+
+
+
+### Example Notifications
+
+
+
+
+
+## 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
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
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.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 bd1bf9f..469618c 100644
--- a/ntfysh_client/MainForm.cs
+++ b/ntfysh_client/MainForm.cs
@@ -7,27 +7,70 @@ using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using Newtonsoft.Json;
+using ntfysh_client.Notifications;
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)
+ {
+ LoadSettings();
+ 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)
{
- 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((int)TimeSpan.FromSeconds((double)Program.Settings.Timeout).TotalMilliseconds, finalTitle, e.Message, priorityIcon);
}
private void OnConnectionMultiAttemptFailure(NotificationListener sender, SubscribedTopic topic)
@@ -42,8 +85,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);
@@ -81,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)
{
@@ -95,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;
@@ -134,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()
{
@@ -215,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 dbf516e..ceabbf2 100644
--- a/ntfysh_client/MainForm.resx
+++ b/ntfysh_client/MainForm.resx
@@ -67,7 +67,7 @@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CculE8AAAACXBIWXMAAA6+AAAOvgHqQrHAAAABDElE
+ JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAABDElE
QVQ4T91RO3bCQAzUy3uhChdJnTVlCj5FcMsZsF1jmy4XycPrzl6fBLgEXMFp4srRiF0wcaBP5j0VI2m0
4zH9EwSq8gPP7ELPNFxtpxrbn9vVPkSsykOkqvHi2QxsWwAevhQTzG8eCb1yD7Glv2I5MlM+sLX0GqEq
6+jVPFl6QZz7lOgdJVnzuMq/sEepbsGln2YnR3AAm0IcIE71geJsTO9mcOWAOa3zicxxxGWApXMGabaH
@@ -287,7 +299,7 @@
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6
- JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA6+AAAOvgHqQrHAAAAAwUlE
+ JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAAAwUlE
QVQ4T2OgClBUVHwAxP9JxA+g2sEG/JeTk5MkBYP0QLVTwQAFBYXHIAFSMEgPVDvYBfulpKSEScEgPVDt
dDIA6OTNQHX/YXysBjAxMcUxMjKuBrGB9DIgPxqmARhwOUBD3sD4WA0QERGRBHLvCwoKygLpm6KiohIw
DVBNz5HY2L0AtHkOEE8F4okgvoyMjDSSJsIGsLOzuwKFfnBycppJS0vLAJ39BUQTbQA6RnYBMkY3YAVI
diff --git a/ntfysh_client/NotificationReceiveEventArgs.cs b/ntfysh_client/NotificationReceiveEventArgs.cs
deleted file mode 100644
index 87d932e..0000000
--- a/ntfysh_client/NotificationReceiveEventArgs.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using System;
-
-namespace ntfysh_client
-{
- public class NotificationReceiveEventArgs : EventArgs
- {
- public string Title { get; }
- public string Message { get; }
-
- public NotificationReceiveEventArgs(string title, string message)
- {
- Title = title;
- Message = message;
- }
- }
-}
\ No newline at end of file
diff --git a/ntfysh_client/NotificationListener.cs b/ntfysh_client/Notifications/NotificationListener.cs
similarity index 98%
rename from ntfysh_client/NotificationListener.cs
rename to ntfysh_client/Notifications/NotificationListener.cs
index 5e4d58c..f0acaa6 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
{
@@ -85,7 +85,7 @@ namespace ntfysh_client
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
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
}
}
- private void ProcessMessage(string message)
+ private void ProcessMessage(SubscribedTopic topic, string message)
{
#if DEBUG
Debug.WriteLine(message);
@@ -257,7 +257,7 @@ namespace ntfysh_client
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
new file mode 100644
index 0000000..d87363d
--- /dev/null
+++ b/ntfysh_client/Notifications/NotificationReceiveEventArgs.cs
@@ -0,0 +1,20 @@
+using System;
+
+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(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/NtfyEvent.cs b/ntfysh_client/Notifications/NtfyEvent.cs
similarity index 73%
rename from ntfysh_client/NtfyEvent.cs
rename to ntfysh_client/Notifications/NtfyEvent.cs
index ef4ee82..de54962 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
{
@@ -20,6 +20,9 @@ namespace ntfysh_client
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
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 5841c89..9880e89 100644
--- a/ntfysh_client/Program.cs
+++ b/ntfysh_client/Program.cs
@@ -1,25 +1,48 @@
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;
+using ntfysh_client.Notifications;
namespace ntfysh_client
{
static class Program
{
- private static readonly NotificationListener NotificationListener = new NotificationListener();
-
+ private static readonly NotificationListener NotificationListener = new();
+ public static SettingsModel Settings { get; set; } = null!;
+
///
/// 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));
}
}
}
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
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
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