mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
Use ShellRun to provide unified experience
This commit is contained in:
@@ -30,17 +30,7 @@ namespace Wox.Plugin.Everything
|
|||||||
r.Action = (c) =>
|
r.Action = (c) =>
|
||||||
{
|
{
|
||||||
context.HideApp();
|
context.HideApp();
|
||||||
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
|
context.ShellRun(path);
|
||||||
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);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
results.Add(r);
|
results.Add(r);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using System.Text;
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Wox.Plugin.System
|
namespace Wox.Infrastructure
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* http://undoc.airesoft.co.uk/shell32.dll/ShellExecCmdLine.php
|
* http://undoc.airesoft.co.uk/shell32.dll/ShellExecCmdLine.php
|
||||||
@@ -60,6 +60,7 @@
|
|||||||
<Compile Include="UserSettings\UserSelectedRecords.cs" />
|
<Compile Include="UserSettings\UserSelectedRecords.cs" />
|
||||||
<Compile Include="UserSettings\UserSetting.cs" />
|
<Compile Include="UserSettings\UserSetting.cs" />
|
||||||
<Compile Include="UserSettings\WebSearch.cs" />
|
<Compile Include="UserSettings\WebSearch.cs" />
|
||||||
|
<Compile Include="WindowsShellRun.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace Wox.Plugin.System
|
|||||||
{
|
{
|
||||||
public class BrowserBookmarks : BaseSystemPlugin
|
public class BrowserBookmarks : BaseSystemPlugin
|
||||||
{
|
{
|
||||||
|
private PluginInitContext context;
|
||||||
private List<Bookmark> bookmarks = new List<Bookmark>();
|
private List<Bookmark> bookmarks = new List<Bookmark>();
|
||||||
|
|
||||||
protected override List<Result> QueryInternal(Query query)
|
protected override List<Result> QueryInternal(Query query)
|
||||||
@@ -29,16 +29,10 @@ namespace Wox.Plugin.System
|
|||||||
SubTitle = "Bookmark: " + c.Url,
|
SubTitle = "Bookmark: " + c.Url,
|
||||||
IcoPath = Directory.GetCurrentDirectory() + @"\Images\bookmark.png",
|
IcoPath = Directory.GetCurrentDirectory() + @"\Images\bookmark.png",
|
||||||
Score = 5,
|
Score = 5,
|
||||||
Action = (context) =>
|
Action = (e) =>
|
||||||
{
|
{
|
||||||
try
|
context.HideApp();
|
||||||
{
|
context.ShellRun(c.Url);
|
||||||
Process.Start(c.Url);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
MessageBox.Show("open url failed:" + c.Url);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}).ToList();
|
}).ToList();
|
||||||
@@ -57,6 +51,7 @@ namespace Wox.Plugin.System
|
|||||||
LoadChromeBookmarks();
|
LoadChromeBookmarks();
|
||||||
|
|
||||||
bookmarks = bookmarks.Distinct().ToList();
|
bookmarks = bookmarks.Distinct().ToList();
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParseChromeBookmarks(String path, string source)
|
private void ParseChromeBookmarks(String path, string source)
|
||||||
|
|||||||
@@ -137,15 +137,8 @@ namespace Wox.Plugin.System
|
|||||||
|
|
||||||
private void ExecuteCmd(string cmd)
|
private void ExecuteCmd(string cmd)
|
||||||
{
|
{
|
||||||
try
|
if (context.ShellRun(cmd))
|
||||||
{
|
|
||||||
WindowsShellRun.Start(cmd);
|
|
||||||
AddCmdHistory(cmd);
|
AddCmdHistory(cmd);
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Wox cound't execute this command. \n\n" + e.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void InitInternal(PluginInitContext context)
|
protected override void InitInternal(PluginInitContext context)
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ namespace Wox.Plugin.System
|
|||||||
{"PortableAppsProgramSource", typeof(PortableAppsProgramSource)},
|
{"PortableAppsProgramSource", typeof(PortableAppsProgramSource)},
|
||||||
{"FileSystemProgramSource", typeof(FileSystemProgramSource)},
|
{"FileSystemProgramSource", typeof(FileSystemProgramSource)},
|
||||||
};
|
};
|
||||||
|
private PluginInitContext context;
|
||||||
|
|
||||||
protected override List<Result> QueryInternal(Query query)
|
protected override List<Result> QueryInternal(Query query)
|
||||||
{
|
{
|
||||||
@@ -69,28 +70,10 @@ namespace Wox.Plugin.System
|
|||||||
SubTitle = c.ExecutePath,
|
SubTitle = c.ExecutePath,
|
||||||
IcoPath = c.IcoPath,
|
IcoPath = c.IcoPath,
|
||||||
Score = 0,
|
Score = 0,
|
||||||
Action = (context) =>
|
Action = (e) =>
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(c.ExecutePath))
|
context.HideApp();
|
||||||
{
|
context.ShellRun(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}).ToList();
|
}).ToList();
|
||||||
@@ -108,6 +91,8 @@ namespace Wox.Plugin.System
|
|||||||
|
|
||||||
protected override void InitInternal(PluginInitContext context)
|
protected override void InitInternal(PluginInitContext context)
|
||||||
{
|
{
|
||||||
|
this.context = context;
|
||||||
|
|
||||||
if (CommonStorage.Instance.UserSetting.ProgramSources == null)
|
if (CommonStorage.Instance.UserSetting.ProgramSources == null)
|
||||||
CommonStorage.Instance.UserSetting.ProgramSources = CommonStorage.Instance.UserSetting.LoadDefaultProgramSources();
|
CommonStorage.Instance.UserSetting.ProgramSources = CommonStorage.Instance.UserSetting.LoadDefaultProgramSources();
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,6 @@
|
|||||||
<Compile Include="FileSystemProgramSource.cs" />
|
<Compile Include="FileSystemProgramSource.cs" />
|
||||||
<Compile Include="UserStartMenuProgramSource.cs" />
|
<Compile Include="UserStartMenuProgramSource.cs" />
|
||||||
<Compile Include="WebSearchPlugin.cs" />
|
<Compile Include="WebSearchPlugin.cs" />
|
||||||
<Compile Include="WindowsShellRun.cs" />
|
|
||||||
<Compile Include="CMD.cs" />
|
<Compile Include="CMD.cs" />
|
||||||
<Compile Include="DirectoryIndicator.cs" />
|
<Compile Include="DirectoryIndicator.cs" />
|
||||||
<Compile Include="ISystemPlugin.cs" />
|
<Compile Include="ISystemPlugin.cs" />
|
||||||
|
|||||||
@@ -29,5 +29,7 @@ namespace Wox.Plugin
|
|||||||
|
|
||||||
public Action StartLoadingBar { get; set; }
|
public Action StartLoadingBar { get; set; }
|
||||||
public Action StopLoadingBar { get; set; }
|
public Action StopLoadingBar { get; set; }
|
||||||
|
|
||||||
|
public Func<string, bool> ShellRun { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -506,6 +506,21 @@ namespace Wox
|
|||||||
|
|
||||||
#endregion
|
#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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,6 +51,7 @@ namespace Wox.PluginLoader
|
|||||||
})),
|
})),
|
||||||
StartLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StartLoadingBar())),
|
StartLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StartLoadingBar())),
|
||||||
StopLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StopLoadingBar())),
|
StopLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StopLoadingBar())),
|
||||||
|
ShellRun = (cmd) => (bool) App.Window.Dispatcher.Invoke(new Func<bool>(() => App.Window.ShellRun(cmd))),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user