mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 11:39:16 +08:00
5bb90828f8
Fix bug in 24866ff032829e9bd34704d3d5970d227a4c8db3. Wait existing Mutex to release itself instead of create a new one. Relate issue: #322
66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
using Wox.CommandArgs;
|
|
using Wox.Core.Plugin;
|
|
using Wox.Helper;
|
|
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
|
|
|
namespace Wox
|
|
{
|
|
public partial class App : Application, ISingleInstanceApp
|
|
{
|
|
private const string Unique = "Wox_Unique_Application_Mutex";
|
|
public static MainWindow Window { get; private set; }
|
|
|
|
[STAThread]
|
|
public static void Main()
|
|
{
|
|
if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
|
|
{
|
|
var application = new App();
|
|
application.InitializeComponent();
|
|
application.Run();
|
|
SingleInstance<App>.Cleanup();
|
|
}
|
|
}
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
{
|
|
Stopwatch.Debug("Startup Time", () =>
|
|
{
|
|
base.OnStartup(e);
|
|
RegisterUnhandledException();
|
|
ThreadPool.QueueUserWorkItem(o => { ImageLoader.ImageLoader.PreloadImages(); });
|
|
Window = new MainWindow();
|
|
PluginManager.Init(Window);
|
|
CommandArgsFactory.Execute(e.Args.ToList());
|
|
});
|
|
|
|
}
|
|
|
|
[Conditional("RELEASE")]
|
|
private void RegisterUnhandledException()
|
|
{
|
|
// let exception throw as normal is better for Debug
|
|
DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException;
|
|
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
|
|
}
|
|
|
|
public void OnActivate(IList<string> args)
|
|
{
|
|
if (args.Count > 0 && args[0] == SingleInstance<App>.Restart)
|
|
{
|
|
Window.CloseApp();
|
|
}
|
|
else
|
|
{
|
|
CommandArgsFactory.Execute(args);
|
|
}
|
|
}
|
|
}
|
|
}
|