PowerToys/WinAlfred.Plugin.System/Sys.cs

79 lines
2.6 KiB
C#
Raw Normal View History

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