28 Commits
1.0.1 ... v1.3

Author SHA1 Message Date
Lucas Bortoli
cb55d0148d Merge pull request #11 from alexhorner/master
Add adjustable reconnects and settings revisions
2023-12-28 12:14:50 -03:00
Alexander Horner
0155cfb8fc Add adjustable reconnects and settings revisions 2023-10-09 21:11:07 +01:00
Lucas Bortoli
68b0bf3eb9 Merge pull request #4 from alexhorner/master
Prevent multiple instances, allow starting in tray, documentation edits and priority support
2022-12-12 19:01:23 -03:00
Alexander Horner
c2c21e720f Added Settings screenshot 2022-12-12 21:36:36 +00:00
Alexander Horner
67b6e5b607 Add new timeout option and supporting settings infrastructure 2022-12-12 21:32:46 +00:00
Alexander Horner
1a73981d20 Add command line parameters 2022-12-08 20:28:26 +00:00
Alexander Horner
79d04b4a58 New screenshots and text 2022-12-08 20:21:51 +00:00
Alexander Horner
617f1e658a Add publish config and adjust app publish name 2022-12-08 20:12:29 +00:00
Alexander Horner
7f73bd2cd1 Add support for priority
Set default title to topic unique, as displayed in subscriptions list, if not provided
Increase toast timeout to 5 seconds
2022-12-08 19:54:14 +00:00
Alexander Horner
d90ddc3be4 Solution cleanup 2022-12-08 19:33:08 +00:00
Alexander Horner
b644035433 Add license to About box and fancy it up a little 2022-12-08 19:30:31 +00:00
Alexander Horner
c4291e6f44 Default to preventing multiple instances
Allow multiple instances if overridden with command line parameter
Allow starting minimised to tray with command line parameter
2022-12-08 19:04:43 +00:00
Lucas Bortoli
2a0d41759b Add MIT License to project 2022-12-08 12:00:48 -03:00
Lucas Bortoli
4e97e81b80 Merge pull request #2 from alexhorner/master
Major overhaul
2022-12-08 10:13:17 -03:00
Alexander Horner
2a8a7e3c0c Adjust subscribe window tab index 2022-12-07 23:31:13 +00:00
Alexander Horner
2b298d6e19 Fix credentials on websocket 2022-12-07 23:28:09 +00:00
Alexander Horner
ecbde9509f Implement error handling and notification 2022-12-07 23:20:36 +00:00
Alexander Horner
1e1187e71f Basic Websocket support working, without authentication (auth broken) 2022-12-07 21:36:03 +00:00
Alexander Horner
fe4ae354b2 Rename main form 2022-12-07 19:54:48 +00:00
Alexander Horner
294747def5 Adjust layout of main form to make long topic names visible 2022-12-07 19:40:37 +00:00
Alexander Horner
76031ee868 Squash that async bug for good 2022-12-06 23:31:11 +00:00
Alexander Horner
bba9051b4b Fix browser launch 2022-12-06 23:27:30 +00:00
Alexander Horner
012eeaa65f Enable .NET Core system aware DPI mode
Fix Exit button in window menu
Cleanup
2022-12-06 23:25:07 +00:00
Alexander Horner
fde9a03887 Upgrade to .NET Core 6 (Windows Only Target) and fix UI thread deadlock bug 2022-12-06 23:17:03 +00:00
Alexander Horner
ed5a43a0e8 Complete refactor, reasync, rebuild listener 2022-12-06 22:34:32 +00:00
Alexander Horner
5a4dfc01b6 Fix topic uniqueness issue 2022-12-06 20:14:45 +00:00
Alexander Horner
6aa48fdd2f Start some really basic persistence support. Buggy because of async missing 2022-12-06 19:59:32 +00:00
Alexander Horner
0a11d5a583 Add very basic but functional support for authentication and custom servers 2022-12-06 19:37:39 +00:00
32 changed files with 2151 additions and 927 deletions

401
.gitignore vendored
View File

@@ -1,4 +1,399 @@
bin/
obj/
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
packages/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml
/.idea

View File

@@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Publish ntfysh_client to folder" type="DotNetFolderPublish" factoryName="Publish to folder">
<riderPublish configuration="Release" delete_existing_files="true" platform="Any CPU" runtime="win-x86" target_folder="./bin/Publish/net6.0-windows" target_framework="net6.0-windows" uuid_high="6492169016564532222" uuid_low="-5168761336838336273" />
<method v="2" />
</configuration>
</component>

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 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.

View File

@@ -1,7 +1,27 @@
# 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.
## 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)
![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)
![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

View File

@@ -29,53 +29,107 @@ namespace ntfysh_client
/// </summary>
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;
}
}

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

View File

@@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
@@ -117,4 +57,24 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="richTextBox2.Text" xml:space="preserve">
<value>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</value>
</data>
<data name="richTextBox1.Text" xml:space="preserve">
<value>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)</value>
</data>
</root>

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

View File

@@ -1,167 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ntfysh_client
{
public partial class Form1 : Form
{
private NotificationListener notificationListener;
public Form1()
{
notificationListener = new NotificationListener();
notificationListener.OnNotificationReceive += OnNotificationReceive;
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.LoadTopics();
}
private void subscribeNewTopic_Click(object sender, EventArgs e)
{
using (var dialog = new SubscribeDialog())
{
var result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
notificationListener.SubscribeToTopic(dialog.getTopicId());
notificationTopics.Items.Add(dialog.getTopicId());
this.SaveTopicsToFile();
}
}
}
private void removeSelectedTopics_Click(object sender, EventArgs e)
{
while (notificationTopics.SelectedIndex > -1)
{
var topicId = notificationTopics.Items[notificationTopics.SelectedIndex];
notificationListener.RemoveTopic((string)topicId);
notificationTopics.Items.RemoveAt(notificationTopics.SelectedIndex);
}
this.SaveTopicsToFile();
}
private void notificationTopics_SelectedValueChanged(object sender, EventArgs e)
{
removeSelectedTopics.Enabled = notificationTopics.SelectedIndices.Count > 0;
}
private void notificationTopics_Click(object sender, EventArgs e)
{
var ev = (MouseEventArgs)e;
var clickedItemIndex = notificationTopics.IndexFromPoint(new Point(ev.X, ev.Y));
if (clickedItemIndex == -1)
{
notificationTopics.ClearSelected();
}
}
private void button1_Click(object sender, EventArgs e)
{
this.Visible = false;
}
private void notifyIcon_Click(object sender, EventArgs e)
{
var mouseEv = (MouseEventArgs)e;
if (mouseEv.Button == MouseButtons.Left)
{
this.Visible = !this.Visible;
this.BringToFront();
}
}
private void showControlWindowToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Visible = true;
this.BringToFront();
}
private string GetTopicsFilePath()
{
string binaryDirectory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
return Path.Combine(binaryDirectory, "topics.txt");
}
private void SaveTopicsToFile()
{
using (StreamWriter writer = new StreamWriter(GetTopicsFilePath()))
{
foreach (string topic in notificationTopics.Items)
{
writer.WriteLine(topic);
}
}
}
private void LoadTopics()
{
if (!File.Exists(GetTopicsFilePath())) return;
using (StreamReader reader = new StreamReader(GetTopicsFilePath()))
{
while (!reader.EndOfStream)
{
var topic = reader.ReadLine();
notificationListener.SubscribeToTopic(topic);
notificationTopics.Items.Add(topic);
}
}
}
private void OnNotificationReceive(object sender, NotificationReceiveEventArgs e)
{
notifyIcon.ShowBalloonTip(3000, e.Title, e.Message, ToolTipIcon.Info);
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
notifyIcon.Dispose();
}
private bool trueExit = false;
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Let it close
if (trueExit) return;
if (e.CloseReason == CloseReason.UserClosing)
{
this.Visible = false;
e.Cancel = true;
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
trueExit = true;
this.Close();
}
private void ntfyshWebsiteToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://ntfy.sh/");
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
var d = new AboutBox();
d.ShowDialog();
d.Dispose();
}
}
}

