mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Refactoring FolderLink and URL plugin.
This commit is contained in:
@@ -1,29 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Security.Policy;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins
|
||||
{
|
||||
public class UrlPlugin : BaseSystemPlugin
|
||||
{
|
||||
const string pattern = @"^(http|https|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$";
|
||||
Regex reg = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
protected override List<Result> QueryInternal(Query query)
|
||||
{
|
||||
var raw = query.RawQuery;
|
||||
Uri uri;
|
||||
if (Uri.TryCreate(raw, UriKind.Absolute, out uri))
|
||||
if (reg.IsMatch(raw))
|
||||
{
|
||||
return new List<Result>
|
||||
{
|
||||
new Result
|
||||
{
|
||||
Title = raw,
|
||||
SubTitle = "Open the typed URL...",
|
||||
IcoPath = "Images/url1.png",
|
||||
SubTitle = "Open " + raw,
|
||||
IcoPath = "Images/url.png",
|
||||
Score = 8,
|
||||
Action = _ =>
|
||||
{
|
||||
Process.Start(uri.AbsoluteUri);
|
||||
return true;
|
||||
if (!raw.ToLower().StartsWith("http"))
|
||||
{
|
||||
raw = "http://" + raw;
|
||||
}
|
||||
try
|
||||
{
|
||||
Process.Start(raw);
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Could not open " + raw);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -38,7 +56,7 @@ namespace Wox.Plugin.SystemPlugins
|
||||
|
||||
public override string Name { get { return "URL handler"; } }
|
||||
public override string Description { get { return "Provide Opening the typed URL from Wox."; } }
|
||||
public override string IcoPath { get { return "Images/url2.png"; } }
|
||||
public override string IcoPath { get { return "Images/url.png"; } }
|
||||
|
||||
protected override void InitInternal(PluginInitContext context)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user