diff --git a/WinAlfred.WorkflowInstaller/MainWindow.xaml.cs b/WinAlfred.WorkflowInstaller/MainWindow.xaml.cs
index 1fae4018e8..320d2aaa6c 100644
--- a/WinAlfred.WorkflowInstaller/MainWindow.xaml.cs
+++ b/WinAlfred.WorkflowInstaller/MainWindow.xaml.cs
@@ -111,7 +111,7 @@ namespace WinAlfred.WorkflowInstaller
string winalfred = AppDomain.CurrentDomain.BaseDirectory + "WinAlfred.exe";
if (File.Exists(winalfred))
{
- Process.Start(winalfred, "refreshWorkflows");
+ Process.Start(winalfred, "reloadWorkflows");
MessageBox.Show("You have installed workflow " + plugin.Name + " successfully.");
}
else
diff --git a/WinAlfred/App.xaml.cs b/WinAlfred/App.xaml.cs
index dfb3747a16..f89ff25428 100644
--- a/WinAlfred/App.xaml.cs
+++ b/WinAlfred/App.xaml.cs
@@ -1,28 +1,68 @@
using System;
+using System.Collections.ObjectModel;
+using System.Linq;
using System.Threading;
using System.Windows;
+using Microsoft.VisualBasic.ApplicationServices;
+using StartupEventArgs = System.Windows.StartupEventArgs;
namespace WinAlfred
{
- ///
- /// App.xaml 的交互逻辑
- ///
+ public static class EntryPoint
+ {
+ [STAThread]
+ public static void Main(string[] args)
+ {
+ SingleInstanceManager manager = new SingleInstanceManager();
+ manager.Run(args);
+ }
+ }
+
+ // Using VB bits to detect single instances and process accordingly:
+ // * OnStartup is fired when the first instance loads
+ // * OnStartupNextInstance is fired when the application is re-run again
+ // NOTE: it is redirected to this instance thanks to IsSingleInstance
+ public class SingleInstanceManager : WindowsFormsApplicationBase
+ {
+ App app;
+
+ public SingleInstanceManager()
+ {
+ this.IsSingleInstance = true;
+ }
+
+ protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
+ {
+ // First time app is launched
+ app = new App();
+ app.InitializeComponent();
+ app.Run();
+ return true;
+ }
+
+ protected override void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs)
+ {
+ // Subsequent launches
+ base.OnStartupNextInstance(eventArgs);
+ app.Activate(eventArgs.CommandLine.ToArray());
+ }
+ }
+
public partial class App : Application
{
+ private MainWindow window;
+
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
- bool startupFlag;
- Mutex mutex = new Mutex(true, "WinAlfred", out startupFlag);
- if (!startupFlag)
- {
- Environment.Exit(0);
- }
- else
- {
- MainWindow mainWindow = new MainWindow();
- mainWindow.Show();
- }
+
+ window = new MainWindow();
+ window.ShowApp(e.Args);
+ }
+
+ public void Activate(string[] commandLine)
+ {
+ window.ShowApp(commandLine);
}
}
}
diff --git a/WinAlfred/MainWindow.xaml.cs b/WinAlfred/MainWindow.xaml.cs
index 27602d97dc..969305f6d4 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();
+ notifyIcon.Click += (o, e) => ShowWinAlfred(null);
System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open");
- open.Click += (o, e) => ShowWinAlfred();
+ open.Click += (o, e) => ShowWinAlfred(null);
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();
+ ShowWinAlfred(null);
}
else
{
@@ -132,8 +132,26 @@ namespace WinAlfred
Hide();
}
- private void ShowWinAlfred()
+ private void ShowWinAlfred(string[] args)
{
+ if (args != null && args.Length > 0)
+ {
+ switch (args[0])
+ {
+ case "reloadWorkflows":
+ Plugins.Init(this);
+ break;
+
+ case "query":
+ if (args.Length > 1)
+ {
+ string query = args[1];
+ tbQuery.Text = query;
+ }
+ break;
+ }
+ }
+
Show();
Activate();
tbQuery.Focus();
@@ -166,7 +184,6 @@ namespace WinAlfred
InitialTray();
selectedRecords.LoadSelectedRecords();
SetAutoStart(true);
- ShowWinAlfred();
//var engine = new Jurassic.ScriptEngine();
//MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString());
}
@@ -244,9 +261,9 @@ namespace WinAlfred
HideWinAlfred();
}
- public void ShowApp()
+ public void ShowApp(string[] args)
{
- ShowWinAlfred();
+ ShowWinAlfred(args);
}
public void ShowMsg(string title, string subTitle, string iconPath)
diff --git a/WinAlfred/PluginLoader/BasePluginLoader.cs b/WinAlfred/PluginLoader/BasePluginLoader.cs
index 3acf56d129..38ff560cfd 100644
--- a/WinAlfred/PluginLoader/BasePluginLoader.cs
+++ b/WinAlfred/PluginLoader/BasePluginLoader.cs
@@ -14,16 +14,11 @@ namespace WinAlfred.PluginLoader
private static string PluginPath = "Plugins";
private static string PluginConfigName = "plugin.ini";
protected static List pluginMetadatas = new List();
-
public abstract List LoadPlugin();
- static BasePluginLoader()
- {
- ParsePlugins();
- }
-
- private static void ParsePlugins()
+ public static void ParsePluginsConfig()
{
+ pluginMetadatas.Clear();
ParseSystemPlugins();
ParseThirdPartyPlugins();
}
@@ -126,7 +121,7 @@ namespace WinAlfred.PluginLoader
/////
//private static PluginMetadata filterPythonMetadata(PluginMetadata metadata)
//{
-
+
//}
}
}
diff --git a/WinAlfred/PluginLoader/Plugins.cs b/WinAlfred/PluginLoader/Plugins.cs
index 9e53b3507a..a047a67da4 100644
--- a/WinAlfred/PluginLoader/Plugins.cs
+++ b/WinAlfred/PluginLoader/Plugins.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
+using Microsoft.CSharp;
using WinAlfred.Plugin;
namespace WinAlfred.PluginLoader
@@ -14,23 +15,22 @@ namespace WinAlfred.PluginLoader
public static void Init(MainWindow window)
{
plugins.Clear();
+ BasePluginLoader.ParsePluginsConfig();
+
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
plugins.AddRange(new CSharpPluginLoader().LoadPlugin());
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
{
IPlugin plugin1 = plugin;
- ThreadPool.QueueUserWorkItem(o =>
+ ThreadPool.QueueUserWorkItem(o => plugin1.Init(new PluginInitContext()
{
- plugin1.Init(new PluginInitContext()
- {
- Plugins = plugins,
- ChangeQuery = s => window.ChangeQuery(s),
- CloseApp = window.CloseApp,
- HideApp = window.HideApp,
- ShowApp = window.ShowApp,
- ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath)
- });
- });
+ Plugins = plugins,
+ ChangeQuery = s => window.ChangeQuery(s),
+ CloseApp = window.CloseApp,
+ HideApp = window.HideApp,
+ ShowApp = () => window.ShowApp(null),
+ ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath)
+ }));
}
}
diff --git a/WinAlfred/PluginLoader/PythonPluginLoader.cs b/WinAlfred/PluginLoader/PythonPluginLoader.cs
index a31fea21fd..3e373c0694 100644
--- a/WinAlfred/PluginLoader/PythonPluginLoader.cs
+++ b/WinAlfred/PluginLoader/PythonPluginLoader.cs
@@ -9,12 +9,6 @@ namespace WinAlfred.PluginLoader
{
public class PythonPluginLoader : BasePluginLoader
{
-
- static PythonPluginLoader()
- {
-
- }
-
public override List LoadPlugin()
{
List plugins = new List();
diff --git a/WinAlfred/WinAlfred.csproj b/WinAlfred/WinAlfred.csproj
index 66b90e5963..d827c0ec48 100644
--- a/WinAlfred/WinAlfred.csproj
+++ b/WinAlfred/WinAlfred.csproj
@@ -16,6 +16,21 @@
..\
true
+ 发布\
+ true
+ Disk
+ false
+ Foreground
+ 7
+ Days
+ false
+ false
+ true
+ 0
+ 1.0.0.%2a
+ false
+ false
+ true
AnyCPU
@@ -57,11 +72,15 @@
prompt
MinimumRecommendedRules.ruleset
+
+ WinAlfred.EntryPoint
+
..\packages\log4net.2.0.3\lib\net35-full\log4net.dll
+
..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll
@@ -198,6 +217,24 @@
Always
+
+
+
+
+
+
+
+
+ False
+ .NET Framework 3.5 SP1 Client Profile
+ false
+
+
+ False
+ .NET Framework 3.5 SP1
+ true
+
+