add run as administration when holding ctrl and shift to Program and Explorer plugins

This commit is contained in:
Michael Mouawad 2021-08-22 13:36:01 +03:00
parent a87cea7e6f
commit ffd22d78c2
3 changed files with 34 additions and 4 deletions

View file

@ -46,6 +46,7 @@
<KeyBinding Key="Home" Modifiers="Alt" Command="{Binding SelectFirstResultCommand}"></KeyBinding>
<KeyBinding Key="O" Modifiers="Ctrl" Command="{Binding LoadContextMenuCommand}"></KeyBinding>
<KeyBinding Key="H" Modifiers="Ctrl" Command="{Binding LoadHistoryCommand}"></KeyBinding>
<KeyBinding Key="Enter" Modifiers="Ctrl+Shift" Command="{Binding OpenResultCommand}"></KeyBinding>
<KeyBinding Key="Enter" Modifiers="Shift" Command="{Binding LoadContextMenuCommand}"></KeyBinding>
<KeyBinding Key="Enter" Command="{Binding OpenResultCommand}"></KeyBinding>
<KeyBinding Key="Enter" Modifiers="Ctrl" Command="{Binding OpenResultCommand}"></KeyBinding>

View file

@ -1,8 +1,10 @@
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Plugin.SharedCommands;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace Flow.Launcher.Plugin.Explorer.Search
@ -127,7 +129,26 @@ namespace Flow.Launcher.Plugin.Explorer.Search
{
try
{
if (c.SpecialKeyState.CtrlPressed)
if (File.Exists(filePath) && c.SpecialKeyState.CtrlPressed && c.SpecialKeyState.ShiftPressed)
{
Task.Run(() =>
{
try
{
Process.Start(new ProcessStartInfo
{
FileName = filePath,
UseShellExecute = true,
Verb = "runas",
});
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Could not start " + filePath);
}
});
}
else if (c.SpecialKeyState.CtrlPressed)
{
FilesFolders.OpenContainingFolder(filePath);
}

View file

@ -102,16 +102,24 @@ namespace Flow.Launcher.Plugin.Program.Programs
Score = matchResult.Score,
TitleHighlightData = matchResult.MatchData,
ContextData = this,
Action = _ =>
Action = c =>
{
var runAsAdmin = (
c.SpecialKeyState.CtrlPressed &&
c.SpecialKeyState.ShiftPressed &&
!c.SpecialKeyState.AltPressed &&
!c.SpecialKeyState.WinPressed
);
var info = new ProcessStartInfo
{
FileName = LnkResolvedPath ?? FullPath,
WorkingDirectory = ParentDirectory,
UseShellExecute = true
UseShellExecute = true,
Verb = runAsAdmin ? "runas" : null
};
Main.StartProcess(Process.Start, info);
Task.Run(() => Main.StartProcess(Process.Start, info));
return true;
}