mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00: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:
parent
f0765ba743
commit
6023f415a4
9 changed files with 71 additions and 58 deletions
|
|
@ -205,22 +205,19 @@ namespace Wox.Plugin.PluginManagement
|
|||
|
||||
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)
|
||||
{
|
||||
File.Create(Path.Combine(plugin.PluginDirectory, "NeedDelete.txt")).Close();
|
||||
if (MessageBox.Show(
|
||||
"You have uninstalled plugin " + plugin.Name + " successfully.\r\n Restart Wox to take effect?",
|
||||
"Install plugin",
|
||||
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
|
||||
var result = MessageBox.Show($"You have uninstalled plugin {plugin.Name} successfully.{Environment.NewLine}" +
|
||||
"Restart Wox to take effect?",
|
||||
"Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
ProcessStartInfo Info = new ProcessStartInfo();
|
||||
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();
|
||||
context.API.RestarApp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,9 @@
|
|||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Windows.Presentation" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="HttpRequest.cs" />
|
||||
|
|
|
|||
|
|
@ -171,14 +171,8 @@ namespace Wox.Plugin.Sys
|
|||
IcoPath = "Images\\restart.png",
|
||||
Action = (c) =>
|
||||
{
|
||||
ProcessStartInfo Info = new ProcessStartInfo();
|
||||
Info.Arguments = "/C ping 127.0.0.1 -n 1 && \"" + FormsApplication.ExecutablePath + "\"";
|
||||
Info.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
Info.CreateNoWindow = true;
|
||||
Info.FileName = "cmd.exe";
|
||||
Process.Start(Info);
|
||||
context.API.CloseApp();
|
||||
return true;
|
||||
context.API.RestarApp();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
new Result
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Plugin;
|
||||
using System.Windows;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
|
|
@ -47,22 +47,24 @@ namespace Wox.Core.Plugin
|
|||
.Replace("*", "_")
|
||||
.Replace("|", "_")
|
||||
+ "-" + Guid.NewGuid();
|
||||
string newPluginPath = Path.Combine(pluginFolerPath,newPluginName);
|
||||
string content = string.Format(
|
||||
"Do you want to install following plugin?\r\n\r\nName: {0}\r\nVersion: {1}\r\nAuthor: {2}",
|
||||
plugin.Name, plugin.Version, plugin.Author);
|
||||
string newPluginPath = Path.Combine(pluginFolerPath, newPluginName);
|
||||
string content = $"Do you want to install following plugin?{Environment.NewLine}{Environment.NewLine}" +
|
||||
$"Name: {plugin.Name}{Environment.NewLine}" +
|
||||
$"Version: {plugin.Version}{Environment.NewLine}" +
|
||||
$"Author: {plugin.Author}";
|
||||
PluginPair existingPlugin = PluginManager.GetPluginForId(plugin.ID);
|
||||
|
||||
if (existingPlugin != null)
|
||||
{
|
||||
content = string.Format(
|
||||
"Do you want to update following plugin?\r\n\r\nName: {0}\r\nOld Version: {1}\r\nNew Version: {2}\r\nAuthor: {3}",
|
||||
plugin.Name, existingPlugin.Metadata.Version, plugin.Version, plugin.Author);
|
||||
content = $"Do you want to update following plugin?{Environment.NewLine}{Environment.NewLine}" +
|
||||
$"Name: {plugin.Name}{Environment.NewLine}" +
|
||||
$"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,
|
||||
MessageBoxIcon.Question);
|
||||
if (result == DialogResult.Yes)
|
||||
var result = MessageBox.Show(content, "Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
if (existingPlugin != null && Directory.Exists(existingPlugin.Metadata.PluginDirectory))
|
||||
{
|
||||
|
|
@ -81,17 +83,11 @@ namespace Wox.Core.Plugin
|
|||
//{
|
||||
// Plugins.Init();
|
||||
//}
|
||||
if (MessageBox.Show("You have installed plugin " + plugin.Name + " successfully.\r\n Restart Wox to take effect?", "Install plugin",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
if (MessageBox.Show($"You have installed plugin {plugin.Name} successfully.{Environment.NewLine}" +
|
||||
" Restart Wox to take effect?",
|
||||
"Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
|
||||
{
|
||||
ProcessStartInfo Info = new ProcessStartInfo();
|
||||
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();
|
||||
PluginManager.API.RestarApp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -114,7 +110,7 @@ namespace Wox.Core.Plugin
|
|||
}
|
||||
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)
|
||||
{
|
||||
throw new System.Exception(error);
|
||||
|
|
@ -126,8 +122,7 @@ namespace Wox.Core.Plugin
|
|||
|
||||
if (!AllowedLanguage.IsAllowed(metadata.Language))
|
||||
{
|
||||
string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath,
|
||||
metadata.Language);
|
||||
string error = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw new System.Exception(error);
|
||||
|
|
@ -137,8 +132,7 @@ namespace Wox.Core.Plugin
|
|||
}
|
||||
if (!File.Exists(metadata.ExecuteFilePath))
|
||||
{
|
||||
string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath,
|
||||
metadata.ExecuteFilePath);
|
||||
string error = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw new System.Exception(error);
|
||||
|
|
|
|||
|
|
@ -51,6 +51,11 @@ namespace Wox.Plugin
|
|||
/// </summary>
|
||||
void CloseApp();
|
||||
|
||||
/// <summary>
|
||||
/// Restart Wox
|
||||
/// </summary>
|
||||
void RestarApp();
|
||||
|
||||
/// <summary>
|
||||
/// Hide Wox
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in a new issue