Add very basic but functional support for authentication and custom servers

This commit is contained in:
Alexander Horner
2022-12-06 19:37:39 +00:00
parent b66620c9da
commit 0a11d5a583
9 changed files with 662 additions and 105 deletions

View File

@@ -40,12 +40,12 @@ namespace ntfysh_client
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.label1 = new System.Windows.Forms.Label();
this.exitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ntfyshWebsiteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.label1 = new System.Windows.Forms.Label();
this.trayContextMenu.SuspendLayout();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@@ -75,8 +75,7 @@ namespace ntfysh_client
//
// notificationTopics
//
this.notificationTopics.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.notificationTopics.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
this.notificationTopics.FormattingEnabled = true;
this.notificationTopics.Location = new System.Drawing.Point(12, 50);
this.notificationTopics.Name = "notificationTopics";
@@ -96,9 +95,7 @@ namespace ntfysh_client
//
// trayContextMenu
//
this.trayContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.showControlWindowToolStripMenuItem,
this.exitToolStripMenuItem});
this.trayContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.showControlWindowToolStripMenuItem, this.exitToolStripMenuItem });
this.trayContextMenu.Name = "trayContextMenu";
this.trayContextMenu.Size = new System.Drawing.Size(190, 48);
//
@@ -121,9 +118,7 @@ namespace ntfysh_client
// menuStrip1
//
this.menuStrip1.BackColor = System.Drawing.Color.White;
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.helpToolStripMenuItem});
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.helpToolStripMenuItem });
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(353, 24);
@@ -132,45 +127,24 @@ namespace ntfysh_client
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.exitToolStripMenuItem1});
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.exitToolStripMenuItem1 });
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Text = "File";
//
// helpToolStripMenuItem
//
this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ntfyshWebsiteToolStripMenuItem,
this.toolStripMenuItem1,
this.aboutToolStripMenuItem});
this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
this.helpToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
this.helpToolStripMenuItem.Text = "Help";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 34);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(145, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Subscribed notification topics";
//
// exitToolStripMenuItem1
//
this.exitToolStripMenuItem1.Image = ((System.Drawing.Image)(resources.GetObject("exitToolStripMenuItem1.Image")));
this.exitToolStripMenuItem1.Name = "exitToolStripMenuItem1";
this.exitToolStripMenuItem1.Size = new System.Drawing.Size(180, 22);
this.exitToolStripMenuItem1.Size = new System.Drawing.Size(93, 22);
this.exitToolStripMenuItem1.Text = "Exit";
//
// aboutToolStripMenuItem
// helpToolStripMenuItem
//
this.aboutToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("aboutToolStripMenuItem.Image")));
this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
this.aboutToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.aboutToolStripMenuItem.Text = "About";
this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ntfyshWebsiteToolStripMenuItem, this.toolStripMenuItem1, this.aboutToolStripMenuItem });
this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
this.helpToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
this.helpToolStripMenuItem.Text = "Help";
//
// ntfyshWebsiteToolStripMenuItem
//
@@ -185,6 +159,23 @@ namespace ntfysh_client
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(182, 6);
//
// aboutToolStripMenuItem
//
this.aboutToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("aboutToolStripMenuItem.Image")));
this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
this.aboutToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.aboutToolStripMenuItem.Text = "About";
this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 34);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(145, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Subscribed notification topics";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -213,7 +204,6 @@ namespace ntfysh_client
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion

View File

@@ -36,7 +36,7 @@ namespace ntfysh_client
if (result == DialogResult.OK)
{
notificationListener.SubscribeToTopic(dialog.getTopicId());
notificationListener.SubscribeToTopic(dialog.getTopicId(), dialog.getServerUrl(), dialog.getUsername(), dialog.getPassword());
notificationTopics.Items.Add(dialog.getTopicId());
this.SaveTopicsToFile();
}
@@ -117,7 +117,7 @@ namespace ntfysh_client
while (!reader.EndOfStream)
{
var topic = reader.ReadLine();
notificationListener.SubscribeToTopic(topic);
notificationListener.SubscribeToTopic(topic, "https://ntfy.sh", null, null);
notificationTopics.Items.Add(topic);
}
}