View File

@@ -1,7 +1,7 @@

namespace ntfysh_client
{
partial class Form1
partial class MainForm
{
/// <summary>
/// Required designer variable.
@@ -30,7 +30,7 @@ namespace ntfysh_client
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.subscribeNewTopic = new System.Windows.Forms.Button();
this.removeSelectedTopics = new System.Windows.Forms.Button();
this.notificationTopics = new System.Windows.Forms.ListBox();
@@ -40,12 +40,13 @@ 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.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.trayContextMenu.SuspendLayout();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@@ -53,9 +54,10 @@ namespace ntfysh_client
// subscribeNewTopic
//
this.subscribeNewTopic.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.subscribeNewTopic.Location = new System.Drawing.Point(236, 50);
this.subscribeNewTopic.Location = new System.Drawing.Point(211, 251);
this.subscribeNewTopic.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.subscribeNewTopic.Name = "subscribeNewTopic";
this.subscribeNewTopic.Size = new System.Drawing.Size(105, 23);
this.subscribeNewTopic.Size = new System.Drawing.Size(188, 27);
this.subscribeNewTopic.TabIndex = 2;
this.subscribeNewTopic.Text = "Add";
this.subscribeNewTopic.UseVisualStyleBackColor = true;
@@ -65,9 +67,10 @@ namespace ntfysh_client
//
this.removeSelectedTopics.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.removeSelectedTopics.Enabled = false;
this.removeSelectedTopics.Location = new System.Drawing.Point(236, 79);
this.removeSelectedTopics.Location = new System.Drawing.Point(13, 251);
this.removeSelectedTopics.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.removeSelectedTopics.Name = "removeSelectedTopics";
this.removeSelectedTopics.Size = new System.Drawing.Size(105, 23);
this.removeSelectedTopics.Size = new System.Drawing.Size(188, 27);
this.removeSelectedTopics.TabIndex = 0;
this.removeSelectedTopics.Text = "Remove selected";
this.removeSelectedTopics.UseVisualStyleBackColor = true;
@@ -78,10 +81,12 @@ namespace ntfysh_client
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.ItemHeight = 15;
this.notificationTopics.Location = new System.Drawing.Point(13, 46);
this.notificationTopics.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.notificationTopics.Name = "notificationTopics";
this.notificationTopics.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.notificationTopics.Size = new System.Drawing.Size(145, 173);
this.notificationTopics.Size = new System.Drawing.Size(386, 199);
this.notificationTopics.TabIndex = 3;
this.notificationTopics.Click += new System.EventHandler(this.notificationTopics_Click);
this.notificationTopics.SelectedValueChanged += new System.EventHandler(this.notificationTopics_SelectedValueChanged);
@@ -126,18 +131,28 @@ namespace ntfysh_client
this.helpToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(353, 24);
this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2);
this.menuStrip1.Size = new System.Drawing.Size(412, 24);
this.menuStrip1.TabIndex = 4;
this.menuStrip1.Text = "menuStrip1";
//
// 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";
//
// 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.Text = "Exit";
this.exitToolStripMenuItem1.Click += new System.EventHandler(this.exitToolStripMenuItem1_Click);
//
// helpToolStripMenuItem
//
this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -148,30 +163,6 @@ namespace ntfysh_client
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.Text = "Exit";
//
// 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);
//
// ntfyshWebsiteToolStripMenuItem
//
this.ntfyshWebsiteToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("ntfyshWebsiteToolStripMenuItem.Image")));
@@ -185,12 +176,38 @@ namespace ntfysh_client
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(182, 6);
//
// Form1
// aboutToolStripMenuItem
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
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(13, 27);
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(170, 15);
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);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(353, 236);
this.ClientSize = new System.Drawing.Size(412, 288);
this.Controls.Add(this.menuStrip1);
this.Controls.Add(this.notificationTopics);
this.Controls.Add(this.removeSelectedTopics);
@@ -200,14 +217,15 @@ namespace ntfysh_client
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyPreview = true;
this.MainMenuStrip = this.menuStrip1;
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ntfy.sh";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed);
this.Load += new System.EventHandler(this.Form1_Load);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed);
this.Load += new System.EventHandler(this.MainForm_Load);
this.trayContextMenu.ResumeLayout(false);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
@@ -232,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;
}
}

413
ntfysh_client/MainForm.cs Normal file
View File

