mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 13:35:31 +02:00
Add Program Plugin
This commit is contained in:
@@ -23,10 +23,12 @@ namespace WinAlfred.Plugin.System
|
||||
Action = () =>
|
||||
{
|
||||
Process process = new Process();
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo();
|
||||
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
startInfo.FileName = "cmd.exe";
|
||||
startInfo.Arguments = "/C " + cmd;
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||
{
|
||||
WindowStyle = ProcessWindowStyle.Normal,
|
||||
FileName = "cmd.exe",
|
||||
Arguments = "/C " + cmd
|
||||
};
|
||||
process.StartInfo = startInfo;
|
||||
process.Start();
|
||||
}
|
||||
|
||||
106
WinAlfred.Plugin.System/Programs.cs
Normal file
106
WinAlfred.Plugin.System/Programs.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace WinAlfred.Plugin.System
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string IcoPath { get; set; }
|
||||
public string ExecutePath { get; set; }
|
||||
}
|
||||
|
||||
public class Programs : ISystemPlugin
|
||||
{
|
||||
List<Program> installedList = new List<Program>();
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.Length <= 1) return new List<Result>();
|
||||
|
||||
return installedList.Where(o => o.Title.ToLower().Contains(query.RawQuery.ToLower())).Select(c => new Result()
|
||||
{
|
||||
Title = c.Title,
|
||||
IcoPath = c.IcoPath,
|
||||
Score = 10,
|
||||
Action = () =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(c.ExecutePath))
|
||||
{
|
||||
MessageBox.Show("couldn't start" + c.Title);
|
||||
}
|
||||
else
|
||||
{
|
||||
Process.Start(c.ExecutePath);
|
||||
}
|
||||
}
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
GetAppFromStartMenu();
|
||||
}
|
||||
|
||||
private void GetAppFromStartMenu()
|
||||
{
|
||||
List<string> path =
|
||||
Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.Programs)).ToList();
|
||||
foreach (string s in path)
|
||||
{
|
||||
GetAppFromDirectory(s);
|
||||
}
|
||||
}
|
||||
|
||||
private void GetAppFromDirectory(string path)
|
||||
{
|
||||
foreach (string file in Directory.GetFiles(path))
|
||||
{
|
||||
if (file.EndsWith(".lnk") || file.EndsWith(".exe"))
|
||||
{
|
||||
Program p = new Program()
|
||||
{
|
||||
Title = getAppNameFromAppPath(file),
|
||||
IcoPath = file,
|
||||
ExecutePath = file
|
||||
};
|
||||
installedList.Add(p);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var subDirectory in Directory.GetDirectories(path))
|
||||
{
|
||||
GetAppFromDirectory(subDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
private string getAppNameFromAppPath(string app)
|
||||
{
|
||||
string temp = app.Substring(app.LastIndexOf('\\') + 1);
|
||||
string name = temp.Substring(0, temp.LastIndexOf('.'));
|
||||
return name;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Programs";
|
||||
}
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return "get system programs";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,12 @@ namespace WinAlfred.Plugin.System
|
||||
{
|
||||
List<Result> availableResults = new List<Result>();
|
||||
|
||||
internal const int EWX_LOGOFF = 0x00000000;
|
||||
internal const int EWX_SHUTDOWN = 0x00000001;
|
||||
internal const int EWX_REBOOT = 0x00000002;
|
||||
internal const int EWX_FORCE = 0x00000004;
|
||||
internal const int EWX_POWEROFF = 0x00000008;
|
||||
internal const int EWX_FORCEIFHUNG = 0x00000010;
|
||||
[DllImport("user32")]
|
||||
public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
|
||||
[DllImport("user32")]
|
||||
@@ -37,14 +43,16 @@ namespace WinAlfred.Plugin.System
|
||||
Title = "Shutdown",
|
||||
SubTitle = "Shutdown Computer",
|
||||
Score = 100,
|
||||
Action = () => MessageBox.Show("shutdown")
|
||||
IcoPath = "Images\\exit.png",
|
||||
Action = () => ExitWindowsEx(EWX_SHUTDOWN,0)
|
||||
});
|
||||
availableResults.Add(new Result
|
||||
{
|
||||
Title = "Log off",
|
||||
SubTitle = "Log off current user",
|
||||
Score = 10,
|
||||
Action = () => MessageBox.Show("Logoff")
|
||||
Score = 20,
|
||||
IcoPath = "Images\\logoff.png",
|
||||
Action = () => ExitWindowsEx(EWX_LOGOFF, 0)
|
||||
});
|
||||
availableResults.Add(new Result
|
||||
{
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="CMD.cs" />
|
||||
<Compile Include="ISystemPlugin.cs" />
|
||||
<Compile Include="Programs.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Sys.cs" />
|
||||
<Compile Include="ThirdpartyPluginIndicator.cs" />
|
||||
|
||||
Reference in New Issue
Block a user