mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
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:
@@ -205,22 +205,19 @@ namespace Wox.Plugin.PluginManagement
|
|||||||
|
|
||||||
private void UnInstallPlugin(PluginMetadata plugin)
|
private void UnInstallPlugin(PluginMetadata plugin)
|
||||||
{
|
{
|
||||||
string content = string.Format("Do you want to uninstall following plugin?\r\n\r\nName: {0}\r\nVersion: {1}\r\nAuthor: {2}", plugin.Name, plugin.Version, plugin.Author);
|
string content = $"Do you want to uninstall following plugin?{Environment.NewLine}{Environment.NewLine}" +
|
||||||
|
$"Name: {plugin.Name}{Environment.NewLine}" +
|
||||||
|
$"Version: {plugin.Version}{Environment.NewLine}" +
|
||||||
|
$"Author: {plugin.Author}";
|
||||||
if (MessageBox.Show(content, "Wox", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
if (MessageBox.Show(content, "Wox", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||||
{
|
{
|
||||||
File.Create(Path.Combine(plugin.PluginDirectory, "NeedDelete.txt")).Close();
|
File.Create(Path.Combine(plugin.PluginDirectory, "NeedDelete.txt")).Close();
|
||||||
if (MessageBox.Show(
|
var result = MessageBox.Show($"You have uninstalled plugin {plugin.Name} successfully.{Environment.NewLine}" +
|
||||||
"You have uninstalled plugin " + plugin.Name + " successfully.\r\n Restart Wox to take effect?",
|
"Restart Wox to take effect?",
|
||||||
"Install plugin",
|
"Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||||
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
|
if (result == MessageBoxResult.Yes)
|
||||||
{
|
{
|
||||||
ProcessStartInfo Info = new ProcessStartInfo();
|
context.API.RestarApp();
|
||||||
Info.Arguments = "/C ping 127.0.0.1 -n 1 && \"" + Assembly.GetExecutingAssembly().Location + "\"";
|
|
||||||
Info.WindowStyle = ProcessWindowStyle.Hidden;
|
|
||||||
Info.CreateNoWindow = true;
|
|
||||||
Info.FileName = "cmd.exe";
|
|
||||||
Process.Start(Info);
|
|
||||||
context.API.CloseApp();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,9 @@
|
|||||||
<Reference Include="PresentationFramework" />
|
<Reference Include="PresentationFramework" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Windows.Presentation" />
|
<Reference Include="System.Windows.Presentation" />
|
||||||
|
<Reference Include="WindowsBase" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="HttpRequest.cs" />
|
<Compile Include="HttpRequest.cs" />
|
||||||
|
|||||||
@@ -171,14 +171,8 @@ namespace Wox.Plugin.Sys
|
|||||||
IcoPath = "Images\\restart.png",
|
IcoPath = "Images\\restart.png",
|
||||||
Action = (c) =>
|
Action = (c) =>
|
||||||
{
|
{
|
||||||
ProcessStartInfo Info = new ProcessStartInfo();
|
context.API.RestarApp();
|
||||||
Info.Arguments = "/C ping 127.0.0.1 -n 1 && \"" + FormsApplication.ExecutablePath + "\"";
|
return false;
|
||||||
Info.WindowStyle = ProcessWindowStyle.Hidden;
|
|
||||||
Info.CreateNoWindow = true;
|
|
||||||
Info.FileName = "cmd.exe";
|
|
||||||
Process.Start(Info);
|
|
||||||
context.API.CloseApp();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new Result
|
new Result
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
|
||||||
using ICSharpCode.SharpZipLib.Zip;
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
namespace Wox.Core.Plugin
|
namespace Wox.Core.Plugin
|
||||||
{
|
{
|
||||||
@@ -47,22 +47,24 @@ namespace Wox.Core.Plugin
|
|||||||
.Replace("*", "_")
|
.Replace("*", "_")
|
||||||
.Replace("|", "_")
|
.Replace("|", "_")
|
||||||
+ "-" + Guid.NewGuid();
|
+ "-" + Guid.NewGuid();
|
||||||
string newPluginPath = Path.Combine(pluginFolerPath,newPluginName);
|
string newPluginPath = Path.Combine(pluginFolerPath, newPluginName);
|
||||||
string content = string.Format(
|
string content = $"Do you want to install following plugin?{Environment.NewLine}{Environment.NewLine}" +
|
||||||
"Do you want to install following plugin?\r\n\r\nName: {0}\r\nVersion: {1}\r\nAuthor: {2}",
|
$"Name: {plugin.Name}{Environment.NewLine}" +
|
||||||
plugin.Name, plugin.Version, plugin.Author);
|
$"Version: {plugin.Version}{Environment.NewLine}" +
|
||||||
|
$"Author: {plugin.Author}";
|
||||||
PluginPair existingPlugin = PluginManager.GetPluginForId(plugin.ID);
|
PluginPair existingPlugin = PluginManager.GetPluginForId(plugin.ID);
|
||||||
|
|
||||||
if (existingPlugin != null)
|
if (existingPlugin != null)
|
||||||
{
|
{
|
||||||
content = string.Format(
|
content = $"Do you want to update following plugin?{Environment.NewLine}{Environment.NewLine}" +
|
||||||
"Do you want to update following plugin?\r\n\r\nName: {0}\r\nOld Version: {1}\r\nNew Version: {2}\r\nAuthor: {3}",
|
$"Name: {plugin.Name}{Environment.NewLine}" +
|
||||||
plugin.Name, existingPlugin.Metadata.Version, plugin.Version, plugin.Author);
|
$"Old Version: {existingPlugin.Metadata.Version}" +
|
||||||
|
$"{Environment.NewLine}New Version: {plugin.Version}" +
|
||||||
|
$"{Environment.NewLine}Author: {plugin.Author}";
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogResult result = System.Windows.Forms.MessageBox.Show(content, "Install plugin", MessageBoxButtons.YesNo,
|
var result = MessageBox.Show(content, "Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||||
MessageBoxIcon.Question);
|
if (result == MessageBoxResult.Yes)
|
||||||
if (result == DialogResult.Yes)
|
|
||||||
{
|
{
|
||||||
if (existingPlugin != null && Directory.Exists(existingPlugin.Metadata.PluginDirectory))
|
if (existingPlugin != null && Directory.Exists(existingPlugin.Metadata.PluginDirectory))
|
||||||
{
|
{
|
||||||
@@ -81,17 +83,11 @@ namespace Wox.Core.Plugin
|
|||||||
//{
|
//{
|
||||||
// Plugins.Init();
|
// Plugins.Init();
|
||||||
//}
|
//}
|
||||||
if (MessageBox.Show("You have installed plugin " + plugin.Name + " successfully.\r\n Restart Wox to take effect?", "Install plugin",
|
if (MessageBox.Show($"You have installed plugin {plugin.Name} successfully.{Environment.NewLine}" +
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
" Restart Wox to take effect?",
|
||||||
|
"Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
|
||||||
{
|
{
|
||||||
ProcessStartInfo Info = new ProcessStartInfo();
|
PluginManager.API.RestarApp();
|
||||||
Info.Arguments = "/C ping 127.0.0.1 -n 1 && \"" +
|
|
||||||
System.Windows.Forms.Application.ExecutablePath + "\"";
|
|
||||||
Info.WindowStyle = ProcessWindowStyle.Hidden;
|
|
||||||
Info.CreateNoWindow = true;
|
|
||||||
Info.FileName = "cmd.exe";
|
|
||||||
Process.Start(Info);
|
|
||||||
PluginManager.API.CloseApp();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,7 +110,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (System.Exception)
|
catch (System.Exception)
|
||||||
{
|
{
|
||||||
string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath);
|
string error = $"Parse plugin config {configPath} failed: json format is not valid";
|
||||||
#if (DEBUG)
|
#if (DEBUG)
|
||||||
{
|
{
|
||||||
throw new System.Exception(error);
|
throw new System.Exception(error);
|
||||||
@@ -126,8 +122,7 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
if (!AllowedLanguage.IsAllowed(metadata.Language))
|
if (!AllowedLanguage.IsAllowed(metadata.Language))
|
||||||
{
|
{
|
||||||
string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath,
|
string error = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
|
||||||
metadata.Language);
|
|
||||||
#if (DEBUG)
|
#if (DEBUG)
|
||||||
{
|
{
|
||||||
throw new System.Exception(error);
|
throw new System.Exception(error);
|
||||||
@@ -137,8 +132,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
if (!File.Exists(metadata.ExecuteFilePath))
|
if (!File.Exists(metadata.ExecuteFilePath))
|
||||||
{
|
{
|
||||||
string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath,
|
string error = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
|
||||||
metadata.ExecuteFilePath);
|
|
||||||
#if (DEBUG)
|
#if (DEBUG)
|
||||||
{
|
{
|
||||||
throw new System.Exception(error);
|
throw new System.Exception(error);
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ namespace Wox.Plugin
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void CloseApp();
|
void CloseApp();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restart Wox
|
||||||
|
/// </summary>
|
||||||
|
void RestarApp();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Hide Wox
|
/// Hide Wox
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ namespace Wox
|
|||||||
|
|
||||||
public bool OnActivate(IList<string> args)
|
public bool OnActivate(IList<string> args)
|
||||||
{
|
{
|
||||||
|
if (args.Count > 0 && args[0] == SingleInstance<App>.Restart)
|
||||||
|
{
|
||||||
|
Window.CloseApp();
|
||||||
|
}
|
||||||
CommandArgsFactory.Execute(args);
|
CommandArgsFactory.Execute(args);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Wox.Helper;
|
||||||
|
|
||||||
namespace Wox.CommandArgs
|
namespace Wox.CommandArgs
|
||||||
{
|
{
|
||||||
@@ -20,7 +21,8 @@ namespace Wox.CommandArgs
|
|||||||
|
|
||||||
public static void Execute(IList<string> args)
|
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];
|
string command = args[0];
|
||||||
ICommandArg cmd = commandArgs.FirstOrDefault(o => o.Command.ToLower() == command);
|
ICommandArg cmd = commandArgs.FirstOrDefault(o => o.Command.ToLower() == command);
|
||||||
|
|||||||
@@ -212,6 +212,8 @@ namespace Wox.Helper
|
|||||||
where TApplication: Application , ISingleInstanceApp
|
where TApplication: Application , ISingleInstanceApp
|
||||||
|
|
||||||
{
|
{
|
||||||
|
public const string Restart = "Restart";
|
||||||
|
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -273,6 +275,8 @@ namespace Wox.Helper
|
|||||||
public static bool InitializeAsFirstInstance( string uniqueName )
|
public static bool InitializeAsFirstInstance( string uniqueName )
|
||||||
{
|
{
|
||||||
commandLineArgs = GetCommandLineArgs(uniqueName);
|
commandLineArgs = GetCommandLineArgs(uniqueName);
|
||||||
|
//remove execute path itself
|
||||||
|
commandLineArgs.RemoveAt(0);
|
||||||
|
|
||||||
// Build unique application Id and the IPC channel name.
|
// Build unique application Id and the IPC channel name.
|
||||||
string applicationIdentifier = uniqueName + Environment.UserName;
|
string applicationIdentifier = uniqueName + Environment.UserName;
|
||||||
@@ -285,13 +289,20 @@ namespace Wox.Helper
|
|||||||
if (firstInstance)
|
if (firstInstance)
|
||||||
{
|
{
|
||||||
CreateRemoteService(channelName);
|
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
|
else
|
||||||
{
|
{
|
||||||
SignalFirstInstance(channelName, commandLineArgs);
|
SignalFirstInstance(channelName, commandLineArgs);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return firstInstance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -442,8 +453,7 @@ namespace Wox.Helper
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//remove execute path itself
|
|
||||||
args.RemoveAt(0);
|
|
||||||
((TApplication)Application.Current).OnActivate(args);
|
((TApplication)Application.Current).OnActivate(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ using System.Reflection;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Forms;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media.Animation;
|
using System.Windows.Media.Animation;
|
||||||
using NHotkey;
|
using NHotkey;
|
||||||
@@ -26,14 +25,10 @@ using Wox.Infrastructure.Hotkey;
|
|||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.Storage;
|
using Wox.Storage;
|
||||||
using ContextMenu = System.Windows.Forms.ContextMenu;
|
using ContextMenu = System.Windows.Forms.ContextMenu;
|
||||||
using DataFormats = System.Windows.DataFormats;
|
using NotifyIcon = System.Windows.Forms.NotifyIcon;
|
||||||
using DragEventArgs = System.Windows.DragEventArgs;
|
using Screen = System.Windows.Forms.Screen;
|
||||||
using IDataObject = System.Windows.IDataObject;
|
|
||||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
|
||||||
using MenuItem = System.Windows.Forms.MenuItem;
|
using MenuItem = System.Windows.Forms.MenuItem;
|
||||||
using MessageBox = System.Windows.MessageBox;
|
|
||||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||||
using ToolTip = System.Windows.Controls.ToolTip;
|
|
||||||
|
|
||||||
namespace Wox
|
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()
|
public void HideApp()
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(new Action(HideWox));
|
Dispatcher.Invoke(new Action(HideWox));
|
||||||
|
|||||||
Reference in New Issue
Block a user