Use ShellRun to provide unified experience

This commit is contained in:
Yeechan Lu 2014-03-21 03:53:18 +08:00
parent 25cedff47a
commit 5c6b741dc4
10 changed files with 33 additions and 52 deletions

View file

@ -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);

View file

@ -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

View file

@ -60,6 +60,7 @@
<Compile Include="UserSettings\UserSelectedRecords.cs" />
<Compile Include="UserSettings\UserSetting.cs" />
<Compile Include="UserSettings\WebSearch.cs" />
<Compile Include="WindowsShellRun.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

View file

@ -14,7 +14,7 @@ namespace Wox.Plugin.System
{
public class BrowserBookmarks : BaseSystemPlugin
{
private PluginInitContext context;
private List<Bookmark> bookmarks = new List<Bookmark>();
protected override List<Result> 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)

View file

@ -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)

View file

@ -51,6 +51,7 @@ namespace Wox.Plugin.System
{"PortableAppsProgramSource", typeof(PortableAppsProgramSource)},
{"FileSystemProgramSource", typeof(FileSystemProgramSource)},
};
private PluginInitContext context;
protected override List<Result> 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();

View file

@ -61,7 +61,6 @@
<Compile Include="FileSystemProgramSource.cs" />
<Compile Include="UserStartMenuProgramSource.cs" />
<Compile Include="WebSearchPlugin.cs" />
<Compile Include="WindowsShellRun.cs" />
<Compile Include="CMD.cs" />
<Compile Include="DirectoryIndicator.cs" />
<Compile Include="ISystemPlugin.cs" />

View file

@ -29,5 +29,7 @@ namespace Wox.Plugin
public Action StartLoadingBar { get; set; }
public Action StopLoadingBar { get; set; }
public Func<string, bool> ShellRun { get; set; }
}
}

View file

@ -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;
}
}
}

View file

@ -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<bool>(() => App.Window.ShellRun(cmd))),
}));
}
}