@@ -0,0 +1,413 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
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, 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)
{
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)
{
MessageBox.Show($"Connecting to topic ID '{topic.TopicId}' on server '{topic.ServerUrl}' failed after multiple attempts.\n\nThis topic ID will be ignored and you will not receive notifications for it until you restart the application.", "Connection Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void OnConnectionCredentialsFailure(NotificationListener sender, SubscribedTopic topic)
{
string reason = string.IsNullOrWhiteSpace(topic.Username) ? "credentials are required but were not provided" : "the entered credentials are incorrect";
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 subscribeNewTopic_Click(object sender, EventArgs e)
{
using SubscribeDialog dialog = new SubscribeDialog(notificationTopics);
DialogResult result = dialog.ShowDialog();
//Do not subscribe on cancelled dialog
if (result != DialogResult.OK) return;
//Convert the reconnection values to ints
int reconnectAttempts = Convert.ToInt32(Math.Ceiling(Program.Settings.ReconnectAttempts));
int reconnectAttemptDelay = Convert.ToInt32(Math.Ceiling(Program.Settings.ReconnectAttemptDelay));
//Subscribe
if (dialog.UseWebsockets)
{
_notificationListener.SubscribeToTopicUsingWebsocket(dialog.Unique, dialog.TopicId, dialog.ServerUrl, dialog.Username, dialog.Password, reconnectAttempts, reconnectAttemptDelay);
}
else
{
_notificationListener.SubscribeToTopicUsingLongHttpJson(dialog.Unique, dialog.TopicId, dialog.ServerUrl, dialog.Username, dialog.Password, reconnectAttempts, reconnectAttemptDelay);
}
//Add to the user visible list
notificationTopics.Items.Add(dialog.Unique);
//Save the topics persistently
SaveTopicsToFile();
}
private async void removeSelectedTopics_Click(object sender, EventArgs e)
{
while (notificationTopics.SelectedIndex > -1)
{
string topicUniqueString = (string)notificationTopics.Items[notificationTopics.SelectedIndex];
await _notificationListener.UnsubscribeFromTopicAsync(topicUniqueString);
notificationTopics.Items.Remove(topicUniqueString);
}
SaveTopicsToFile();
}
private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
{
using SettingsDialog dialog = new();
//Load current settings into dialog
dialog.Timeout = Program.Settings.Timeout;
dialog.ReconnectAttempts = Program.Settings.ReconnectAttempts;
dialog.ReconnectAttemptDelay = Program.Settings.ReconnectAttemptDelay;
//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;
Program.Settings.ReconnectAttempts = dialog.ReconnectAttempts;
Program.Settings.ReconnectAttemptDelay = dialog.ReconnectAttemptDelay;
//Save new settings persistently
SaveSettingsToFile();
}
private void notificationTopics_SelectedValueChanged(object sender, EventArgs e)
{
removeSelectedTopics.Enabled = notificationTopics.SelectedIndices.Count > 0;
}
private void notificationTopics_Click(object sender, EventArgs e)
{
MouseEventArgs ev = (MouseEventArgs)e;
int clickedItemIndex = notificationTopics.IndexFromPoint(new Point(ev.X, ev.Y));
if (clickedItemIndex == -1) notificationTopics.ClearSelected();
}
private void notifyIcon_Click(object sender, EventArgs e)
{
MouseEventArgs mouseEv = (MouseEventArgs)e;
if (mouseEv.Button != MouseButtons.Left) return;
Visible = !Visible;
BringToFront();
}
private void showControlWindowToolStripMenuItem_Click(object sender, EventArgs e)
{
Visible = true;
BringToFront();
}
private string GetTopicsFilePath()
{
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 topics file"), "topics.json");
}
private string GetLegacyTopicsFilePath()
{
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 legacy topics file"), "topics.txt");
}
private void SaveTopicsToFile()
{
string topicsSerialised = JsonConvert.SerializeObject(_notificationListener.SubscribedTopicsByUnique.Select(st => st.Value).ToList(), Formatting.Indented);
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()
{
string legacyTopicsPath = GetLegacyTopicsFilePath();
string topicsFilePath = GetTopicsFilePath();
//If we have an old format topics file. Convert it to the new format!
if (File.Exists(legacyTopicsPath))
{
//Read old format
List<string> legacyTopics = new List<string>();
using (StreamReader reader = new StreamReader(legacyTopicsPath))
{
while (!reader.EndOfStream)
{
string? legacyTopic = reader.ReadLine();
if (!string.IsNullOrWhiteSpace(legacyTopic)) legacyTopics.Add(legacyTopic);
}
}
//Assemble new format
List<SubscribedTopic> newTopics = legacyTopics.Select(lt => new SubscribedTopic(lt, "https://ntfy.sh", null, null)).ToList();
string newFormatSerialised = JsonConvert.SerializeObject(newTopics, Formatting.Indented);
//Write new format
File.WriteAllText(topicsFilePath, newFormatSerialised);
//Delete old format
File.Delete(legacyTopicsPath);
}
//Check if we have any topics file on disk to load
if (!File.Exists(topicsFilePath)) return;
//We have a topics file. Load it!
string topicsSerialised = File.ReadAllText(topicsFilePath);
//Check if the file is empty
if (string.IsNullOrWhiteSpace(topicsSerialised))
{
//The file is empty. May as well remove it and consider it nonexistent
File.Delete(topicsFilePath);
return;
}
//Deserialise the topics
List<SubscribedTopic>? topics = JsonConvert.DeserializeObject<List<SubscribedTopic>>(topicsSerialised);
if (topics is null)
{
//TODO Deserialise error!
return;
}
//Convert the reconnection values to ints
int reconnectAttempts = Convert.ToInt32(Math.Ceiling(Program.Settings.ReconnectAttempts));
int reconnectAttemptDelay = Convert.ToInt32(Math.Ceiling(Program.Settings.ReconnectAttemptDelay));
//Load them in
foreach (SubscribedTopic topic in topics)
{
string[] parts = topic.ServerUrl.Split("://", 2);
switch (parts[0].ToLower())
{
case "ws":
case "wss":
_notificationListener.SubscribeToTopicUsingWebsocket($"{topic.TopicId}@{topic.ServerUrl}", topic.TopicId, topic.ServerUrl, topic.Username, topic.Password, reconnectAttempts, reconnectAttemptDelay);
break;
case "http":
case "https":
_notificationListener.SubscribeToTopicUsingLongHttpJson($"{topic.TopicId}@{topic.ServerUrl}", topic.TopicId, topic.ServerUrl, topic.Username, topic.Password, reconnectAttempts, reconnectAttemptDelay);
break;
default:
continue;
}
notificationTopics.Items.Add($"{topic.TopicId}@{topic.ServerUrl}");
}
}
private SettingsModel GetDefaultSettings() => new()
{
Revision = 1,
Timeout = 5,
ReconnectAttempts = 10,
ReconnectAttemptDelay = 3
};
private void MergeSettingsRevisions(SettingsModel older, SettingsModel newer)
{
//Apply settings introduced in Revision 1
if (older.Revision < 1)
{
older.ReconnectAttempts = newer.ReconnectAttempts;
older.ReconnectAttemptDelay = newer.ReconnectAttemptDelay;
}
//Update the revision
older.Revision = newer.Revision;
}
private void LoadSettings()
{
string settingsFilePath = GetSettingsFilePath();
SettingsModel defaultSettings = GetDefaultSettings();
//Check if we have any settings file on disk to load. If we don't, initialise defaults
if (!File.Exists(settingsFilePath))
{
Program.Settings = defaultSettings;
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 = defaultSettings;
SaveSettingsToFile();
return;
}
//Deserialise the settings
SettingsModel? settings = JsonConvert.DeserializeObject<SettingsModel?>(settingsSerialised);
//Check if the deserialise succeeded. If it didn't, initialise default settings
if (settings is null)
{
Program.Settings = defaultSettings;
SaveSettingsToFile();
return;
}
Program.Settings = settings;
//Check the settings revision. If it is older than the current latest revision, apply the settings defaults missing from previous revision
if (Program.Settings.Revision < defaultSettings.ReconnectAttempts)
{
MergeSettingsRevisions(Program.Settings, defaultSettings);
SaveSettingsToFile();
}
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
notifyIcon.Dispose();
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
// Let it close
if (_trueExit) return;
if (e.CloseReason != CloseReason.UserClosing) return;
Visible = false;
e.Cancel = true;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
_trueExit = true;
Close();
}
private void ntfyshWebsiteToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start(new ProcessStartInfo("https://ntfy.sh/")
{
UseShellExecute = true
});
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
using AboutBox d = new AboutBox();
d.ShowDialog();
}
private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
{
_trueExit = true;
Close();
}
}
}

View File

@@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
@@ -124,6 +64,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
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAAAiklE
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
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAAAgUlE
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,31 +261,34 @@
/////8AA////////wAD////////AAA==
</value>
</data>
<data name="showControlWindowToolStripMenuItem.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
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
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAAAgUlE
QVQ4T2OgGjjOLq4AZeIFWNWBBI9yib06zC3uABXCCkDyIHVYDTnMI2pzhEvs5VFucSeoEAo4wiNii08e
DHAZQshwFICumCTNMADyK1gTl2gJiCYUNlgBSDPQ1v8gGipEPKDIBRSFAa6oIsoQQvGM1xCqpESsglgA
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="settingsToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
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=
</value>
</data>
<data name="ntfyshWebsiteToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA7DAAAOwwHHb6hkAAABDElE
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAABDElE
QVQ4T91RO3bCQAzUy3uhChdJnTVlCj5FcMsZsF1jmy4XycPrzl6fBLgEXMFp4srRiF0wcaBP5j0VI2m0
4zH9EwSq8gPP7ELPNFxtpxrbn9vVPkSsykOkqvHi2QxsWwAevhQTzG8eCb1yD7Glv2I5MlM+sLX0GqEq
6+jVPFl6QZz7lOgdJVnzuMq/sEepbsGln2YnR3AAm0IcIE71geJsTO9mcOWAOa3zicxxxGWApXMGabaH
@@ -338,20 +299,11 @@
<data name="aboutToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAwUlE
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAAAwUlE
QVQ4T2OgClBUVHwAxP9JxA+g2sEG/JeTk5MkBYP0QLVTwQAFBYXHIAFSMEgPVDvYBfulpKSEScEgPVDt
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

@@ -1,154 +0,0 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
namespace ntfysh_client
{
class NotificationListener : IDisposable
{
private HttpClient httpClient;
private bool disposedValue;
public Dictionary<string, StreamReader> subscribedTopics;
public delegate void NotificationReceiveHandler(object sender, NotificationReceiveEventArgs e);
public event NotificationReceiveHandler OnNotificationReceive;
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)
{
HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Get, $"https://ntfy.sh/{HttpUtility.UrlEncode(topicId)}/json");
using (var response = await httpClient.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead))
{
using (var body = await response.Content.ReadAsStreamAsync())
{
using (StreamReader reader = new StreamReader(body))
{
subscribedTopics.Add(topicId, reader);
try
{
// The loop will be broken when this stream is closed
while (true)
{
var line = await reader.ReadLineAsync();
Debug.WriteLine(line);
NtfyEventObject nev = JsonConvert.DeserializeObject<NtfyEventObject>(line);
if (nev.Event == "message")
{
if (OnNotificationReceive != null)
{
var evArgs = new NotificationReceiveEventArgs(nev.Title, nev.Message);
OnNotificationReceive(this, evArgs);
}
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
// If the topic is still registered, then that stream wasn't mean to be closed (maybe network failure?)
// Restart it
if (subscribedTopics.ContainsKey(topicId))
{
SubscribeToTopic(topicId);
}
}
}
}
}
}
public void RemoveTopic(string topicId)
{
Debug.WriteLine($"Removing topic {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();
}
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
disposedValue = true;
}
}
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~NotificationListener()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
public class NotificationReceiveEventArgs : EventArgs
{
public string Title { get; private set; }
public string Message { get; private set; }
public NotificationReceiveEventArgs(string title, string message)
{
Title = title;
Message = message;
}
}
public class NtfyEventObject
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("time")]
public Int64 Time { get; set; }
[JsonProperty("event")]
public string Event { get; set; }
[JsonProperty("topic")]
public string Topic { get; set; }
[JsonProperty("message")]
public string Message { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
}
}

