2014-01-29 10:33:24 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.ObjectModel;
|
2014-03-11 15:54:37 +00:00
|
|
|
|
using System.IO;
|
2014-01-29 10:33:24 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using Microsoft.VisualBasic.ApplicationServices;
|
|
|
|
|
using Wox.Commands;
|
2014-03-11 15:54:37 +00:00
|
|
|
|
using Wox.Helper;
|
2014-01-29 10:33:24 +00:00
|
|
|
|
using StartupEventArgs = System.Windows.StartupEventArgs;
|
|
|
|
|
|
|
|
|
|
namespace Wox
|
|
|
|
|
{
|
|
|
|
|
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 static MainWindow window;
|
|
|
|
|
|
|
|
|
|
public static MainWindow Window
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return window;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnStartup(e);
|
|
|
|
|
|
2014-03-11 15:54:37 +00:00
|
|
|
|
//for install plugin command when wox didn't start up
|
|
|
|
|
//we shouldn't init MainWindow, just intall plugin and exit.
|
|
|
|
|
if (e.Args.Length > 0 && e.Args[0].ToLower() == "installplugin")
|
|
|
|
|
{
|
|
|
|
|
var path = e.Args[1];
|
|
|
|
|
if (!File.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Plugin " + path + " didn't exist");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PluginInstaller.Install(path);
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-01-29 10:33:24 +00:00
|
|
|
|
window = new MainWindow();
|
2014-02-18 14:02:55 +00:00
|
|
|
|
if (e.Args.Length == 0 || e.Args[0].ToLower() != "hidestart")
|
2014-02-07 14:10:00 +00:00
|
|
|
|
{
|
|
|
|
|
window.ShowApp();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 10:33:24 +00:00
|
|
|
|
window.ParseArgs(e.Args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Activate(string[] args)
|
|
|
|
|
{
|
2014-02-18 14:02:55 +00:00
|
|
|
|
if (args.Length == 0 || args[0].ToLower() != "hidestart")
|
2014-02-07 14:10:00 +00:00
|
|
|
|
{
|
|
|
|
|
window.ShowApp();
|
|
|
|
|
}
|
2014-01-29 10:33:24 +00:00
|
|
|
|
window.ParseArgs(args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|