mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Forgot to add Files
This commit is contained in:
163
Wox.Plugin.SystemPlugins/Sys/Sys.cs
Normal file
163
Wox.Plugin.SystemPlugins/Sys/Sys.cs
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace Wox.Plugin.SystemPlugins.Sys
|
||||||
|
{
|
||||||
|
public class Sys : BaseSystemPlugin, ISettingProvider
|
||||||
|
{
|
||||||
|
List<Result> availableResults = new List<Result>();
|
||||||
|
|
||||||
|
#region DllImport
|
||||||
|
|
||||||
|
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")]
|
||||||
|
private static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
|
||||||
|
[DllImport("user32")]
|
||||||
|
private static extern void LockWorkStation();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Overrides
|
||||||
|
|
||||||
|
public override string ID
|
||||||
|
{
|
||||||
|
get { return "CEA08895D2544B019B2E9C5009600DF4"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Name
|
||||||
|
{
|
||||||
|
get { return "System Commands"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string IcoPath
|
||||||
|
{
|
||||||
|
get { return @"Images\lock.png"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Description
|
||||||
|
{
|
||||||
|
get { return "Provide System related commands. e.g. shutdown,lock,setting etc."; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
public System.Windows.Controls.Control CreateSettingPanel()
|
||||||
|
{
|
||||||
|
return new SysSettings(availableResults);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected override List<Result> QueryInternal(Query query)
|
||||||
|
{
|
||||||
|
if (query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
|
||||||
|
|
||||||
|
List<Result> results = new List<Result>();
|
||||||
|
|
||||||
|
foreach (Result availableResult in availableResults)
|
||||||
|
{
|
||||||
|
if (availableResult.Title.ToLower().StartsWith(query.RawQuery.ToLower()))
|
||||||
|
{
|
||||||
|
results.Add(availableResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void InitInternal(PluginInitContext context)
|
||||||
|
{
|
||||||
|
availableResults.AddRange(new Result[] {
|
||||||
|
new Result
|
||||||
|
{
|
||||||
|
Title = "Shutdown",
|
||||||
|
SubTitle = "Shutdown Computer",
|
||||||
|
Score = 100,
|
||||||
|
IcoPath = "Images\\exit.png",
|
||||||
|
Action = (c) =>
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Are you sure you want to shut the computer down?","Shutdown Computer?",MessageBoxButtons.YesNo,MessageBoxIcon.Warning) == DialogResult.Yes) {
|
||||||
|
Process.Start("shutdown", "/s /t 0");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new Result
|
||||||
|
{
|
||||||
|
Title = "Log off",
|
||||||
|
SubTitle = "Log off current user",
|
||||||
|
Score = 20,
|
||||||
|
IcoPath = "Images\\logoff.png",
|
||||||
|
Action = (c) => ExitWindowsEx(EWX_LOGOFF, 0)
|
||||||
|
},
|
||||||
|
new Result
|
||||||
|
{
|
||||||
|
Title = "Lock",
|
||||||
|
SubTitle = "Lock this computer",
|
||||||
|
Score = 20,
|
||||||
|
IcoPath = "Images\\lock.png",
|
||||||
|
Action = (c) =>
|
||||||
|
{
|
||||||
|
LockWorkStation();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new Result
|
||||||
|
{
|
||||||
|
Title = "Exit",
|
||||||
|
SubTitle = "Close this app",
|
||||||
|
Score = 110,
|
||||||
|
IcoPath = "Images\\app.png",
|
||||||
|
Action = (c) =>
|
||||||
|
{
|
||||||
|
context.API.CloseApp();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new Result
|
||||||
|
{
|
||||||
|
Title = "Restart Wox",
|
||||||
|
SubTitle = "Restart Wox",
|
||||||
|
Score = 110,
|
||||||
|
IcoPath = "Images\\restart.png",
|
||||||
|
Action = (c) =>
|
||||||
|
{
|
||||||
|
ProcessStartInfo Info = new ProcessStartInfo();
|
||||||
|
Info.Arguments = "/C ping 127.0.0.1 -n 1 && \"" + Application.ExecutablePath + "\"";
|
||||||
|
Info.WindowStyle = ProcessWindowStyle.Hidden;
|
||||||
|
Info.CreateNoWindow = true;
|
||||||
|
Info.FileName = "cmd.exe";
|
||||||
|
Process.Start(Info);
|
||||||
|
context.API.CloseApp();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new Result
|
||||||
|
{
|
||||||
|
Title = "Settings",
|
||||||
|
SubTitle = "Tweak this app",
|
||||||
|
Score = 40,
|
||||||
|
IcoPath = "Images\\app.png",
|
||||||
|
Action = (c) =>
|
||||||
|
{
|
||||||
|
context.API.OpenSettingDialog();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
31
Wox.Plugin.SystemPlugins/Sys/SysSettings.xaml
Normal file
31
Wox.Plugin.SystemPlugins/Sys/SysSettings.xaml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<UserControl x:Class="Wox.Plugin.SystemPlugins.Sys.SysSettings"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="300" d:DesignWidth="300">
|
||||||
|
<Grid>
|
||||||
|
<ListView x:Name="lbxCommands" Grid.Row="0">
|
||||||
|
<ListView.View>
|
||||||
|
<GridView>
|
||||||
|
<GridViewColumn Header="Title" Width="Auto">
|
||||||
|
<GridViewColumn.CellTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding Title}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</GridViewColumn.CellTemplate>
|
||||||
|
</GridViewColumn>
|
||||||
|
<GridViewColumn Header="Description" Width="Auto">
|
||||||
|
<GridViewColumn.CellTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding SubTitle}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</GridViewColumn.CellTemplate>
|
||||||
|
</GridViewColumn>
|
||||||
|
</GridView>
|
||||||
|
</ListView.View>
|
||||||
|
</ListView>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
28
Wox.Plugin.SystemPlugins/Sys/SysSettings.xaml.cs
Normal file
28
Wox.Plugin.SystemPlugins/Sys/SysSettings.xaml.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace Wox.Plugin.SystemPlugins.Sys {
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for SysSettings.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class SysSettings : UserControl {
|
||||||
|
public SysSettings(List<Result> Results) {
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
foreach (var Result in Results) {
|
||||||
|
this.lbxCommands.Items.Add(Result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user