PowerToys/WinAlfred.Plugin.System/Sys.cs

95 lines
2.8 KiB
C#
Raw Normal View History

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