View File

@@ -124,6 +124,24 @@
<value>123, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="showControlWindowToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAiklE
QVQ4T8WPQQqAIBBFvUOrXIhu3dcZOkqtu5R1ia4SdRDrxyyGGKmBIOGBDL6nmk9WCGE9yUpW0q9Ads7V
GuCQ/kHAe79joAEO6dcLFmttpQEO6c+Bvpm2oZ0zwB4zVQBiF8cIsMdMDPCb+G2vA/wgP/z6C6WAhBgo
fUFCDGi4BxIGShLpvy5jDoPes/0oNG3VAAAAAElFTkSuQmCC
</value>
</data>
<data name="exitToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAgUlE
QVQ4T2OgGjjOLq4AZeIFWNWBBI9yib06zC3uABXCCkDyIHVYDTnMI2pzhEvs5VFucSeoEAo4wiNii08e
DHAZQshwFICumCTNMADyK1gTl2gJiCYUNlgBSDPQ1v8gGipEPKDIBRSFAa6oIsoQQvGM1xCqpESsglgA
seroBRgYAOoOWBJbfVcRAAAAAElFTkSuQmCC
</value>
</data>
<data name="notifyIcon.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAEAMjIAAAEAIADIKAAAFgAAACgAAAAyAAAAZAAAAAEAIAAAAAAAECcAACMuAAAjLgAAAAAAAAAA
@@ -303,16 +321,10 @@
/////8AA////////wAD////////AAA==
</value>
</data>
<data name="showControlWindowToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAiklE
QVQ4T8WPQQqAIBBFvUOrXIhu3dcZOkqtu5R1ia4SdRDrxyyGGKmBIOGBDL6nmk9WCGE9yUpW0q9Ads7V
GuCQ/kHAe79joAEO6dcLFmttpQEO6c+Bvpm2oZ0zwB4zVQBiF8cIsMdMDPCb+G2vA/wgP/z6C6WAhBgo
fUFCDGi4BxIGShLpvy5jDoPes/0oNG3VAAAAAElFTkSuQmCC
</value>
</data>
<data name="exitToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>269, 17</value>
</metadata>
<data name="exitToolStripMenuItem1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAgUlE
@@ -321,9 +333,6 @@
seroBRgYAOoOWBJbfVcRAAAAAElFTkSuQmCC
</value>
</data>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>269, 17</value>
</metadata>
<data name="ntfyshWebsiteToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6
@@ -343,15 +352,6 @@
dDIA6OTNQHX/YXysBjAxMcUxMjKuBrGB9DIgPxqmARhwOUBD3sD4WA0QERGRBHLvCwoKygLpm6KiohIw
DVBNz5HY2L0AtHkOEE8F4okgvoyMjDSSJsIGsLOzuwKFfnBycppJS0vLAJ39BUQTbQA6RnYBMkY3YAVI
gES8Aqp9QAEDAwCq9oYvtggceQAAAABJRU5ErkJggg==
</value>
</data>
<data name="exitToolStripMenuItem1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAgUlE
QVQ4T2OgGjjOLq4AZeIFWNWBBI9yib06zC3uABXCCkDyIHVYDTnMI2pzhEvs5VFucSeoEAo4wiNii08e
DHAZQshwFICumCTNMADyK1gTl2gJiCYUNlgBSDPQ1v8gGipEPKDIBRSFAa6oIsoQQvGM1xCqpESsglgA
seroBRgYAOoOWBJbfVcRAAAAAElFTkSuQmCC
</value>
</data>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">

View File