View File

@@ -0,0 +1,354 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json;
namespace ntfysh_client.Notifications
{
public class NotificationListener
{
public readonly Dictionary<string, SubscribedTopic?> SubscribedTopicsByUnique = new();
public delegate void NotificationReceiveHandler(NotificationListener sender, NotificationReceiveEventArgs e);
public event NotificationReceiveHandler? OnNotificationReceive;
public delegate void ConnectionErrorHandler(NotificationListener sender, SubscribedTopic topic);
public event ConnectionErrorHandler? OnConnectionMultiAttemptFailure;
public event ConnectionErrorHandler? OnConnectionCredentialsFailure;
public NotificationListener()
{
ServicePointManager.DefaultConnectionLimit = 100;
}
private async Task ListenToTopicWithHttpLongJsonAsync(HttpRequestMessage message, SubscribedTopic topic, int reconnectAttempts = 10, int reconnectAttemptDelay = 3, CancellationToken cancellationToken = default)
{
int connectionAttempts = 0;
while (!cancellationToken.IsCancellationRequested)
{
//See if we have exceeded maximum attempts
if (reconnectAttempts != 0 && connectionAttempts >= reconnectAttempts)
{
//<reconnectAttempts> connection failures (1 initial + (<reconnectAttempts> - 1) reattempts)! Do not retry
OnConnectionMultiAttemptFailure?.Invoke(this, topic);
return;
}
try
{
//Establish connection
using HttpClient client = new();
client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite); //This will not prevent us from failing to connect, luckily
using HttpResponseMessage response = await client.SendAsync(message, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
await using Stream body = await response.Content.ReadAsStreamAsync(cancellationToken);
//Ensure successful connect
response.EnsureSuccessStatusCode();
//Reset connection attempts after a successful connect
connectionAttempts = 0;
//Begin listening
StringBuilder mainBuffer = new();
while (!cancellationToken.IsCancellationRequested)
{
//Read as much as possible
byte[] buffer = new byte[8192];
int readBytes = await body.ReadAsync(buffer, 0, buffer.Length, cancellationToken);
//Append it to our main buffer
mainBuffer.Append(Encoding.UTF8.GetString(buffer, 0, readBytes));
List<string> lines = mainBuffer.ToString().Split('\n').ToList();
//If we have not yet received a full line, meaning theres only 1 part, go back to reading
if (lines.Count <= 1) continue;
//We now have at least 1 line! Count how many full lines. There will always be a partial line at the end, even if that partial line is empty
//Separate the partial line from the full lines
int partialLineIndex = lines.Count - 1;
string partialLine = lines[partialLineIndex];
lines.RemoveAt(partialLineIndex);
//Process the full lines
foreach (string line in lines) ProcessMessage(topic, line);
//Write back the partial line
mainBuffer.Clear();
mainBuffer.Append(partialLine);
}
}
catch (HttpRequestException hre)
{
if (hre.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)
{
//Our credentials either aren't present when they need to be or are invalid
//Credential Failure! Do not retry
OnConnectionCredentialsFailure?.Invoke(this, topic);
return;
}
#if DEBUG
Debug.WriteLine(hre);
#endif
//We will not hit the finally block which will increment the connection failure counter and attempt a reconnect if applicable
}
catch (Exception e)
{
#if DEBUG
Debug.WriteLine(e);
#endif
//We will not hit the finally block which will increment the connection failure counter and attempt a reconnect if applicable
}
finally
{
//We land here if we fail to connect or our connection gets closed (and if we are canceling, but that gets ignored)
if (!cancellationToken.IsCancellationRequested)
{
//Not cancelling, legitimate connection failure or termination
if (reconnectAttempts == 0 || connectionAttempts != 0)
{
//On our first reconnect attempt, try instantly (unless we have infinite retries). On consecutive, wait <reconnectAttemptDelay> seconds before each attempt
await Task.Delay(TimeSpan.FromSeconds(reconnectAttemptDelay), cancellationToken);
}
//Increment attempts
connectionAttempts++;
//Proceed to reattempt
}
}
}
}
private async Task ListenToTopicWithWebsocketAsync(Uri uri, string? credentials, SubscribedTopic topic, int reconnectAttempts = 10, int reconnectAttemptDelay = 3, CancellationToken cancellationToken = default)
{
int connectionAttempts = 0;
while (!cancellationToken.IsCancellationRequested)
{
//See if we have exceeded maximum attempts
if (reconnectAttempts != 0 && connectionAttempts >= reconnectAttempts)
{
//<reconnectAttempts> connection failures (1 initial + (<reconnectAttempts> - 1) reattempts)! Do not retry
OnConnectionMultiAttemptFailure?.Invoke(this, topic);
return;
}
try
{
//Establish connection
using ClientWebSocket socket = new();
if (!string.IsNullOrWhiteSpace(credentials)) socket.Options.SetRequestHeader("Authorization", "Basic " + credentials);
await socket.ConnectAsync(uri, cancellationToken);
//Reset connection attempts after a successful connect
connectionAttempts = 0;
//Begin listening
StringBuilder mainBuffer = new();
while (!cancellationToken.IsCancellationRequested)
{
//Read as much as possible
byte[] buffer = new byte[8192];
WebSocketReceiveResult? result = await socket.ReceiveAsync(new ArraySegment<byte>(buffer), cancellationToken);
//Append it to our main buffer
mainBuffer.Append(Encoding.UTF8.GetString(buffer, 0, result.Count));
List<string> lines = mainBuffer.ToString().Split('\n').ToList();
//If we have not yet received a full line, meaning theres only 1 part, go back to reading
if (lines.Count <= 1) continue;
//We now have at least 1 line! Count how many full lines. There will always be a partial line at the end, even if that partial line is empty
//Separate the partial line from the full lines
int partialLineIndex = lines.Count - 1;
string partialLine = lines[partialLineIndex];
lines.RemoveAt(partialLineIndex);
//Process the full lines
foreach (string line in lines) ProcessMessage(topic, line);
//Write back the partial line
mainBuffer.Clear();
mainBuffer.Append(partialLine);
}
}
catch (WebSocketException wse)
{
if (wse.WebSocketErrorCode is WebSocketError.NotAWebSocket)
{
//We haven't achieved a connection with a websocket. TODO Seems ntfy doesn't report unauthorised properly, and responds 200
//Credential Failure! Do not retry
OnConnectionCredentialsFailure?.Invoke(this, topic);
return;
}
#if DEBUG
Debug.WriteLine(wse);
#endif
//We will not hit the finally block which will increment the connection failure counter and attempt a reconnect if applicable
}
catch (Exception e)
{
#if DEBUG
Debug.WriteLine(e);
#endif
//We will not hit the finally block which will increment the connection failure counter and attempt a reconnect if applicable
}
finally
{
//We land here if we fail to connect or our connection gets closed (and if we are canceling, but that gets ignored)
if (!cancellationToken.IsCancellationRequested)
{
//Not cancelling, legitimate connection failure or termination
if (reconnectAttempts == 0 || connectionAttempts != 0)
{
//On our first reconnect attempt, try instantly (unless we have infinite retries). On consecutive, wait <reconnectAttemptDelay> seconds before each attempt
await Task.Delay(TimeSpan.FromSeconds(reconnectAttemptDelay), cancellationToken);
}
//Increment attempts
connectionAttempts++;
//Proceed to reattempt
}
}
}
}
private void ProcessMessage(SubscribedTopic topic, string message)
{
#if DEBUG
Debug.WriteLine(message);
#endif
NtfyEvent? evt = JsonConvert.DeserializeObject<NtfyEvent>(message);
//If we hit this, ntfy sent us an invalid message
if (evt is null) return;
if (evt.Event == "message")
{
OnNotificationReceive?.Invoke(this, new NotificationReceiveEventArgs(topic, evt.Title ?? "", evt.Message, evt.Priority ?? NotificationPriority.Default));
}
}
public void SubscribeToTopicUsingLongHttpJson(string unique, string topicId, string serverUrl, string? username, string? password, int reconnectAttempts, int reconnectAttemptDelay)
{
if (SubscribedTopicsByUnique.ContainsKey(unique)) throw new ArgumentException("A topic with this unique already exists", nameof(unique));
if (string.IsNullOrWhiteSpace(username)) username = null;
if (string.IsNullOrWhiteSpace(password)) password = null;
if (reconnectAttempts < 0) throw new ArgumentException("Reconnect attempts must be 0 or more", nameof(reconnectAttempts));
if (reconnectAttemptDelay < 0) throw new ArgumentException("Reconnect attempt delay; must be 0 or more", nameof(reconnectAttemptDelay));
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, $"{serverUrl}/{HttpUtility.UrlEncode(topicId)}/json");
if (username is not null && password is not null)
{
byte[] boundCredentialsBytes = Encoding.UTF8.GetBytes($"{username}:{password}");
message.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(boundCredentialsBytes));
}
SubscribedTopic newTopic = new(topicId, serverUrl, username, password);
CancellationTokenSource listenCanceller = new();
Task listenTask = ListenToTopicWithHttpLongJsonAsync(message, newTopic, reconnectAttempts, reconnectAttemptDelay, listenCanceller.Token);
newTopic.SetAssociatedRunner(listenTask, listenCanceller);
SubscribedTopicsByUnique.Add(unique, newTopic);
}
public void SubscribeToTopicUsingWebsocket(string unique, string topicId, string serverUrl, string? username, string? password, int reconnectAttempts, int reconnectAttemptDelay)
{
if (SubscribedTopicsByUnique.ContainsKey(unique)) throw new ArgumentException("A topic with this unique already exists", nameof(unique));
if (string.IsNullOrWhiteSpace(username)) username = null;
if (string.IsNullOrWhiteSpace(password)) password = null;
if (reconnectAttempts < 0) throw new ArgumentException("Reconnect attempts must be 0 or more", nameof(reconnectAttempts));
if (reconnectAttemptDelay < 0) throw new ArgumentException("Reconnect attempt delay; must be 0 or more", nameof(reconnectAttemptDelay));
SubscribedTopic newTopic = new(topicId, serverUrl, username, password);
string? credentials = null;
if (username is not null && password is not null)
{
byte[] boundCredentialsBytes = Encoding.UTF8.GetBytes($"{username}:{password}");
credentials = Convert.ToBase64String(boundCredentialsBytes);
}
CancellationTokenSource listenCanceller = new();
Task listenTask = ListenToTopicWithWebsocketAsync(new Uri($"{serverUrl}/{HttpUtility.UrlEncode(topicId)}/ws"), credentials, newTopic, reconnectAttempts, reconnectAttemptDelay, listenCanceller.Token);
newTopic.SetAssociatedRunner(listenTask, listenCanceller);
SubscribedTopicsByUnique.Add(unique, newTopic);
}
public async Task UnsubscribeFromTopicAsync(string topicUniqueString)
{
#if DEBUG
Debug.WriteLine($"Removing topic {topicUniqueString}");
#endif
// ReSharper disable once InlineOutVariableDeclaration - Needed to avoid nullable warning
SubscribedTopic topic;
//Topic isn't even subscribed, ignore
if (!SubscribedTopicsByUnique.TryGetValue(topicUniqueString, out topic!)) return;
//Cancel and dispose the task runner
topic.RunnerCanceller?.Cancel();
//Wait for the task runner to shut down
try
{
if (topic.Runner is not null) await topic.Runner;
}
catch (Exception)
{
// ignored
}
//Dispose task
topic.Runner?.Dispose();
//Remove the old topic
SubscribedTopicsByUnique.Remove(topicUniqueString);
}
}
}

