mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
fix #151.
This commit is contained in:
@@ -8,7 +8,7 @@ using Control = System.Windows.Controls.Control;
|
|||||||
|
|
||||||
namespace Wox.Plugin.SystemPlugins.CMD
|
namespace Wox.Plugin.SystemPlugins.CMD
|
||||||
{
|
{
|
||||||
public class CMD : BaseSystemPlugin,ISettingProvider
|
public class CMD : BaseSystemPlugin, ISettingProvider
|
||||||
{
|
{
|
||||||
private PluginInitContext context;
|
private PluginInitContext context;
|
||||||
|
|
||||||
@@ -28,12 +28,13 @@ namespace Wox.Plugin.SystemPlugins.CMD
|
|||||||
{
|
{
|
||||||
ExecuteCmd(m.Key);
|
ExecuteCmd(m.Key);
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
|
ContextMenu = GetContextMenus(m.Key)
|
||||||
}).Take(5);
|
}).Take(5);
|
||||||
|
|
||||||
results.AddRange(history);
|
results.AddRange(history);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.RawQuery.StartsWith(">") && query.RawQuery.Length > 1)
|
if (query.RawQuery.StartsWith(">") && query.RawQuery.Length > 1)
|
||||||
{
|
{
|
||||||
string cmd = query.RawQuery.Substring(1);
|
string cmd = query.RawQuery.Substring(1);
|
||||||
@@ -47,7 +48,8 @@ namespace Wox.Plugin.SystemPlugins.CMD
|
|||||||
{
|
{
|
||||||
ExecuteCmd(cmd);
|
ExecuteCmd(cmd);
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
|
ContextMenu = GetContextMenus(cmd)
|
||||||
};
|
};
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -59,7 +61,7 @@ namespace Wox.Plugin.SystemPlugins.CMD
|
|||||||
}
|
}
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
|
|
||||||
context.API.PushResults(query,context.CurrentPluginMetadata, new List<Result>() { result });
|
context.API.PushResults(query, context.CurrentPluginMetadata, new List<Result>() { result });
|
||||||
pushedResults.Add(result);
|
pushedResults.Add(result);
|
||||||
|
|
||||||
IEnumerable<Result> history = CMDStorage.Instance.CMDHistory.Where(o => o.Key.Contains(cmd))
|
IEnumerable<Result> history = CMDStorage.Instance.CMDHistory.Where(o => o.Key.Contains(cmd))
|
||||||
@@ -81,7 +83,8 @@ namespace Wox.Plugin.SystemPlugins.CMD
|
|||||||
{
|
{
|
||||||
ExecuteCmd(m.Key);
|
ExecuteCmd(m.Key);
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
|
ContextMenu = GetContextMenus(m.Key)
|
||||||
};
|
};
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -95,7 +98,7 @@ namespace Wox.Plugin.SystemPlugins.CMD
|
|||||||
return ret;
|
return ret;
|
||||||
}).Where(o => o != null).Take(4);
|
}).Where(o => o != null).Take(4);
|
||||||
|
|
||||||
context.API.PushResults(query,context.CurrentPluginMetadata,history.ToList());
|
context.API.PushResults(query, context.CurrentPluginMetadata, history.ToList());
|
||||||
pushedResults.AddRange(history);
|
pushedResults.AddRange(history);
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -128,7 +131,8 @@ namespace Wox.Plugin.SystemPlugins.CMD
|
|||||||
{
|
{
|
||||||
ExecuteCmd(m);
|
ExecuteCmd(m);
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
|
ContextMenu = GetContextMenus(m)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,10 +141,27 @@ namespace Wox.Plugin.SystemPlugins.CMD
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Result> GetContextMenus(string cmd)
|
||||||
private void ExecuteCmd(string cmd)
|
|
||||||
{
|
{
|
||||||
if (context.API.ShellRun(cmd))
|
return new List<Result>()
|
||||||
|
{
|
||||||
|
new Result()
|
||||||
|
{
|
||||||
|
Title = "Run As Administrator",
|
||||||
|
Action = c =>
|
||||||
|
{
|
||||||
|
context.API.HideApp();
|
||||||
|
ExecuteCmd(cmd, true);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
IcoPath = "Images/cmd.png"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ExecuteCmd(string cmd, bool runAsAdministrator = false)
|
||||||
|
{
|
||||||
|
if (context.API.ShellRun(cmd, runAsAdministrator))
|
||||||
CMDStorage.Instance.AddCmdHistory(cmd);
|
CMDStorage.Instance.AddCmdHistory(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +192,7 @@ namespace Wox.Plugin.SystemPlugins.CMD
|
|||||||
|
|
||||||
public Control CreateSettingPanel()
|
public Control CreateSettingPanel()
|
||||||
{
|
{
|
||||||
return new CMDSetting();
|
return new CMDSetting();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user