Skip to content
This repository has been archived by the owner on Feb 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #105 from jjw24/add_folderplugin_runasuser
Browse files Browse the repository at this point in the history
Add run as different user option when file is of certain type
  • Loading branch information
jjw24 authored Dec 15, 2019
2 parents 725eee7 + c279f40 commit 0d0aa49
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using Wox.Infrastructure.Logger;
using Wox.Plugin.SharedCommands;

namespace Wox.Plugin.Folder
{
Expand Down Expand Up @@ -100,6 +102,27 @@ public List<Result> LoadContextMenus(Result selectedResult)
IcoPath = icoPath
});

if (record.Type == ResultType.File && CanRunAsDifferentUser(record.FullPath))
contextMenus.Add(new Result
{
Title = "Run as different user",
Action = (context) =>
{
try
{
Task.Run(()=> ShellCommand.RunAsDifferentUser(record.FullPath.SetProcessStartInfo()));
}
catch (FileNotFoundException e)
{
var name = "Plugin: Folder";
var message = $"File not found: {e.Message}";
_context.API.ShowMsg(name, message);
}
return true;
},
IcoPath = "Images/user.png"
});
}

return contextMenus;
Expand Down Expand Up @@ -162,6 +185,20 @@ public void LogException(string message, Exception e)
{
Log.Exception($"|Wox.Plugin.Folder.ContextMenu|{message}", e);
}

private bool CanRunAsDifferentUser(string path)
{
switch(Path.GetExtension(path))
{
case ".exe":
case ".bat":
return true;

default:
return false;

}
}
}

public class SearchResult
Expand Down
Binary file added Plugins/Wox.Plugin.Folder/Images/user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
<Content Include="Images\file.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Images\user.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="Languages\en.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down

0 comments on commit 0d0aa49

Please sign in to comment.