[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>
This commit is contained in:
Lee Won Jun 2021-05-15 01:55:57 +09:00 committed by GitHub
parent 319adcbd62
commit de9b7772e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 3 deletions

View file

@ -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<Result>();
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)

View file

@ -60,6 +60,24 @@ namespace Microsoft.Plugin.Uri.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Failed to open default browser.
/// </summary>
public static string Microsoft_plugin_default_browser_open_failed {
get {
return ResourceManager.GetString("Microsoft_plugin_default_browser_open_failed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Open Default Browser.
/// </summary>
public static string Microsoft_plugin_uri_default_browser {
get {
return ResourceManager.GetString("Microsoft_plugin_uri_default_browser", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Failed to open URL.
/// </summary>
@ -88,7 +106,7 @@ namespace Microsoft.Plugin.Uri.Properties {
}
/// <summary>
/// Looks up a localized string similar to Open in browser.
/// Looks up a localized string similar to Open in default browser.
/// </summary>
public static string Microsoft_plugin_uri_website {
get {

View file

@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Microsoft_plugin_default_browser_open_failed" xml:space="preserve">
<value>Failed to open default browser</value>
</data>
<data name="Microsoft_plugin_uri_default_browser" xml:space="preserve">
<value>Open default browser</value>
</data>
<data name="Microsoft_plugin_uri_open_failed" xml:space="preserve">
<value>Failed to open URL</value>
</data>
@ -127,6 +133,6 @@
<value>URI Handler</value>
</data>
<data name="Microsoft_plugin_uri_website" xml:space="preserve">
<value>Open in browser</value>
<value>Open in default browser</value>
</data>
</root>
</root>