View File

@@ -0,0 +1,11 @@
namespace ntfysh_client.Notifications
{
public enum NotificationPriority
{
Min = 1,
Low = 2,
Default = 3,
High = 4,
Max = 5
}
}

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,28 @@
using Newtonsoft.Json;
namespace ntfysh_client.Notifications
{
public class NtfyEvent
{
[JsonProperty("id")]
public string Id { get; set; } = null!;
[JsonProperty("time")]
public long Time { get; set; }
[JsonProperty("event")]
public string Event { get; set; } = null!;
[JsonProperty("topic")]
public string Topic { get; set; } = null!;
[JsonProperty("message")]
public string Message { get; set; } = null!;
[JsonProperty("title")]
public string? Title { get; set; }
[JsonProperty("priority")]
public NotificationPriority? Priority { get; set; }
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace ntfysh_client.Notifications
{
public class SubscribedTopic
{
public SubscribedTopic(string topicId, string serverUrl, string? username, string? password)
{
TopicId = topicId;
ServerUrl = serverUrl;
Username = username;
Password = password;
}
public void SetAssociatedRunner(Task runner, CancellationTokenSource runnerCanceller)
{
if (Runner is not null || RunnerCanceller is not null) throw new InvalidOperationException("Runner already associated");
Runner = runner;
RunnerCanceller = runnerCanceller;
}
public string TopicId { get; }
public string ServerUrl { get; }
public string? Username { get; }
public string? Password { get; }
[JsonIgnore]
public Task? Runner { get; private set; }
[JsonIgnore]
public CancellationTokenSource? RunnerCanceller { get; private set; }
}
}

View File

@@ -1,22 +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();
public static SettingsModel Settings { get; set; } = null!;
/// <summary>
/// The main entry point for the application.
/// </summary>
[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 Form1());
Application.Run(new MainForm(NotificationListener, startInTray));
}
}
}