@@ -6,6 +6,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -19,7 +20,7 @@ namespace ntfysh_client
private bool disposedValue;
public Dictionary<string, StreamReader> subscribedTopics;
public readonly Dictionary<string, SubscribedTopic> SubscribedTopics = new Dictionary<string, SubscribedTopic>();
public delegate void NotificationReceiveHandler(object sender, NotificationReceiveEventArgs e);
public event NotificationReceiveHandler OnNotificationReceive;
@@ -27,22 +28,32 @@ namespace ntfysh_client
public NotificationListener()
{
httpClient = new HttpClient();
subscribedTopics = new Dictionary<string, StreamReader>();
httpClient.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
ServicePointManager.DefaultConnectionLimit = 100;
}
public async Task SubscribeToTopic(string topicId)
public async Task SubscribeToTopic(string topicId, string serverUrl, string username, string password)
{
HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Get, $"https://ntfy.sh/{HttpUtility.UrlEncode(topicId)}/json");
using (var response = await httpClient.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead))
if (string.IsNullOrWhiteSpace(username)) username = null;
if (string.IsNullOrWhiteSpace(password)) password = null;
HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Get, $"{serverUrl}/{HttpUtility.UrlEncode(topicId)}/json");
if (username != null && password != null)
{
using (var body = await response.Content.ReadAsStreamAsync())
byte[] boundCredentialsBytes = Encoding.UTF8.GetBytes($"{username}:{password}");
msg.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(boundCredentialsBytes));
}
using (HttpResponseMessage response = await httpClient.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead))
{
using (Stream body = await response.Content.ReadAsStreamAsync())
{
using (StreamReader reader = new StreamReader(body))
{
subscribedTopics.Add(topicId, reader);
SubscribedTopics.Add(topicId, new SubscribedTopic(topicId, serverUrl, username, password, reader));
try
{
@@ -71,9 +82,9 @@ namespace ntfysh_client
// If the topic is still registered, then that stream wasn't mean to be closed (maybe network failure?)
// Restart it
if (subscribedTopics.ContainsKey(topicId))
if (SubscribedTopics.ContainsKey(topicId))
{
SubscribeToTopic(topicId);
SubscribeToTopic(topicId, serverUrl, username, password);
}
}
}
@@ -85,12 +96,12 @@ namespace ntfysh_client
{
Debug.WriteLine($"Removing topic {topicId}");
if (subscribedTopics.ContainsKey(topicId))
if (SubscribedTopics.ContainsKey(topicId))
{
// Not moronic to store it in a variable; this solves a race condition in SubscribeToTopic
var topic = subscribedTopics[topicId];
subscribedTopics.Remove(topicId);
topic.Close();
var topic = SubscribedTopics[topicId];
SubscribedTopics.Remove(topicId);
topic.Stream.Close();
}
}

View File

@@ -30,10 +30,16 @@ namespace ntfysh_client
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.topicId = new System.Windows.Forms.TextBox();
this.serverUrl = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.username = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.password = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
@@ -43,23 +49,11 @@ namespace ntfysh_client
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.button1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel1.Location = new System.Drawing.Point(0, 81);
this.panel1.Location = new System.Drawing.Point(0, 175);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(297, 44);
this.panel1.TabIndex = 0;
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(212, 11);
this.button1.Margin = new System.Windows.Forms.Padding(3, 10, 10, 10);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "Subscribe";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
@@ -72,10 +66,22 @@ namespace ntfysh_client
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(212, 11);
this.button1.Margin = new System.Windows.Forms.Padding(3, 10, 10, 10);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "Subscribe";
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, 23);
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(51, 13);
this.label1.TabIndex = 1;
@@ -83,20 +89,85 @@ namespace ntfysh_client
//
// topicId
//
this.topicId.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.topicId.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.topicId.Location = new System.Drawing.Point(15, 39);
this.topicId.Location = new System.Drawing.Point(12, 25);
this.topicId.Name = "topicId";
this.topicId.Size = new System.Drawing.Size(273, 20);
this.topicId.TabIndex = 0;
this.topicId.KeyDown += new System.Windows.Forms.KeyEventHandler(this.topicId_KeyDown);
//
// serverUrl
//
this.serverUrl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.serverUrl.Location = new System.Drawing.Point(12, 64);
this.serverUrl.Name = "serverUrl";
this.serverUrl.Size = new System.Drawing.Size(273, 20);
this.serverUrl.TabIndex = 2;
this.serverUrl.Text = "https://ntfy.sh";
this.serverUrl.KeyDown += new System.Windows.Forms.KeyEventHandler(this.serverUrl_KeyDown);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(10, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(66, 13);
this.label2.TabIndex = 3;
this.label2.Text = "Server URL:";
//
// username
//
this.username.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.username.Location = new System.Drawing.Point(12, 103);
this.username.Name = "username";
this.username.Size = new System.Drawing.Size(273, 20);
this.username.TabIndex = 4;
this.username.KeyDown += new System.Windows.Forms.KeyEventHandler(this.username_KeyDown);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(10, 87);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(58, 13);
this.label3.TabIndex = 5;
this.label3.Text = "Username:";
//
// password
//
this.password.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.password.Location = new System.Drawing.Point(12, 142);
this.password.Name = "password";
this.password.Size = new System.Drawing.Size(273, 20);
this.password.TabIndex = 6;
this.password.UseSystemPasswordChar = true;
this.password.KeyDown += new System.Windows.Forms.KeyEventHandler(this.password_KeyDown);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(10, 126);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 13);
this.label4.TabIndex = 7;
this.label4.Text = "Password:";
//
// SubscribeDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(297, 125);
this.ClientSize = new System.Drawing.Size(297, 219);
this.Controls.Add(this.password);
this.Controls.Add(this.label4);
this.Controls.Add(this.username);
this.Controls.Add(this.label3);
this.Controls.Add(this.serverUrl);
this.Controls.Add(this.label2);
this.Controls.Add(this.topicId);
this.Controls.Add(this.label1);
this.Controls.Add(this.panel1);
@@ -114,6 +185,9 @@ namespace ntfysh_client
}
private System.Windows.Forms.TextBox serverUrl;
private System.Windows.Forms.Label label2;
#endregion
private System.Windows.Forms.Panel panel1;
@@ -121,5 +195,9 @@ namespace ntfysh_client
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox topicId;
private System.Windows.Forms.TextBox username;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox password;
private System.Windows.Forms.Label label4;
}
}

