From b2f3b245b797caa5afdbdd7cb4795c0dbbc4d269 Mon Sep 17 00:00:00 2001 From: chylex <contact@chylex.com> Date: Mon, 20 Nov 2017 17:25:25 +0100 Subject: [PATCH] Open TweetDuck guide links directly in the app --- Core/Other/FormGuide.cs | 25 +++++++++++++++++++++++-- Core/Utils/BrowserUtils.cs | 8 +++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Core/Other/FormGuide.cs b/Core/Other/FormGuide.cs index e73eb81d..0964e386 100644 --- a/Core/Other/FormGuide.cs +++ b/Core/Other/FormGuide.cs @@ -8,14 +8,35 @@ using TweetDuck.Core.Handling.General; using TweetDuck.Core.Other.Analytics; using TweetDuck.Core.Utils; +using System.Text.RegularExpressions; namespace TweetDuck.Core.Other{ sealed partial class FormGuide : Form{ private const string GuideUrl = "https://tweetduck.chylex.com/guide/v2/"; + private const string GuidePathRegex = @"^guide(?:/v\d+)?(?:/(#.*))?"; + + public static bool CheckGuideUrl(string url, out string hash){ + if (!url.Contains("//tweetduck.chylex.com/guide")){ + hash = null; + return false; + } + + string path = url.Substring(url.IndexOf("/guide")+1); + Match match = Regex.Match(path, GuidePathRegex); + + if (match.Success){ + hash = match.Groups[1].Value; + return true; + } + else{ + hash = null; + return false; + } + } private readonly ChromiumWebBrowser browser; - public FormGuide(){ + public FormGuide(string hash = null){ InitializeComponent(); Text = Program.BrandName+" Guide"; @@ -29,7 +50,7 @@ public FormGuide(){ owner.TriggerAnalyticsEvent(AnalyticsFile.Event.OpenGuide); } - this.browser = new ChromiumWebBrowser(GuideUrl){ + this.browser = new ChromiumWebBrowser(GuideUrl+(hash ?? string.Empty)){ MenuHandler = new ContextMenuGuide(), JsDialogHandler = new JavaScriptDialogHandler(), LifeSpanHandler = new LifeSpanHandler(), diff --git a/Core/Utils/BrowserUtils.cs b/Core/Utils/BrowserUtils.cs index f5e1ece2..045d41b1 100644 --- a/Core/Utils/BrowserUtils.cs +++ b/Core/Utils/BrowserUtils.cs @@ -70,7 +70,13 @@ public static void OpenExternalBrowser(string url){ switch(CheckUrl(url)){ case UrlCheckResult.Fine: - WindowsUtils.OpenAssociatedProgram(url); + if (FormGuide.CheckGuideUrl(url, out string hash)){ + new FormGuide(hash).Show(); + } + else{ + WindowsUtils.OpenAssociatedProgram(url); + } + break; case UrlCheckResult.Tracking: