From de9b7772e1924343684882f998955e85895933fd Mon Sep 17 00:00:00 2001 From: Lee Won Jun Date: Sat, 15 May 2021 01:55:57 +0900 Subject: [PATCH] [PT Run] Implement quick browser open in PT-run (#11260) * Implement quick broswer open in PT-run * Update src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Properties/Resources.resx Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> --- .../Plugins/Microsoft.Plugin.Uri/Main.cs | 40 +++++++++++++++++++ .../Properties/Resources.Designer.cs | 20 +++++++++- .../Properties/Resources.resx | 10 ++++- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Main.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Main.cs index 39688d3bce..a069b5b5c3 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Main.cs @@ -39,6 +39,8 @@ namespace Microsoft.Plugin.Uri public string BrowserIconPath { get; set; } + public string BrowserPath { get; set; } + public string DefaultIconPath { get; set; } public PluginInitContext Context { get; protected set; } @@ -56,6 +58,32 @@ namespace Microsoft.Plugin.Uri { var results = new List(); + if (IsActivationKeyword(query) + && IsDefaultBrowserSet()) + { + results.Add(new Result + { + Title = Properties.Resources.Microsoft_plugin_uri_default_browser, + SubTitle = BrowserPath, + IcoPath = _uriSettings.ShowBrowserIcon + ? BrowserIconPath + : DefaultIconPath, + Action = action => + { + if (!Helper.OpenInShell(BrowserPath)) + { + var title = $"Plugin: {Properties.Resources.Microsoft_plugin_uri_plugin_name}"; + var message = $"{Properties.Resources.Microsoft_plugin_default_browser_open_failed}: "; + Context.API.ShowMsg(title, message); + return false; + } + + return true; + }, + }); + return results; + } + if (!string.IsNullOrEmpty(query?.Search) && _uriParser.TryParse(query.Search, out var uriResult) && _uriResolver.IsValidHost(uriResult)) @@ -87,6 +115,17 @@ namespace Microsoft.Plugin.Uri return results; } + private static bool IsActivationKeyword(Query query) + { + return !string.IsNullOrEmpty(query?.ActionKeyword) + && query?.ActionKeyword == query?.RawQuery; + } + + private bool IsDefaultBrowserSet() + { + return !string.IsNullOrEmpty(BrowserPath); + } + public void Init(PluginInitContext context) { Context = context ?? throw new ArgumentNullException(nameof(context)); @@ -155,6 +194,7 @@ namespace Microsoft.Plugin.Uri BrowserIconPath = indexOfComma > 0 ? programLocation.Substring(0, indexOfComma) : programLocation; + BrowserPath = BrowserIconPath; } } catch (Exception e) diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Properties/Resources.Designer.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Properties/Resources.Designer.cs index 83bde72d74..71c6832a11 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Properties/Resources.Designer.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Properties/Resources.Designer.cs @@ -60,6 +60,24 @@ namespace Microsoft.Plugin.Uri.Properties { } } + /// + /// Looks up a localized string similar to Failed to open default browser. + /// + public static string Microsoft_plugin_default_browser_open_failed { + get { + return ResourceManager.GetString("Microsoft_plugin_default_browser_open_failed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Open Default Browser. + /// + public static string Microsoft_plugin_uri_default_browser { + get { + return ResourceManager.GetString("Microsoft_plugin_uri_default_browser", resourceCulture); + } + } + /// /// Looks up a localized string similar to Failed to open URL. /// @@ -88,7 +106,7 @@ namespace Microsoft.Plugin.Uri.Properties { } /// - /// Looks up a localized string similar to Open in browser. + /// Looks up a localized string similar to Open in default browser. /// public static string Microsoft_plugin_uri_website { get { diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Properties/Resources.resx b/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Properties/Resources.resx index 567a259c91..6ce700ddef 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Properties/Resources.resx +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Properties/Resources.resx @@ -117,6 +117,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Failed to open default browser + + + Open default browser + Failed to open URL @@ -127,6 +133,6 @@ URI Handler - Open in browser + Open in default browser - \ No newline at end of file +