PowerToys/WinAlfred.Plugin.System/Sys.cs

79 lines
2.6 KiB
C#
Raw Normal View History

2013-12-22 00:44:56 +08:00
using System;
using System.Collections.Generic;
2014-01-06 22:21:08 +08:00
using System.Diagnostics;
2013-12-22 00:44:56 +08:00
using System.Linq;
2013-12-22 19:35:21 +08:00
using System.Runtime.InteropServices;
2013-12-22 00:44:56 +08:00
using System.Text;
2013-12-22 19:35:21 +08:00
using System.Windows.Forms;
2013-12-22 00:44:56 +08:00
namespace WinAlfred.Plugin.System
{
2014-01-15 22:45:02 +08:00
public class Sys : BaseSystemPlugin
2013-12-22 00:44:56 +08:00
{
2013-12-22 19:35:21 +08:00
List<Result> availableResults = new List<Result>();
2014-01-04 20:26:13 +08:00
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;
2013-12-22 19:35:21 +08:00
[DllImport("user32")]
public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
[DllImport("user32")]
public static extern void LockWorkStation();
2013-12-22 00:44:56 +08:00
2014-01-15 22:45:02 +08:00
protected override List<Result> QueryInternal(Query query)
2013-12-22 00:44:56 +08:00
{
2014-01-07 19:27:51 +08:00
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
2013-12-22 19:35:21 +08:00
List<Result> results = new List<Result>();
2014-01-03 23:52:36 +08:00
foreach (Result availableResult in availableResults)
2013-12-22 19:35:21 +08:00
{
2014-01-03 23:52:36 +08:00
if (availableResult.Title.ToLower().StartsWith(query.RawQuery.ToLower()))
{
results.Add(availableResult);
}
2013-12-22 00:44:56 +08:00
}
return results;
}
2014-01-15 22:45:02 +08:00
protected override void InitInternal(PluginInitContext context)
2013-12-22 00:44:56 +08:00
{
2013-12-22 19:35:21 +08:00
availableResults.Add(new Result
{
Title = "Shutdown",
SubTitle = "Shutdown Computer",
Score = 100,
2014-01-04 20:26:13 +08:00
IcoPath = "Images\\exit.png",
2014-01-06 22:21:08 +08:00
Action = () => Process.Start("shutdown","/s /t 0")
2013-12-22 19:35:21 +08:00
});
availableResults.Add(new Result
{
Title = "Log off",
SubTitle = "Log off current user",
2014-01-04 20:26:13 +08:00
Score = 20,
IcoPath = "Images\\logoff.png",
Action = () => ExitWindowsEx(EWX_LOGOFF, 0)
2013-12-22 19:35:21 +08:00
});
availableResults.Add(new Result
{
Title = "Lock",
SubTitle = "Lock this computer",
Score = 20,
IcoPath = "Images\\lock.png",
Action = () => LockWorkStation()
2014-01-03 23:52:36 +08:00
});
2014-01-05 17:56:02 +08:00
availableResults.Add(new Result
{
Title = "Exit",
SubTitle = "Close this app",
Score = 110,
IcoPath = "Images\\app.png",
2014-01-05 17:56:02 +08:00
Action = () => context.CloseApp()
});
2014-01-03 23:52:36 +08:00
}
2013-12-22 00:44:56 +08:00
}
}