View File

@@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ntfy.sh")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ntfy.sh")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5a18d152-d620-43fe-b844-def30cfa50ef")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -1,63 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ntfysh_client.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ntfysh_client.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@@ -1,26 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ntfysh_client.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@@ -1,7 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

175
ntfysh_client/SettingsDialog.Designer.cs generated Normal file
View File

@@ -0,0 +1,175 @@

namespace ntfysh_client
{
partial class SettingsDialog
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
buttonPanel = new System.Windows.Forms.Panel();
cancelButton = new System.Windows.Forms.Button();
saveButton = new System.Windows.Forms.Button();
timeoutLabel = new System.Windows.Forms.Label();
timeout = new System.Windows.Forms.NumericUpDown();
reconnectAttempts = new System.Windows.Forms.NumericUpDown();
reconnectAttemptsLabel = new System.Windows.Forms.Label();
reconnectAttemptDelay = new System.Windows.Forms.NumericUpDown();
reconnectAttemptDelayLabel = new System.Windows.Forms.Label();
buttonPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)timeout).BeginInit();
((System.ComponentModel.ISupportInitialize)reconnectAttempts).BeginInit();
((System.ComponentModel.ISupportInitialize)reconnectAttemptDelay).BeginInit();
SuspendLayout();
//
// buttonPanel
//
buttonPanel.BackColor = System.Drawing.SystemColors.Control;
buttonPanel.Controls.Add(cancelButton);
buttonPanel.Controls.Add(saveButton);
buttonPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
buttonPanel.Location = new System.Drawing.Point(0, 150);
buttonPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
buttonPanel.Name = "buttonPanel";
buttonPanel.Size = new System.Drawing.Size(531, 51);
buttonPanel.TabIndex = 0;
//
// cancelButton
//
cancelButton.Location = new System.Drawing.Point(363, 16);
cancelButton.Name = "cancelButton";
cancelButton.Size = new System.Drawing.Size(75, 23);
cancelButton.TabIndex = 2;
cancelButton.Text = "Cancel";
cancelButton.UseVisualStyleBackColor = true;
cancelButton.Click += cancelButton_Click;
//
// saveButton
//
saveButton.Location = new System.Drawing.Point(444, 16);
saveButton.Name = "saveButton";
saveButton.Size = new System.Drawing.Size(75, 23);
saveButton.TabIndex = 1;
saveButton.Text = "Save";
saveButton.UseVisualStyleBackColor = true;
saveButton.Click += saveButton_Click;
//
// timeoutLabel
//
timeoutLabel.AutoSize = true;
timeoutLabel.Location = new System.Drawing.Point(13, 9);
timeoutLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
timeoutLabel.Name = "timeoutLabel";
timeoutLabel.Size = new System.Drawing.Size(488, 15);
timeoutLabel.TabIndex = 3;
timeoutLabel.Text = "Notification Toast Timeout (seconds, may be ignored by OS based on accessibility settings):";
//
// timeout
//
timeout.Location = new System.Drawing.Point(13, 28);
timeout.Maximum = new decimal(new int[] { -1981284353, -1966660860, 0, 0 });
timeout.Name = "timeout";
timeout.Size = new System.Drawing.Size(506, 23);
timeout.TabIndex = 4;
//
// reconnectAttempts
//
reconnectAttempts.Location = new System.Drawing.Point(12, 73);
reconnectAttempts.Maximum = new decimal(new int[] { -1981284353, -1966660860, 0, 0 });
reconnectAttempts.Name = "reconnectAttempts";
reconnectAttempts.Size = new System.Drawing.Size(506, 23);
reconnectAttempts.TabIndex = 6;
//
// reconnectAttemptsLabel
//
reconnectAttemptsLabel.AutoSize = true;
reconnectAttemptsLabel.Location = new System.Drawing.Point(12, 54);
reconnectAttemptsLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
reconnectAttemptsLabel.Name = "reconnectAttemptsLabel";
reconnectAttemptsLabel.Size = new System.Drawing.Size(198, 15);
reconnectAttemptsLabel.TabIndex = 5;
reconnectAttemptsLabel.Text = "Maximum reconnect retry attempts (requires restart):";
//
// reconnectAttemptDelay
//
reconnectAttemptDelay.Location = new System.Drawing.Point(12, 118);
reconnectAttemptDelay.Maximum = new decimal(new int[] { -1981284353, -1966660860, 0, 0 });
reconnectAttemptDelay.Name = "reconnectAttemptDelay";
reconnectAttemptDelay.Size = new System.Drawing.Size(506, 23);
reconnectAttemptDelay.TabIndex = 8;
//
// reconnectAttemptDelayLabel
//
reconnectAttemptDelayLabel.AutoSize = true;
reconnectAttemptDelayLabel.Location = new System.Drawing.Point(12, 99);
reconnectAttemptDelayLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
reconnectAttemptDelayLabel.Name = "reconnectAttemptDelayLabel";
reconnectAttemptDelayLabel.Size = new System.Drawing.Size(191, 15);
reconnectAttemptDelayLabel.TabIndex = 7;
reconnectAttemptDelayLabel.Text = "Delay between attempts (seconds, requires restart):";
//
// SettingsDialog
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
BackColor = System.Drawing.Color.White;
ClientSize = new System.Drawing.Size(531, 201);
Controls.Add(reconnectAttemptDelay);
Controls.Add(reconnectAttemptDelayLabel);
Controls.Add(reconnectAttempts);
Controls.Add(reconnectAttemptsLabel);
Controls.Add(timeout);
Controls.Add(timeoutLabel);
Controls.Add(buttonPanel);
FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
MaximizeBox = false;
MinimizeBox = false;
Name = "SettingsDialog";
ShowIcon = false;
ShowInTaskbar = false;
StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
Text = "Settings";
buttonPanel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)timeout).EndInit();
((System.ComponentModel.ISupportInitialize)reconnectAttempts).EndInit();
((System.ComponentModel.ISupportInitialize)reconnectAttemptDelay).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private System.Windows.Forms.Panel buttonPanel;
private System.Windows.Forms.Label timeoutLabel;
private System.Windows.Forms.NumericUpDown timeout;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Button saveButton;
private System.Windows.Forms.NumericUpDown reconnectAttempts;
private System.Windows.Forms.Label reconnectAttemptsLabel;
private System.Windows.Forms.NumericUpDown reconnectAttemptDelay;
private System.Windows.Forms.Label reconnectAttemptDelayLabel;
}
}

