mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 19:19:23 +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
|
namespace Espresso.Shell.Core
|
||||||
{
|
{
|
||||||
[FlagsAttribute]
|
[Flags]
|
||||||
public enum EXECUTION_STATE : uint
|
public enum EXECUTION_STATE : uint
|
||||||
{
|
{
|
||||||
ES_AWAYMODE_REQUIRED = 0x00000040,
|
ES_AWAYMODE_REQUIRED = 0x00000040,
|
||||||
@ -32,7 +32,7 @@ namespace Espresso.Shell.Core
|
|||||||
private static CancellationTokenSource TokenSource = new CancellationTokenSource();
|
private static CancellationTokenSource TokenSource = new CancellationTokenSource();
|
||||||
private static CancellationToken ThreadToken;
|
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
|
// 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)]
|
[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)
|
public static Icon? Extract(string file, int number, bool largeIcon)
|
||||||
{
|
{
|
||||||
IntPtr large;
|
ExtractIconEx(file, number, out IntPtr large, out IntPtr small, 1);
|
||||||
IntPtr small;
|
|
||||||
ExtractIconEx(file, number, out large, out small, 1);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Icon.FromHandle(largeIcon ? large : small);
|
return Icon.FromHandle(largeIcon ? large : small);
|
||||||
|
@ -63,7 +63,7 @@ namespace Espresso.Shell.Core
|
|||||||
{
|
{
|
||||||
// Just changing the display mode.
|
// Just changing the display mode.
|
||||||
var currentSettings = ModuleSettings.GetSettings<EspressoSettings>(text);
|
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);
|
ModuleSettings.SaveSettings(JsonSerializer.Serialize(currentSettings), text);
|
||||||
});
|
});
|
||||||
@ -74,29 +74,43 @@ namespace Espresso.Shell.Core
|
|||||||
var contextMenuStrip = new ContextMenuStrip();
|
var contextMenuStrip = new ContextMenuStrip();
|
||||||
|
|
||||||
// Main toolstrip.
|
// Main toolstrip.
|
||||||
var operationContextMenu = new ToolStripMenuItem();
|
var operationContextMenu = new ToolStripMenuItem
|
||||||
operationContextMenu.Text = "Mode";
|
{
|
||||||
|
Text = "Mode"
|
||||||
|
};
|
||||||
|
|
||||||
// Indefinite keep-awake menu item.
|
// Indefinite keep-awake menu item.
|
||||||
var indefiniteMenuItem = new ToolStripMenuItem();
|
var indefiniteMenuItem = new ToolStripMenuItem
|
||||||
indefiniteMenuItem.Text = "Indefinite";
|
{
|
||||||
|
Text = "Indefinite"
|
||||||
|
};
|
||||||
|
|
||||||
if (mode == EspressoMode.INDEFINITE)
|
if (mode == EspressoMode.INDEFINITE)
|
||||||
{
|
{
|
||||||
indefiniteMenuItem.Checked = true;
|
indefiniteMenuItem.Checked = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
indefiniteMenuItem.Checked = false;
|
||||||
|
}
|
||||||
indefiniteMenuItem.Click += (e, s) =>
|
indefiniteMenuItem.Click += (e, s) =>
|
||||||
{
|
{
|
||||||
// User opted to set the mode to indefinite, so we need to write new settings.
|
// User opted to set the mode to indefinite, so we need to write new settings.
|
||||||
indefiniteKeepAwakeCallback();
|
indefiniteKeepAwakeCallback();
|
||||||
};
|
};
|
||||||
|
|
||||||
var displayOnMenuItem = new ToolStripMenuItem();
|
var displayOnMenuItem = new ToolStripMenuItem
|
||||||
displayOnMenuItem.Text = "Keep display on";
|
{
|
||||||
|
Text = "Keep display on"
|
||||||
|
};
|
||||||
if (keepDisplayOn)
|
if (keepDisplayOn)
|
||||||
{
|
{
|
||||||
displayOnMenuItem.Checked = true;
|
displayOnMenuItem.Checked = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
displayOnMenuItem.Checked = false;
|
||||||
|
}
|
||||||
displayOnMenuItem.Click += (e, s) =>
|
displayOnMenuItem.Click += (e, s) =>
|
||||||
{
|
{
|
||||||
// User opted to set the display mode directly.
|
// User opted to set the display mode directly.
|
||||||
@ -104,27 +118,35 @@ namespace Espresso.Shell.Core
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Timed keep-awake menu item
|
// Timed keep-awake menu item
|
||||||
var timedMenuItem = new ToolStripMenuItem();
|
var timedMenuItem = new ToolStripMenuItem
|
||||||
timedMenuItem.Text = "Timed";
|
{
|
||||||
|
Text = "Timed"
|
||||||
|
};
|
||||||
|
|
||||||
var halfHourMenuItem = new ToolStripMenuItem();
|
var halfHourMenuItem = new ToolStripMenuItem
|
||||||
halfHourMenuItem.Text = "30 minutes";
|
{
|
||||||
|
Text = "30 minutes"
|
||||||
|
};
|
||||||
halfHourMenuItem.Click += (e, s) =>
|
halfHourMenuItem.Click += (e, s) =>
|
||||||
{
|
{
|
||||||
// User is setting the keep-awake to 30 minutes.
|
// User is setting the keep-awake to 30 minutes.
|
||||||
timedKeepAwakeCallback(0, 30);
|
timedKeepAwakeCallback(0, 30);
|
||||||
};
|
};
|
||||||
|
|
||||||
var oneHourMenuItem = new ToolStripMenuItem();
|
var oneHourMenuItem = new ToolStripMenuItem
|
||||||
oneHourMenuItem.Text = "1 hour";
|
{
|
||||||
|
Text = "1 hour"
|
||||||
|
};
|
||||||
oneHourMenuItem.Click += (e, s) =>
|
oneHourMenuItem.Click += (e, s) =>
|
||||||
{
|
{
|
||||||
// User is setting the keep-awake to 1 hour.
|
// User is setting the keep-awake to 1 hour.
|
||||||
timedKeepAwakeCallback(1, 0);
|
timedKeepAwakeCallback(1, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
var twoHoursMenuItem = new ToolStripMenuItem();
|
var twoHoursMenuItem = new ToolStripMenuItem
|
||||||
twoHoursMenuItem.Text = "2 hours";
|
{
|
||||||
|
Text = "2 hours"
|
||||||
|
};
|
||||||
twoHoursMenuItem.Click += (e, s) =>
|
twoHoursMenuItem.Click += (e, s) =>
|
||||||
{
|
{
|
||||||
// User is setting the keep-awake to 2 hours.
|
// User is setting the keep-awake to 2 hours.
|
||||||
@ -142,6 +164,7 @@ namespace Espresso.Shell.Core
|
|||||||
|
|
||||||
contextMenuStrip.Items.Add(operationContextMenu);
|
contextMenuStrip.Items.Add(operationContextMenu);
|
||||||
|
|
||||||
|
TrayIcon.Text = text;
|
||||||
TrayIcon.ContextMenuStrip = contextMenuStrip;
|
TrayIcon.ContextMenuStrip = contextMenuStrip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,9 +230,6 @@ namespace Espresso.Shell
|
|||||||
|
|
||||||
if (settings != null)
|
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)
|
switch (settings.Properties.Mode)
|
||||||
{
|
{
|
||||||
case EspressoMode.INDEFINITE:
|
case EspressoMode.INDEFINITE:
|
||||||
|
Loading…
Reference in New Issue
Block a user