PowerToys/WinAlfred/App.xaml.cs

69 lines
1.9 KiB
C#
Raw Normal View History

2014-01-06 22:21:08 +08:00
using System;
2014-01-12 18:15:30 +08:00
using System.Collections.ObjectModel;
using System.Linq;
2014-01-06 22:21:08 +08:00
using System.Threading;
using System.Windows;
2014-01-12 18:15:30 +08:00
using Microsoft.VisualBasic.ApplicationServices;
using StartupEventArgs = System.Windows.StartupEventArgs;
2014-01-06 22:21:08 +08:00
namespace WinAlfred
{
2014-01-12 18:15:30 +08:00
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());
}
}
2014-01-06 22:21:08 +08:00
public partial class App : Application
{
2014-01-12 18:15:30 +08:00
private MainWindow window;
2014-01-06 22:21:08 +08:00
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
2014-01-12 18:15:30 +08:00
window = new MainWindow();
window.ShowApp(e.Args);
}
public void Activate(string[] commandLine)
{
window.ShowApp(commandLine);
2014-01-06 22:21:08 +08:00
}
}
}