View File

@@ -0,0 +1,41 @@
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 decimal ReconnectAttempts
{
get => reconnectAttempts.Value;
set => reconnectAttempts.Value = value;
}
public decimal ReconnectAttemptDelay
{
get => reconnectAttemptDelay.Value;
set => reconnectAttemptDelay.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;
}
}
}

View File

@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
@@ -26,40 +26,41 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
@@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
@@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
@@ -109,9 +112,9 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,10 @@
namespace ntfysh_client
{
public class SettingsModel
{
public uint Revision { get; set; }
public decimal Timeout { get; set; }
public decimal ReconnectAttempts { get; set; }
public decimal ReconnectAttemptDelay { get; set; }
}
}

View File

@@ -30,10 +30,18 @@ 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.label5 = new System.Windows.Forms.Label();
this.connectionType = new System.Windows.Forms.ComboBox();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
@@ -43,64 +51,164 @@ 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, 244);
this.panel1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
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);
this.panel1.Size = new System.Drawing.Size(346, 51);
this.panel1.TabIndex = 8;
//
// button2
//
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button2.Location = new System.Drawing.Point(131, 11);
this.button2.Margin = new System.Windows.Forms.Padding(10, 10, 3, 10);
this.button2.Location = new System.Drawing.Point(153, 13);
this.button2.Margin = new System.Windows.Forms.Padding(12, 12, 4, 12);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 1;
this.button2.Size = new System.Drawing.Size(88, 27);
this.button2.TabIndex = 7;
this.button2.Text = "Cancel";
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(247, 13);
this.button1.Margin = new System.Windows.Forms.Padding(4, 12, 12, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(88, 27);
this.button1.TabIndex = 6;
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(14, 10);
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(51, 13);
this.label1.Size = new System.Drawing.Size(52, 15);
this.label1.TabIndex = 1;
this.label1.Text = "Topic ID:";
//
// 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(14, 29);
this.topicId.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.topicId.Name = "topicId";
this.topicId.Size = new System.Drawing.Size(273, 20);
this.topicId.TabIndex = 0;
this.topicId.Size = new System.Drawing.Size(318, 23);
this.topicId.TabIndex = 1;
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(14, 74);
this.serverUrl.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.serverUrl.Name = "serverUrl";
this.serverUrl.Size = new System.Drawing.Size(318, 23);
this.serverUrl.TabIndex = 2;
this.serverUrl.Text = "wss://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(12, 55);
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(66, 15);
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(14, 119);
this.username.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.username.Name = "username";
this.username.Size = new System.Drawing.Size(318, 23);
this.username.TabIndex = 3;
this.username.KeyDown += new System.Windows.Forms.KeyEventHandler(this.username_KeyDown);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 100);
this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(63, 15);
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(14, 164);
this.password.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.password.Name = "password";
this.password.Size = new System.Drawing.Size(318, 23);
this.password.TabIndex = 4;
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(12, 145);
this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(60, 15);
this.label4.TabIndex = 7;
this.label4.Text = "Password:";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(12, 190);
this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(99, 15);
this.label5.TabIndex = 9;
this.label5.Text = "Connection Type:";
//
// connectionType
//
this.connectionType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.connectionType.FormattingEnabled = true;
this.connectionType.Items.AddRange(new object[] {
"Websockets (Recommended)",
"Long HTTP JSON (Robust)"});
this.connectionType.Location = new System.Drawing.Point(14, 208);
this.connectionType.Name = "connectionType";
this.connectionType.Size = new System.Drawing.Size(318, 23);
this.connectionType.TabIndex = 5;
this.connectionType.TextChanged += new System.EventHandler(this.connectionType_TextChanged);
//
// SubscribeDialog
//
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(297, 125);
this.ClientSize = new System.Drawing.Size(346, 295);
this.Controls.Add(this.connectionType);
this.Controls.Add(this.label5);
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);
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 = "SubscribeDialog";
@@ -108,12 +216,16 @@ namespace ntfysh_client
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Subscribe to new topic";
this.Load += new System.EventHandler(this.SubscribeDialog_Load);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.TextBox serverUrl;
private System.Windows.Forms.Label label2;
#endregion
private System.Windows.Forms.Panel panel1;
@@ -121,5 +233,11 @@ 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;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ComboBox connectionType;
}
}

