PowerToys/Wox.Plugin.SystemPlugins/UrlPlugin.cs

65 lines
2.2 KiB
C#
Raw Normal View History

2014-05-24 16:29:56 +08:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
2014-07-19 10:12:11 +08:00
using System.IO;
using System.Security.Policy;
using System.Text.RegularExpressions;
using System.Windows;
2014-05-24 16:29:56 +08:00
namespace Wox.Plugin.SystemPlugins
{
public class UrlPlugin : BaseSystemPlugin
{
2014-07-19 10:12:11 +08:00
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);
2014-05-24 16:29:56 +08:00
protected override List<Result> QueryInternal(Query query)
{
var raw = query.RawQuery;
2014-07-19 10:12:11 +08:00
if (reg.IsMatch(raw))
2014-05-24 16:29:56 +08:00
{
return new List<Result>
{
new Result
{
Title = raw,
2014-07-19 10:12:11 +08:00
SubTitle = "Open " + raw,
IcoPath = "Images/url.png",
2014-05-24 16:29:56 +08:00
Score = 8,
Action = _ =>
{
2014-07-19 10:12:11 +08:00
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;
}
2014-05-24 16:29:56 +08:00
}
}
};
}
return new List<Result>(0);
}
public override string ID
{
get { return "0308FD86DE0A4DEE8D62B9B535370992"; }
}
2014-05-24 16:29:56 +08:00
public override string Name { get { return "URL handler"; } }
2014-06-30 21:31:13 +08:00
public override string Description { get { return "Provide Opening the typed URL from Wox."; } }
2014-07-19 10:12:11 +08:00
public override string IcoPath { get { return "Images/url.png"; } }
2014-05-24 16:29:56 +08:00
protected override void InitInternal(PluginInitContext context)
{
}
}
}