mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
[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:
@@ -39,6 +39,8 @@ namespace Microsoft.Plugin.Uri
|
|||||||
|
|
||||||
public string BrowserIconPath { get; set; }
|
public string BrowserIconPath { get; set; }
|
||||||
|
|
||||||
|
public string BrowserPath { get; set; }
|
||||||
|
|
||||||
public string DefaultIconPath { get; set; }
|
public string DefaultIconPath { get; set; }
|
||||||
|
|
||||||
public PluginInitContext Context { get; protected set; }
|
public PluginInitContext Context { get; protected set; }
|
||||||
@@ -56,6 +58,32 @@ namespace Microsoft.Plugin.Uri
|
|||||||
{
|
{
|
||||||
var results = new List<Result>();
|
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)
|
if (!string.IsNullOrEmpty(query?.Search)
|
||||||
&& _uriParser.TryParse(query.Search, out var uriResult)
|
&& _uriParser.TryParse(query.Search, out var uriResult)
|
||||||
&& _uriResolver.IsValidHost(uriResult))
|
&& _uriResolver.IsValidHost(uriResult))
|
||||||
@@ -87,6 +115,17 @@ namespace Microsoft.Plugin.Uri
|
|||||||
return results;
|
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)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
Context = context ?? throw new ArgumentNullException(nameof(context));
|
Context = context ?? throw new ArgumentNullException(nameof(context));
|
||||||
@@ -155,6 +194,7 @@ namespace Microsoft.Plugin.Uri
|
|||||||
BrowserIconPath = indexOfComma > 0
|
BrowserIconPath = indexOfComma > 0
|
||||||
? programLocation.Substring(0, indexOfComma)
|
? programLocation.Substring(0, indexOfComma)
|
||||||
: programLocation;
|
: programLocation;
|
||||||
|
BrowserPath = BrowserIconPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@@ -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>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Failed to open URL.
|
/// Looks up a localized string similar to Failed to open URL.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -88,7 +106,7 @@ namespace Microsoft.Plugin.Uri.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Open in browser.
|
/// Looks up a localized string similar to Open in default browser.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string Microsoft_plugin_uri_website {
|
public static string Microsoft_plugin_uri_website {
|
||||||
get {
|
get {
|
||||||
|
|||||||
@@ -117,6 +117,12 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</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">
|
<data name="Microsoft_plugin_uri_open_failed" xml:space="preserve">
|
||||||
<value>Failed to open URL</value>
|
<value>Failed to open URL</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -127,6 +133,6 @@
|
|||||||
<value>URI Handler</value>
|
<value>URI Handler</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Microsoft_plugin_uri_website" xml:space="preserve">
|
<data name="Microsoft_plugin_uri_website" xml:space="preserve">
|
||||||
<value>Open in browser</value>
|
<value>Open in default browser</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|||||||
Reference in New Issue
Block a user