View File

@@ -1,25 +1,121 @@
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
{
public partial class SubscribeDialog : Form
{
public SubscribeDialog()
private readonly ListBox _notificationTopics;
public string TopicId => topicId.Text;
public string ServerUrl => serverUrl.Text;
public string Username => username.Text;
public string Password => password.Text;
public string Unique => $"{topicId.Text}@{serverUrl.Text}";
public bool UseWebsockets
{
get
{
switch (connectionType.Text)
{
case "Websockets (Recommended)":
return true;
case "Long HTTP JSON (Robust)":
return false;
default:
throw new InvalidOperationException();
}
}
}
public SubscribeDialog(ListBox notificationTopics)
{
_notificationTopics = notificationTopics;
InitializeComponent();
}
public string getTopicId()
private void SubscribeDialog_Load(object sender, EventArgs e)
{
return topicId.Text;
connectionType.SelectedIndex = 0;
}
private bool ReparseAddress()
{
//Separate schema and address
string[] parts = serverUrl.Text.Split("://", 2);
//Validate the basic formatting is correct
if (parts.Length != 2) return false;
//Take the schema aside for parsing
string schema = parts[0].ToLower();
//Ensure the schema is actually valid
switch (schema)
{
case "http":
case "https":
case "ws":
case "wss":
break;
default:
return false;
}
//Correct the schema based on connection type if required
if (UseWebsockets)
{
switch (schema)
{
case "http":
schema = "ws";
break;
case "https":
schema = "wss";
break;
case "ws":
case "wss":
break;
}
}
else
{
switch (schema)
{
case "ws":
schema = "http";
break;
case "wss":
schema = "https";
break;
case "http":
case "https":
break;
}
}
//Reconstruct the address
string finalAddress = schema + "://" + parts[1];
//Validate the address
if (!Uri.IsWellFormedUriString(finalAddress, UriKind.Absolute)) return false;
//Set the final address and OK it
serverUrl.Text = finalAddress;
return true;
}
private void button1_Click(object sender, EventArgs e)
@@ -32,6 +128,58 @@ namespace ntfysh_client
return;
}
if (serverUrl.Text.Length < 1)
{
MessageBox.Show("You must specify a server URL. The default is wss://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;
}
if (_notificationTopics.Items.Contains(Unique))
{
MessageBox.Show($"The specified topic '{topicId.Text}' on the server '{serverUrl.Text}' is already subscribed", "Topic already subscribed", MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = DialogResult.None;
username.Focus();
return;
}
try
{
if (!ReparseAddress())
{
MessageBox.Show($"The specified server URL is invalid. Accepted schemas are: http:// https:// ws:// wss://", "Invalid Server URL", MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = DialogResult.None;
connectionType.Focus();
return;
}
}
catch (InvalidOperationException)
{
MessageBox.Show($"The selected Connection Type '{connectionType.Text}' is invalid.", "Invalid Connection Type", MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = DialogResult.None;
connectionType.Focus();
return;
}
DialogResult = DialogResult.OK;
}
@@ -48,5 +196,37 @@ 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;
}
}
private void connectionType_TextChanged(object sender, EventArgs e)
{
ReparseAddress();
}
}
}

View File

@@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">

View File

@@ -1,114 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5A18D152-D620-43FE-B844-DEF30CFA50EF}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>ntfysh_client</RootNamespace>
<AssemblyName>ntfysh</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ApplicationIcon>NotificationHub.ico</ApplicationIcon>
<StartupObject>ntfysh_client.Program</StartupObject>
<AssemblyName>ntfy.sh</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
<ItemGroup>
<Compile Include="AboutBox.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="AboutBox.Designer.cs">
<DependentUpon>AboutBox.cs</DependentUpon>
</Compile>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="NotificationListener.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SubscribeDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="SubscribeDialog.Designer.cs">
<DependentUpon>SubscribeDialog.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="AboutBox.resx">
<DependentUpon>AboutBox.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="SubscribeDialog.resx">
<DependentUpon>SubscribeDialog.cs</DependentUpon>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="NotificationHub.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
</packages>