mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 12:46:47 +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 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)
|
||||
|
||||
Reference in New Issue
Block a user