From e9f291f6f70f9e4fcb62cf52f629fabad3a8d895 Mon Sep 17 00:00:00 2001 From: Martin Barker Date: Sat, 28 Jan 2023 15:17:50 +0000 Subject: [PATCH] Updates to finally secure the Twitch codes so i don't have to keep adding them for compile and removing them for Source Distribution. fixed a Bug in the notification system that ment dismiss did not work. --- .gitignore | 1 + Readme.md | 15 +++++++++++---- TwitchDesktopNotifications/Core/Notification.cs | 16 ++++++++++++---- .../Core/TwitchFetcher.cs | 17 ++++++----------- .../TwitchDesktopNotifications.csproj | 2 +- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 460f9b3..3e89407 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /TwitchDesktopNotifications/obj /.vs /TwitchDesktopNotifications/App.config +/TwitchDesktopNotifications/TwitchDetails.cs diff --git a/Readme.md b/Readme.md index bd40352..e0366d5 100644 --- a/Readme.md +++ b/Readme.md @@ -11,10 +11,17 @@ Want to contribute? Great! Project is built using Visual Studios 2022, -You need to create Application to obtain a ID and Secret on [Twitch Developer Console](https://dev.twitch.tv/console) replace lines 15 and 16 in TwitchFetcher.cs -```pwsh -TwitchClientID = ""; -TwitchClientSecret = ""; +You need to create Application to obtain a ID and Secret on [Twitch Developer Console](https://dev.twitch.tv/console) +Add a new C# Class to the project named `TwitchDetails.cs` add the following code with your ID and Secret +```cs +namespace TwitchDesktopNotifications +{ + static public class TwitchDetails + { + public static string TwitchClientID = ""; + public static string TwitchClientSecret = ""; + } +} ``` ### CommunityToolkit 8.0.0 Pre-release diff --git a/TwitchDesktopNotifications/Core/Notification.cs b/TwitchDesktopNotifications/Core/Notification.cs index cc33c0b..70935c0 100644 --- a/TwitchDesktopNotifications/Core/Notification.cs +++ b/TwitchDesktopNotifications/Core/Notification.cs @@ -22,10 +22,18 @@ namespace TwitchDesktopNotifications.Core try { - Process myProcess = new Process(); - myProcess.StartInfo.UseShellExecute = true; - myProcess.StartInfo.FileName = args["streamerUrl"]; - myProcess.Start(); + if ( + // action is defined and set to watch + ( args.Contains("action") && args["action"] == "watch" ) + || + // action is not defined so the user just generally clicked on the notification + !args.Contains("action") + ){ + Process myProcess = new Process(); + myProcess.StartInfo.UseShellExecute = true; + myProcess.StartInfo.FileName = args["streamerUrl"]; + myProcess.Start(); + } }catch(Exception ex) { } }; } diff --git a/TwitchDesktopNotifications/Core/TwitchFetcher.cs b/TwitchDesktopNotifications/Core/TwitchFetcher.cs index 3b35e8d..4a3fd94 100644 --- a/TwitchDesktopNotifications/Core/TwitchFetcher.cs +++ b/TwitchDesktopNotifications/Core/TwitchFetcher.cs @@ -12,15 +12,10 @@ namespace TwitchDesktopNotifications.Core internal class TwitchFetcher { private TwitchFetcher() { - TwitchClientID = ""; - TwitchClientSecret = ""; } public static TwitchFetcher instance { get; private set; } - string TwitchClientID = ""; - string TwitchClientSecret = ""; - List currentlyLive = null; public string guid { get; private set; } @@ -60,7 +55,7 @@ namespace TwitchDesktopNotifications.Core WebRequest request = WebRequest.Create("https://api.twitch.tv/" + endpoint); request.Method = "GET"; request.Headers[HttpRequestHeader.Authorization] = String.Format("Bearer {0}", DataStore.GetInstance().Store.Authentication.AccessToken); - request.Headers["Client-ID"] = TwitchClientID; + request.Headers["Client-ID"] = TwitchDetails.TwitchClientID; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); @@ -139,8 +134,8 @@ namespace TwitchDesktopNotifications.Core { Dictionary postData = new Dictionary(); - postData["client_id"] = TwitchClientID; - postData["client_secret"] = TwitchClientSecret; + postData["client_id"] = TwitchDetails.TwitchClientID; + postData["client_secret"] = TwitchDetails.TwitchClientSecret; postData["grant_type"] = "refresh_token"; postData["refresh_token"] = DataStore.GetInstance().Store.Authentication.RefreshToken; @@ -173,7 +168,7 @@ namespace TwitchDesktopNotifications.Core WebServer.GetInstance().TwitchState = guid; Process myProcess = new Process(); myProcess.StartInfo.UseShellExecute = true; - myProcess.StartInfo.FileName = String.Format("https://id.twitch.tv/oauth2/authorize?&redirect_uri=http://localhost:32584/twitchRedirect&scope=user:read:subscriptions%20user:read:follows%20user:read:email%20openid&response_type=code&state={0}&nonce={1}&client_id={2}", guid, guid, TwitchClientID); + myProcess.StartInfo.FileName = String.Format("https://id.twitch.tv/oauth2/authorize?&redirect_uri=http://localhost:32584/twitchRedirect&scope=user:read:subscriptions%20user:read:follows%20user:read:email%20openid&response_type=code&state={0}&nonce={1}&client_id={2}", guid, guid, TwitchDetails.TwitchClientID); myProcess.Start(); } @@ -181,8 +176,8 @@ namespace TwitchDesktopNotifications.Core { Dictionary postData = new Dictionary(); - postData["client_id"] = TwitchClientID; - postData["client_secret"] = TwitchClientSecret; + postData["client_id"] = TwitchDetails.TwitchClientID; + postData["client_secret"] = TwitchDetails.TwitchClientSecret; postData["grant_type"] = "authorization_code"; postData["redirect_uri"] = "http://localhost:32584/twitchRedirect"; postData["code"] = code; diff --git a/TwitchDesktopNotifications/TwitchDesktopNotifications.csproj b/TwitchDesktopNotifications/TwitchDesktopNotifications.csproj index a2bb1f0..a05b015 100644 --- a/TwitchDesktopNotifications/TwitchDesktopNotifications.csproj +++ b/TwitchDesktopNotifications/TwitchDesktopNotifications.csproj @@ -1,7 +1,7 @@  - Exe + WinExe net6.0-windows10.0.17763.0 enable enable