View File

@@ -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
@@ -21,6 +14,21 @@ namespace ntfysh_client
{
return topicId.Text;
}
public string getServerUrl()
{
return serverUrl.Text;
}
public string getUsername()
{
return username.Text;
}
public string getPassword()
{
return password.Text;
}
private void button1_Click(object sender, EventArgs e)
{
@@ -32,6 +40,30 @@ namespace ntfysh_client
return;
}
if (serverUrl.Text.Length < 1)
{
MessageBox.Show("You must specify a server URL. The default is https://ntfy.sh", "Server URL not specified", MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = DialogResult.None;
serverUrl.Focus();
return;
}
if (username.Text.Length > 0 && password.Text.Length < 1)
{
MessageBox.Show("You must specify a password alongside the username", "Password not specified", MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = DialogResult.None;
password.Focus();
return;
}
if (password.Text.Length > 0 && username.Text.Length < 1)
{
MessageBox.Show("You must specify a username alongside the password", "Username not specified", MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = DialogResult.None;
username.Focus();
return;
}
DialogResult = DialogResult.OK;
}
@@ -48,5 +80,32 @@ namespace ntfysh_client
e.SuppressKeyPress = true;
}
}
private void serverUrl_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
button1.PerformClick();
e.SuppressKeyPress = true;
}
}
private void username_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
button1.PerformClick();
e.SuppressKeyPress = true;
}
}
private void password_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
button1.PerformClick();
e.SuppressKeyPress = true;
}
}
}
}

View File

@@ -0,0 +1,23 @@
using System.IO;
namespace ntfysh_client
{
public class SubscribedTopic
{
public SubscribedTopic(string topicId, string serverUrl, string username, string password, StreamReader stream)
{
TopicId = topicId;
ServerUrl = serverUrl;
Username = username;
Password = password;
Stream = stream;
}
public string TopicId { get; }
public string ServerUrl { get; }
public string Username { get; }
public string Password { get; }
public StreamReader Stream { get; }
}
}

View File

@@ -74,6 +74,7 @@
<Compile Include="SubscribeDialog.Designer.cs">
<DependentUpon>SubscribeDialog.cs</DependentUpon>
</Compile>
<Compile Include="SubscribedTopic.cs" />
<EmbeddedResource Include="AboutBox.resx">
<DependentUpon>AboutBox.cs</DependentUpon>
</EmbeddedResource>