mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add one instance support.
This commit is contained in:
parent
4a37a6f497
commit
2249bbb0f5
7 changed files with 130 additions and 47 deletions
|
|
@ -111,7 +111,7 @@ namespace WinAlfred.WorkflowInstaller
|
||||||
string winalfred = AppDomain.CurrentDomain.BaseDirectory + "WinAlfred.exe";
|
string winalfred = AppDomain.CurrentDomain.BaseDirectory + "WinAlfred.exe";
|
||||||
if (File.Exists(winalfred))
|
if (File.Exists(winalfred))
|
||||||
{
|
{
|
||||||
Process.Start(winalfred, "refreshWorkflows");
|
Process.Start(winalfred, "reloadWorkflows");
|
||||||
MessageBox.Show("You have installed workflow " + plugin.Name + " successfully.");
|
MessageBox.Show("You have installed workflow " + plugin.Name + " successfully.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,68 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using Microsoft.VisualBasic.ApplicationServices;
|
||||||
|
using StartupEventArgs = System.Windows.StartupEventArgs;
|
||||||
|
|
||||||
namespace WinAlfred
|
namespace WinAlfred
|
||||||
{
|
{
|
||||||
/// <summary>
|
public static class EntryPoint
|
||||||
/// App.xaml 的交互逻辑
|
{
|
||||||
/// </summary>
|
[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
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
|
private MainWindow window;
|
||||||
|
|
||||||
protected override void OnStartup(StartupEventArgs e)
|
protected override void OnStartup(StartupEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnStartup(e);
|
base.OnStartup(e);
|
||||||
bool startupFlag;
|
|
||||||
Mutex mutex = new Mutex(true, "WinAlfred", out startupFlag);
|
window = new MainWindow();
|
||||||
if (!startupFlag)
|
window.ShowApp(e.Args);
|
||||||
{
|
}
|
||||||
Environment.Exit(0);
|
|
||||||
}
|
public void Activate(string[] commandLine)
|
||||||
else
|
{
|
||||||
{
|
window.ShowApp(commandLine);
|
||||||
MainWindow mainWindow = new MainWindow();
|
|
||||||
mainWindow.Show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,9 +59,9 @@ namespace WinAlfred
|
||||||
private void InitialTray()
|
private void InitialTray()
|
||||||
{
|
{
|
||||||
notifyIcon = new NotifyIcon { Text = "WinAlfred", Icon = Properties.Resources.app, Visible = true };
|
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");
|
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");
|
System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit");
|
||||||
exit.Click += (o, e) => CloseApp();
|
exit.Click += (o, e) => CloseApp();
|
||||||
System.Windows.Forms.MenuItem[] childen = { open, exit };
|
System.Windows.Forms.MenuItem[] childen = { open, exit };
|
||||||
|
|
@ -78,7 +78,7 @@ namespace WinAlfred
|
||||||
{
|
{
|
||||||
if (!IsVisible)
|
if (!IsVisible)
|
||||||
{
|
{
|
||||||
ShowWinAlfred();
|
ShowWinAlfred(null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -132,8 +132,26 @@ namespace WinAlfred
|
||||||
Hide();
|
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();
|
Show();
|
||||||
Activate();
|
Activate();
|
||||||
tbQuery.Focus();
|
tbQuery.Focus();
|
||||||
|
|
@ -166,7 +184,6 @@ namespace WinAlfred
|
||||||
InitialTray();
|
InitialTray();
|
||||||
selectedRecords.LoadSelectedRecords();
|
selectedRecords.LoadSelectedRecords();
|
||||||
SetAutoStart(true);
|
SetAutoStart(true);
|
||||||
ShowWinAlfred();
|
|
||||||
//var engine = new Jurassic.ScriptEngine();
|
//var engine = new Jurassic.ScriptEngine();
|
||||||
//MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString());
|
//MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString());
|
||||||
}
|
}
|
||||||
|
|
@ -244,9 +261,9 @@ namespace WinAlfred
|
||||||
HideWinAlfred();
|
HideWinAlfred();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowApp()
|
public void ShowApp(string[] args)
|
||||||
{
|
{
|
||||||
ShowWinAlfred();
|
ShowWinAlfred(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowMsg(string title, string subTitle, string iconPath)
|
public void ShowMsg(string title, string subTitle, string iconPath)
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,11 @@ namespace WinAlfred.PluginLoader
|
||||||
private static string PluginPath = "Plugins";
|
private static string PluginPath = "Plugins";
|
||||||
private static string PluginConfigName = "plugin.ini";
|
private static string PluginConfigName = "plugin.ini";
|
||||||
protected static List<PluginMetadata> pluginMetadatas = new List<PluginMetadata>();
|
protected static List<PluginMetadata> pluginMetadatas = new List<PluginMetadata>();
|
||||||
|
|
||||||
public abstract List<PluginPair> LoadPlugin();
|
public abstract List<PluginPair> LoadPlugin();
|
||||||
|
|
||||||
static BasePluginLoader()
|
public static void ParsePluginsConfig()
|
||||||
{
|
|
||||||
ParsePlugins();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ParsePlugins()
|
|
||||||
{
|
{
|
||||||
|
pluginMetadatas.Clear();
|
||||||
ParseSystemPlugins();
|
ParseSystemPlugins();
|
||||||
ParseThirdPartyPlugins();
|
ParseThirdPartyPlugins();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Microsoft.CSharp;
|
||||||
using WinAlfred.Plugin;
|
using WinAlfred.Plugin;
|
||||||
|
|
||||||
namespace WinAlfred.PluginLoader
|
namespace WinAlfred.PluginLoader
|
||||||
|
|
@ -14,23 +15,22 @@ namespace WinAlfred.PluginLoader
|
||||||
public static void Init(MainWindow window)
|
public static void Init(MainWindow window)
|
||||||
{
|
{
|
||||||
plugins.Clear();
|
plugins.Clear();
|
||||||
|
BasePluginLoader.ParsePluginsConfig();
|
||||||
|
|
||||||
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
|
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
|
||||||
plugins.AddRange(new CSharpPluginLoader().LoadPlugin());
|
plugins.AddRange(new CSharpPluginLoader().LoadPlugin());
|
||||||
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
|
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
|
||||||
{
|
{
|
||||||
IPlugin plugin1 = 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),
|
||||||
Plugins = plugins,
|
CloseApp = window.CloseApp,
|
||||||
ChangeQuery = s => window.ChangeQuery(s),
|
HideApp = window.HideApp,
|
||||||
CloseApp = window.CloseApp,
|
ShowApp = () => window.ShowApp(null),
|
||||||
HideApp = window.HideApp,
|
ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath)
|
||||||
ShowApp = window.ShowApp,
|
}));
|
||||||
ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath)
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,6 @@ namespace WinAlfred.PluginLoader
|
||||||
{
|
{
|
||||||
public class PythonPluginLoader : BasePluginLoader
|
public class PythonPluginLoader : BasePluginLoader
|
||||||
{
|
{
|
||||||
|
|
||||||
static PythonPluginLoader()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override List<PluginPair> LoadPlugin()
|
public override List<PluginPair> LoadPlugin()
|
||||||
{
|
{
|
||||||
List<PluginPair> plugins = new List<PluginPair>();
|
List<PluginPair> plugins = new List<PluginPair>();
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,21 @@
|
||||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||||
<RestorePackages>true</RestorePackages>
|
<RestorePackages>true</RestorePackages>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
|
<PublishUrl>发布\</PublishUrl>
|
||||||
|
<Install>true</Install>
|
||||||
|
<InstallFrom>Disk</InstallFrom>
|
||||||
|
<UpdateEnabled>false</UpdateEnabled>
|
||||||
|
<UpdateMode>Foreground</UpdateMode>
|
||||||
|
<UpdateInterval>7</UpdateInterval>
|
||||||
|
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||||
|
<UpdatePeriodically>false</UpdatePeriodically>
|
||||||
|
<UpdateRequired>false</UpdateRequired>
|
||||||
|
<MapFileExtensions>true</MapFileExtensions>
|
||||||
|
<ApplicationRevision>0</ApplicationRevision>
|
||||||
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||||
|
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||||
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
|
@ -57,11 +72,15 @@
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<StartupObject>WinAlfred.EntryPoint</StartupObject>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Accessibility" />
|
<Reference Include="Accessibility" />
|
||||||
<Reference Include="log4net">
|
<Reference Include="log4net">
|
||||||
<HintPath>..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
|
<HintPath>..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.VisualBasic" />
|
||||||
<Reference Include="Newtonsoft.Json">
|
<Reference Include="Newtonsoft.Json">
|
||||||
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|
@ -198,6 +217,24 @@
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Resource>
|
</Resource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<WCFMetadata Include="Service References\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||||
|
<Install>false</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||||
|
<Install>true</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue