mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-12 18:29:24 +08:00
Code cleanup
This commit is contained in:
parent
4a46619857
commit
c2f1cbf867
@ -12,7 +12,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Espresso.Shell.Core
|
||||
{
|
||||
[FlagsAttribute]
|
||||
[Flags]
|
||||
public enum EXECUTION_STATE : uint
|
||||
{
|
||||
ES_AWAYMODE_REQUIRED = 0x00000040,
|
||||
@ -32,7 +32,7 @@ namespace Espresso.Shell.Core
|
||||
private static CancellationTokenSource TokenSource = new CancellationTokenSource();
|
||||
private static CancellationToken ThreadToken;
|
||||
|
||||
private static Logger log;
|
||||
private static readonly Logger log;
|
||||
|
||||
// More details about the API used: https://docs.microsoft.com/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
@ -191,9 +191,7 @@ namespace Espresso.Shell.Core
|
||||
|
||||
public static Icon? Extract(string file, int number, bool largeIcon)
|
||||
{
|
||||
IntPtr large;
|
||||
IntPtr small;
|
||||
ExtractIconEx(file, number, out large, out small, 1);
|
||||
ExtractIconEx(file, number, out IntPtr large, out IntPtr small, 1);
|
||||
try
|
||||
{
|
||||
return Icon.FromHandle(largeIcon ? large : small);
|
||||
|
@ -63,7 +63,7 @@ namespace Espresso.Shell.Core
|
||||
{
|
||||
// Just changing the display mode.
|
||||
var currentSettings = ModuleSettings.GetSettings<EspressoSettings>(text);
|
||||
currentSettings.Properties.KeepDisplayOn = settings.Properties.KeepDisplayOn;
|
||||
currentSettings.Properties.KeepDisplayOn.Value = !currentSettings.Properties.KeepDisplayOn.Value;
|
||||
|
||||
ModuleSettings.SaveSettings(JsonSerializer.Serialize(currentSettings), text);
|
||||
});
|
||||
@ -74,29 +74,43 @@ namespace Espresso.Shell.Core
|
||||
var contextMenuStrip = new ContextMenuStrip();
|
||||
|
||||
// Main toolstrip.
|
||||
var operationContextMenu = new ToolStripMenuItem();
|
||||
operationContextMenu.Text = "Mode";
|
||||
var operationContextMenu = new ToolStripMenuItem
|
||||
{
|
||||
Text = "Mode"
|
||||
};
|
||||
|
||||
// Indefinite keep-awake menu item.
|
||||
var indefiniteMenuItem = new ToolStripMenuItem();
|
||||
indefiniteMenuItem.Text = "Indefinite";
|
||||
var indefiniteMenuItem = new ToolStripMenuItem
|
||||
{
|
||||
Text = "Indefinite"
|
||||
};
|
||||
|
||||
if (mode == EspressoMode.INDEFINITE)
|
||||
{
|
||||
indefiniteMenuItem.Checked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
indefiniteMenuItem.Checked = false;
|
||||
}
|
||||
indefiniteMenuItem.Click += (e, s) =>
|
||||
{
|
||||
// User opted to set the mode to indefinite, so we need to write new settings.
|
||||
indefiniteKeepAwakeCallback();
|
||||
};
|
||||
|
||||
var displayOnMenuItem = new ToolStripMenuItem();
|
||||
displayOnMenuItem.Text = "Keep display on";
|
||||
var displayOnMenuItem = new ToolStripMenuItem
|
||||
{
|
||||
Text = "Keep display on"
|
||||
};
|
||||
if (keepDisplayOn)
|
||||
{
|
||||
displayOnMenuItem.Checked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
displayOnMenuItem.Checked = false;
|
||||
}
|
||||
displayOnMenuItem.Click += (e, s) =>
|
||||
{
|
||||
// User opted to set the display mode directly.
|
||||
@ -104,27 +118,35 @@ namespace Espresso.Shell.Core
|
||||
};
|
||||
|
||||
// Timed keep-awake menu item
|
||||
var timedMenuItem = new ToolStripMenuItem();
|
||||
timedMenuItem.Text = "Timed";
|
||||
var timedMenuItem = new ToolStripMenuItem
|
||||
{
|
||||
Text = "Timed"
|
||||
};
|
||||
|
||||
var halfHourMenuItem = new ToolStripMenuItem();
|
||||
halfHourMenuItem.Text = "30 minutes";
|
||||
var halfHourMenuItem = new ToolStripMenuItem
|
||||
{
|
||||
Text = "30 minutes"
|
||||
};
|
||||
halfHourMenuItem.Click += (e, s) =>
|
||||
{
|
||||
// User is setting the keep-awake to 30 minutes.
|
||||
timedKeepAwakeCallback(0, 30);
|
||||
};
|
||||
|
||||
var oneHourMenuItem = new ToolStripMenuItem();
|
||||
oneHourMenuItem.Text = "1 hour";
|
||||
var oneHourMenuItem = new ToolStripMenuItem
|
||||
{
|
||||
Text = "1 hour"
|
||||
};
|
||||
oneHourMenuItem.Click += (e, s) =>
|
||||
{
|
||||
// User is setting the keep-awake to 1 hour.
|
||||
timedKeepAwakeCallback(1, 0);
|
||||
};
|
||||
|
||||
var twoHoursMenuItem = new ToolStripMenuItem();
|
||||
twoHoursMenuItem.Text = "2 hours";
|
||||
var twoHoursMenuItem = new ToolStripMenuItem
|
||||
{
|
||||
Text = "2 hours"
|
||||
};
|
||||
twoHoursMenuItem.Click += (e, s) =>
|
||||
{
|
||||
// User is setting the keep-awake to 2 hours.
|
||||
@ -142,6 +164,7 @@ namespace Espresso.Shell.Core
|
||||
|
||||
contextMenuStrip.Items.Add(operationContextMenu);
|
||||
|
||||
TrayIcon.Text = text;
|
||||
TrayIcon.ContextMenuStrip = contextMenuStrip;
|
||||
}
|
||||
}
|
||||
|
@ -230,9 +230,6 @@ namespace Espresso.Shell
|
||||
|
||||
if (settings != null)
|
||||
{
|
||||
// If the settings were successfully processed, we need to set the right mode of operation.
|
||||
// INDEFINITE = 0
|
||||
// TIMED = 1
|
||||
switch (settings.Properties.Mode)
|
||||
{
|
||||
case EspressoMode.INDEFINITE:
|
||||
|
Loading…
Reference in New Issue
Block a user