diff --git a/Plugins/Wox.Plugin.Everything/Main.cs b/Plugins/Wox.Plugin.Everything/Main.cs
index c29b3a530c..dc8abe93ab 100644
--- a/Plugins/Wox.Plugin.Everything/Main.cs
+++ b/Plugins/Wox.Plugin.Everything/Main.cs
@@ -30,17 +30,7 @@ namespace Wox.Plugin.Everything
r.Action = (c) =>
{
context.HideApp();
- System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
- info.UseShellExecute = true;
- info.FileName = path;
- try
- {
- System.Diagnostics.Process.Start(info);
- }
- catch (Exception ex)
- {
- context.ShowMsg("Could not start " + r.Title, ex.Message, null);
- }
+ context.ShellRun(path);
return true;
};
results.Add(r);
diff --git a/Wox.Plugin.System/WindowsShellRun.cs b/Wox.Infrastructure/WindowsShellRun.cs
similarity index 99%
rename from Wox.Plugin.System/WindowsShellRun.cs
rename to Wox.Infrastructure/WindowsShellRun.cs
index fbdaa6a504..038448c76b 100644
--- a/Wox.Plugin.System/WindowsShellRun.cs
+++ b/Wox.Infrastructure/WindowsShellRun.cs
@@ -5,7 +5,7 @@ using System.Text;
using System.Runtime.InteropServices;
using System.IO;
-namespace Wox.Plugin.System
+namespace Wox.Infrastructure
{
/*
* http://undoc.airesoft.co.uk/shell32.dll/ShellExecCmdLine.php
diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj
index 4aab17fbe5..a807ea39a8 100644
--- a/Wox.Infrastructure/Wox.Infrastructure.csproj
+++ b/Wox.Infrastructure/Wox.Infrastructure.csproj
@@ -60,6 +60,7 @@
+
diff --git a/Wox.Plugin.System/BrowserBookmarks.cs b/Wox.Plugin.System/BrowserBookmarks.cs
index 42be68a777..32965762db 100644
--- a/Wox.Plugin.System/BrowserBookmarks.cs
+++ b/Wox.Plugin.System/BrowserBookmarks.cs
@@ -14,7 +14,7 @@ namespace Wox.Plugin.System
{
public class BrowserBookmarks : BaseSystemPlugin
{
-
+ private PluginInitContext context;
private List bookmarks = new List();
protected override List QueryInternal(Query query)
@@ -29,16 +29,10 @@ namespace Wox.Plugin.System
SubTitle = "Bookmark: " + c.Url,
IcoPath = Directory.GetCurrentDirectory() + @"\Images\bookmark.png",
Score = 5,
- Action = (context) =>
+ Action = (e) =>
{
- try
- {
- Process.Start(c.Url);
- }
- catch (Exception)
- {
- MessageBox.Show("open url failed:" + c.Url);
- }
+ context.HideApp();
+ context.ShellRun(c.Url);
return true;
}
}).ToList();
@@ -57,6 +51,7 @@ namespace Wox.Plugin.System
LoadChromeBookmarks();
bookmarks = bookmarks.Distinct().ToList();
+ this.context = context;
}
private void ParseChromeBookmarks(String path, string source)
diff --git a/Wox.Plugin.System/CMD.cs b/Wox.Plugin.System/CMD.cs
index 7142ada54f..d8c7b6ff34 100644
--- a/Wox.Plugin.System/CMD.cs
+++ b/Wox.Plugin.System/CMD.cs
@@ -137,15 +137,8 @@ namespace Wox.Plugin.System
private void ExecuteCmd(string cmd)
{
- try
- {
- WindowsShellRun.Start(cmd);
+ if (context.ShellRun(cmd))
AddCmdHistory(cmd);
- }
- catch (Exception e)
- {
- MessageBox.Show("Wox cound't execute this command. \n\n" + e.Message);
- }
}
protected override void InitInternal(PluginInitContext context)
diff --git a/Wox.Plugin.System/Programs.cs b/Wox.Plugin.System/Programs.cs
index 5d05bff18e..67f492cbf8 100644
--- a/Wox.Plugin.System/Programs.cs
+++ b/Wox.Plugin.System/Programs.cs
@@ -51,6 +51,7 @@ namespace Wox.Plugin.System
{"PortableAppsProgramSource", typeof(PortableAppsProgramSource)},
{"FileSystemProgramSource", typeof(FileSystemProgramSource)},
};
+ private PluginInitContext context;
protected override List QueryInternal(Query query)
{
@@ -69,28 +70,10 @@ namespace Wox.Plugin.System
SubTitle = c.ExecutePath,
IcoPath = c.IcoPath,
Score = 0,
- Action = (context) =>
+ Action = (e) =>
{
- if (string.IsNullOrEmpty(c.ExecutePath))
- {
- MessageBox.Show("couldn't start" + c.Title);
- }
- else
- {
- try
- {
- Process.Start(c.ExecutePath);
- }
- catch (Win32Exception)
- {
- //Do nothing.
- //It may be caused if UAC blocks the program.
- }
- catch (Exception e)
- {
- throw e;
- }
- }
+ context.HideApp();
+ context.ShellRun(c.ExecutePath);
return true;
}
}).ToList();
@@ -108,6 +91,8 @@ namespace Wox.Plugin.System
protected override void InitInternal(PluginInitContext context)
{
+ this.context = context;
+
if (CommonStorage.Instance.UserSetting.ProgramSources == null)
CommonStorage.Instance.UserSetting.ProgramSources = CommonStorage.Instance.UserSetting.LoadDefaultProgramSources();
diff --git a/Wox.Plugin.System/Wox.Plugin.System.csproj b/Wox.Plugin.System/Wox.Plugin.System.csproj
index d6984b650e..7de509b30e 100644
--- a/Wox.Plugin.System/Wox.Plugin.System.csproj
+++ b/Wox.Plugin.System/Wox.Plugin.System.csproj
@@ -61,7 +61,6 @@
-
diff --git a/Wox.Plugin/PluginInitContext.cs b/Wox.Plugin/PluginInitContext.cs
index fae6d758d9..a29448ba35 100644
--- a/Wox.Plugin/PluginInitContext.cs
+++ b/Wox.Plugin/PluginInitContext.cs
@@ -29,5 +29,7 @@ namespace Wox.Plugin
public Action StartLoadingBar { get; set; }
public Action StopLoadingBar { get; set; }
+
+ public Func ShellRun { get; set; }
}
}
diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs
index 3eb3e35561..566b2b67f4 100644
--- a/Wox/MainWindow.xaml.cs
+++ b/Wox/MainWindow.xaml.cs
@@ -506,6 +506,21 @@ namespace Wox
#endregion
+ public bool ShellRun(string cmd)
+ {
+ try
+ {
+ if (string.IsNullOrEmpty(cmd))
+ throw new ArgumentNullException();
+ Wox.Infrastructure.WindowsShellRun.Start(cmd);
+ return true;
+ }
+ catch (Exception ex)
+ {
+ ShowMsg("Could not start " + cmd, ex.Message, null);
+ }
+ return false;
+ }
}
}
\ No newline at end of file
diff --git a/Wox/PluginLoader/Plugins.cs b/Wox/PluginLoader/Plugins.cs
index d1fe4b118d..72accc6109 100644
--- a/Wox/PluginLoader/Plugins.cs
+++ b/Wox/PluginLoader/Plugins.cs
@@ -51,6 +51,7 @@ namespace Wox.PluginLoader
})),
StartLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StartLoadingBar())),
StopLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StopLoadingBar())),
+ ShellRun = (cmd) => (bool) App.Window.Dispatcher.Invoke(new Func(() => App.Window.ShellRun(cmd))),
}));
}
}