diff --git a/Plugins/winalfred.Plugin.V2ex/Images/app.ico b/Plugins/winalfred.Plugin.V2ex/Images/app.ico new file mode 100644 index 0000000000..b0c3435fc3 Binary files /dev/null and b/Plugins/winalfred.Plugin.V2ex/Images/app.ico differ diff --git a/Plugins/winalfred.Plugin.V2ex/main.py b/Plugins/winalfred.Plugin.V2ex/main.py new file mode 100644 index 0000000000..ef3a1a504d --- /dev/null +++ b/Plugins/winalfred.Plugin.V2ex/main.py @@ -0,0 +1,34 @@ +#encoding=utf8 + +from __future__ import unicode_literals +import requests +from bs4 import BeautifulSoup +import json +import webbrowser + +def safeSelectText(s,path): + return s.select(path)[0].text if len(s.select(path)) > 0 else "" + +def query(key): + r = requests.get('http://v2ex.com/?tab=all') + bs = BeautifulSoup(r.text) + results = [] + for i in bs.select(".box div.item"): + res = {} + title = safeSelectText(i,".item_title") + subTitle = safeSelectText(i,".fade") + url = "http://v2ex.com" + i.select(".item_title a")[0]["href"] + + res["Title"] = title + res["SubTitle"] = subTitle + res["ActionName"] = "openUrl" + res["IcoPath"] = "Images\\app.ico" + res["ActionPara"] = url + results.append(res) + return json.dumps(results) + +def openUrl(url): + webbrowser.open(url) + +if __name__ == "__main__": + print query("movie geo") diff --git a/Plugins/winalfred.Plugin.V2ex/plugin.ini b/Plugins/winalfred.Plugin.V2ex/plugin.ini new file mode 100644 index 0000000000..3ddc5588cb --- /dev/null +++ b/Plugins/winalfred.Plugin.V2ex/plugin.ini @@ -0,0 +1,8 @@ +[plugin] +ActionKeyword = v2ex +Name = WinAlfred.V2ex +Author = qianlifeng +Version = 0.1 +Language = python +Description = workflow for v2ex +ExecuteFile = main.py diff --git a/WinAlfred.WorkflowInstaller/MainWindow.xaml.cs b/WinAlfred.WorkflowInstaller/MainWindow.xaml.cs index 320d2aaa6c..87a1c968d3 100644 --- a/WinAlfred.WorkflowInstaller/MainWindow.xaml.cs +++ b/WinAlfred.WorkflowInstaller/MainWindow.xaml.cs @@ -111,7 +111,11 @@ namespace WinAlfred.WorkflowInstaller string winalfred = AppDomain.CurrentDomain.BaseDirectory + "WinAlfred.exe"; if (File.Exists(winalfred)) { - Process.Start(winalfred, "reloadWorkflows"); + ProcessStartInfo info = new ProcessStartInfo(winalfred, "reloadWorkflows") + { + UseShellExecute = true + }; + Process.Start(info); MessageBox.Show("You have installed workflow " + plugin.Name + " successfully."); } else diff --git a/WinAlfred/App.xaml.cs b/WinAlfred/App.xaml.cs index f89ff25428..0f4a78997a 100644 --- a/WinAlfred/App.xaml.cs +++ b/WinAlfred/App.xaml.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading; using System.Windows; using Microsoft.VisualBasic.ApplicationServices; +using WinAlfred.Commands; using StartupEventArgs = System.Windows.StartupEventArgs; namespace WinAlfred @@ -57,12 +58,14 @@ namespace WinAlfred base.OnStartup(e); window = new MainWindow(); - window.ShowApp(e.Args); + window.ShowApp(); + window.ParseArgs(e.Args); } - public void Activate(string[] commandLine) + public void Activate(string[] args) { - window.ShowApp(commandLine); + window.ShowApp(); + window.ParseArgs(args); } } } diff --git a/WinAlfred/MainWindow.xaml.cs b/WinAlfred/MainWindow.xaml.cs index 969305f6d4..6a627110a3 100644 --- a/WinAlfred/MainWindow.xaml.cs +++ b/WinAlfred/MainWindow.xaml.cs @@ -59,9 +59,9 @@ namespace WinAlfred private void InitialTray() { notifyIcon = new NotifyIcon { Text = "WinAlfred", Icon = Properties.Resources.app, Visible = true }; - notifyIcon.Click += (o, e) => ShowWinAlfred(null); + notifyIcon.Click += (o, e) => ShowWinAlfred(); System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open"); - open.Click += (o, e) => ShowWinAlfred(null); + open.Click += (o, e) => ShowWinAlfred(); System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit"); exit.Click += (o, e) => CloseApp(); System.Windows.Forms.MenuItem[] childen = { open, exit }; @@ -78,7 +78,7 @@ namespace WinAlfred { if (!IsVisible) { - ShowWinAlfred(null); + ShowWinAlfred(); } else { @@ -132,7 +132,15 @@ namespace WinAlfred Hide(); } - private void ShowWinAlfred(string[] args) + private void ShowWinAlfred() + { + Show(); + Activate(); + tbQuery.Focus(); + tbQuery.SelectAll(); + } + + public void ParseArgs(string[] args) { if (args != null && args.Length > 0) { @@ -147,15 +155,11 @@ namespace WinAlfred { string query = args[1]; tbQuery.Text = query; + tbQuery.SelectAll(); } break; } } - - Show(); - Activate(); - tbQuery.Focus(); - tbQuery.SelectAll(); } private void SetAutoStart(bool IsAtuoRun) @@ -261,9 +265,9 @@ namespace WinAlfred HideWinAlfred(); } - public void ShowApp(string[] args) + public void ShowApp() { - ShowWinAlfred(args); + ShowWinAlfred(); } public void ShowMsg(string title, string subTitle, string iconPath) diff --git a/WinAlfred/PluginLoader/BasePluginLoader.cs b/WinAlfred/PluginLoader/BasePluginLoader.cs index 38ff560cfd..ea8161bd8b 100644 --- a/WinAlfred/PluginLoader/BasePluginLoader.cs +++ b/WinAlfred/PluginLoader/BasePluginLoader.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using System.Windows.Forms; using WinAlfred.Helper; using WinAlfred.Plugin; using WinAlfred.Plugin.System; @@ -11,7 +12,7 @@ namespace WinAlfred.PluginLoader { public abstract class BasePluginLoader { - private static string PluginPath = "Plugins"; + private static string PluginPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins"; private static string PluginConfigName = "plugin.ini"; protected static List pluginMetadatas = new List(); public abstract List LoadPlugin(); @@ -70,8 +71,8 @@ namespace WinAlfred.PluginLoader metadata.Version = ini.GetSetting("plugin", "Version"); metadata.PluginType = PluginType.ThirdParty; metadata.ActionKeyword = ini.GetSetting("plugin", "ActionKeyword"); - metadata.ExecuteFilePath = AppDomain.CurrentDomain.BaseDirectory + directory + "\\" + ini.GetSetting("plugin", "ExecuteFile"); - metadata.PluginDirecotry = AppDomain.CurrentDomain.BaseDirectory + directory + "\\"; + metadata.ExecuteFilePath = directory + "\\" + ini.GetSetting("plugin", "ExecuteFile"); + metadata.PluginDirecotry = directory + "\\"; metadata.ExecuteFileName = ini.GetSetting("plugin", "ExecuteFile"); if (!AllowedLanguage.IsAllowed(metadata.Language)) diff --git a/WinAlfred/PluginLoader/Plugins.cs b/WinAlfred/PluginLoader/Plugins.cs index a047a67da4..e832febb73 100644 --- a/WinAlfred/PluginLoader/Plugins.cs +++ b/WinAlfred/PluginLoader/Plugins.cs @@ -28,7 +28,7 @@ namespace WinAlfred.PluginLoader ChangeQuery = s => window.ChangeQuery(s), CloseApp = window.CloseApp, HideApp = window.HideApp, - ShowApp = () => window.ShowApp(null), + ShowApp = () => window.ShowApp(), ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath) })); } diff --git a/WinAlfred/Properties/AssemblyInfo.cs b/WinAlfred/Properties/AssemblyInfo.cs index 0e09fcd589..85b3df9561 100644 --- a/WinAlfred/Properties/AssemblyInfo.cs +++ b/WinAlfred/Properties/AssemblyInfo.cs @@ -1,56 +1,56 @@ -using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Windows; - -// 有关程序集的常规信息通过以下 -// 特性集控制。更改这些特性值可修改 -// 与程序集关联的信息。 -[assembly: AssemblyTitle("WinAlfredWPF")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("WinAlfredWPF")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 将 ComVisible 设置为 false 使此程序集中的类型 -// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, -// 则将该类型上的 ComVisible 特性设置为 true。 -[assembly: ComVisible(false)] - -//若要开始生成可本地化的应用程序,请在 -// 中的 .csproj 文件中 -//设置 CultureYouAreCodingWith。例如,如果您在源文件中 -//使用的是美国英语,请将 设置为 en-US。然后取消 -//对以下 NeutralResourceLanguage 特性的注释。更新 -//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 - -//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //主题特定资源词典所处位置 - //(在页面或应用程序资源词典中 - // 未找到某个资源的情况下使用) - ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 - //(在页面、应用程序或任何主题特定资源词典中 - // 未找到某个资源的情况下使用) -)] - - -// 程序集的版本信息由下面四个值组成: -// -// 主版本 -// 次版本 -// 生成号 -// 修订号 -// -// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, -// 方法是按如下所示使用“*”: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("WinAlfred")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("WinAlfred")] +[assembly: AssemblyCopyright("Copyright © qianlifeng 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +//若要开始生成可本地化的应用程序,请在 +// 中的 .csproj 文件中 +//设置 CultureYouAreCodingWith。例如,如果您在源文件中 +//使用的是美国英语,请将 设置为 en-US。然后取消 +//对以下 NeutralResourceLanguage 特性的注释。更新 +//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //主题特定资源词典所处位置 + //(在页面或应用程序资源词典中 + // 未找到某个资源的情况下使用) + ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 + //(在页面、应用程序或任何主题特定资源词典中 + // 未找到某个资源的情况下使用) +)] + + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: log4net.Config.XmlConfigurator(Watch = true)] \ No newline at end of file