1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-14 03:15:49 +02:00

Open TweetDuck guide links directly in the app

This commit is contained in:
chylex 2017-11-20 17:25:25 +01:00
parent 15bc6c1d73
commit b2f3b245b7
2 changed files with 30 additions and 3 deletions

View File

@ -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(),

View File

@ -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: