Fix Wox restart

1. refactoring restart
2. delte some windows forms methods
3. using string inteperlation and delete hard coeded new line char

should fix #322
This commit is contained in:
bao-qian
2015-11-26 02:04:44 +00:00
parent f0765ba743
commit 6023f415a4
9 changed files with 71 additions and 58 deletions

View File

@@ -52,6 +52,10 @@ namespace Wox
public bool OnActivate(IList<string> args)
{
if (args.Count > 0 && args[0] == SingleInstance<App>.Restart)
{
Window.CloseApp();
}
CommandArgsFactory.Execute(args);
return true;
}

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Wox.Helper;
namespace Wox.CommandArgs
{
@@ -20,7 +21,8 @@ namespace Wox.CommandArgs
public static void Execute(IList<string> args)
{
if (args.Count > 0)
// todo restart command line args?
if (args.Count > 0 && args[0] != SingleInstance<App>.Restart)
{
string command = args[0];
ICommandArg cmd = commandArgs.FirstOrDefault(o => o.Command.ToLower() == command);

View File

@@ -212,6 +212,8 @@ namespace Wox.Helper
where TApplication: Application , ISingleInstanceApp
{
public const string Restart = "Restart";
#region Private Fields
/// <summary>
@@ -273,6 +275,8 @@ namespace Wox.Helper
public static bool InitializeAsFirstInstance( string uniqueName )
{
commandLineArgs = GetCommandLineArgs(uniqueName);
//remove execute path itself
commandLineArgs.RemoveAt(0);
// Build unique application Id and the IPC channel name.
string applicationIdentifier = uniqueName + Environment.UserName;
@@ -285,13 +289,20 @@ namespace Wox.Helper
if (firstInstance)
{
CreateRemoteService(channelName);
return true;
}
else if (commandLineArgs.Count > 0 && commandLineArgs[0] == Restart)
{
SignalFirstInstance(channelName, commandLineArgs);
singleInstanceMutex = new Mutex(true, applicationIdentifier);
CreateRemoteService(channelName);
return true;
}
else
{
SignalFirstInstance(channelName, commandLineArgs);
return false;
}
return firstInstance;
}
/// <summary>
@@ -442,8 +453,7 @@ namespace Wox.Helper
{
return;
}
//remove execute path itself
args.RemoveAt(0);
((TApplication)Application.Current).OnActivate(args);
}

View File

@@ -10,7 +10,6 @@ using System.Reflection;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media.Animation;
using NHotkey;
@@ -26,14 +25,10 @@ using Wox.Infrastructure.Hotkey;
using Wox.Plugin;
using Wox.Storage;
using ContextMenu = System.Windows.Forms.ContextMenu;
using DataFormats = System.Windows.DataFormats;
using DragEventArgs = System.Windows.DragEventArgs;
using IDataObject = System.Windows.IDataObject;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using NotifyIcon = System.Windows.Forms.NotifyIcon;
using Screen = System.Windows.Forms.Screen;
using MenuItem = System.Windows.Forms.MenuItem;
using MessageBox = System.Windows.MessageBox;
using Stopwatch = Wox.Infrastructure.Stopwatch;
using ToolTip = System.Windows.Controls.ToolTip;
namespace Wox
{
@@ -93,6 +88,16 @@ namespace Wox
}));
}
public void RestarApp()
{
ProcessStartInfo info = new ProcessStartInfo
{
FileName = Application.ResourceAssembly.Location,
Arguments = SingleInstance<App>.Restart
};
Process.Start(info);
}
public void HideApp()
{
Dispatcher.Invoke(new Action(HideWox));