mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-12 18:29:24 +08:00
Updating how the tray works
This commit is contained in:
parent
bd8decdfc8
commit
8013664eef
@ -27,7 +27,7 @@ namespace Espresso.Shell.Core
|
||||
ModuleSettings = new SettingsUtils();
|
||||
}
|
||||
|
||||
public static void InitializeTray(string text, Icon icon, ContextMenuStrip? contextMenu)
|
||||
public static void InitializeTray(string text, Icon icon, ContextMenuStrip? contextMenu = null)
|
||||
{
|
||||
System.Threading.Tasks.Task.Factory.StartNew((tray) =>
|
||||
{
|
||||
@ -42,19 +42,19 @@ namespace Espresso.Shell.Core
|
||||
|
||||
internal static void SetTray(string text, EspressoSettings settings)
|
||||
{
|
||||
SetTray(text, settings.Properties.KeepDisplayOn.Value, settings.Properties.Mode, settings.Properties.Hours.Value, settings.Properties.Minutes.Value,
|
||||
SetTray(text, settings.Properties.KeepDisplayOn.Value, settings.Properties.Mode,
|
||||
() => {
|
||||
// Set indefinite keep awake.
|
||||
var currentSettings = ModuleSettings.GetSettings<EspressoSettings>(text);
|
||||
currentSettings.Properties.Mode = EspressoMode.INDEFINITE;
|
||||
ModuleSettings.SaveSettings(JsonConvert.SerializeObject(currentSettings), text);
|
||||
},
|
||||
() => {
|
||||
(hours, minutes) => {
|
||||
// Set timed keep awake.
|
||||
var currentSettings = ModuleSettings.GetSettings<EspressoSettings>(text);
|
||||
currentSettings.Properties.Mode = EspressoMode.TIMED;
|
||||
currentSettings.Properties.Hours.Value = settings.Properties.Hours.Value;
|
||||
currentSettings.Properties.Minutes.Value = settings.Properties.Minutes.Value;
|
||||
currentSettings.Properties.Hours.Value = hours;
|
||||
currentSettings.Properties.Minutes.Value = minutes;
|
||||
|
||||
ModuleSettings.SaveSettings(JsonConvert.SerializeObject(currentSettings), text);
|
||||
},
|
||||
@ -68,7 +68,7 @@ namespace Espresso.Shell.Core
|
||||
});
|
||||
}
|
||||
|
||||
internal static void SetTray(string text, bool keepDisplayOn, EspressoMode mode, int hours, int minutes, Action indefiniteKeepAwakeCallback, Action timedKeepAwakeCallback, Action keepDisplayOnCallback)
|
||||
internal static void SetTray(string text, bool keepDisplayOn, EspressoMode mode, Action indefiniteKeepAwakeCallback, Action<int, int> timedKeepAwakeCallback, Action keepDisplayOnCallback)
|
||||
{
|
||||
var contextMenuStrip = new ContextMenuStrip();
|
||||
|
||||
@ -111,7 +111,7 @@ namespace Espresso.Shell.Core
|
||||
halfHourMenuItem.Click += (e, s) =>
|
||||
{
|
||||
// User is setting the keep-awake to 30 minutes.
|
||||
timedKeepAwakeCallback();
|
||||
timedKeepAwakeCallback(0, 30);
|
||||
};
|
||||
|
||||
var oneHourMenuItem = new ToolStripMenuItem();
|
||||
@ -119,7 +119,7 @@ namespace Espresso.Shell.Core
|
||||
oneHourMenuItem.Click += (e, s) =>
|
||||
{
|
||||
// User is setting the keep-awake to 1 hour.
|
||||
timedKeepAwakeCallback();
|
||||
timedKeepAwakeCallback(1, 0);
|
||||
};
|
||||
|
||||
var twoHoursMenuItem = new ToolStripMenuItem();
|
||||
@ -127,7 +127,7 @@ namespace Espresso.Shell.Core
|
||||
twoHoursMenuItem.Click += (e, s) =>
|
||||
{
|
||||
// User is setting the keep-awake to 2 hours.
|
||||
timedKeepAwakeCallback();
|
||||
timedKeepAwakeCallback(2, 0);
|
||||
};
|
||||
|
||||
timedMenuItem.DropDownItems.Add(halfHourMenuItem);
|
||||
|
@ -134,6 +134,10 @@ namespace Espresso.Shell
|
||||
log.Info($"The value for --time-limit is: {timeLimit}");
|
||||
log.Info($"The value for --pid is: {pid}");
|
||||
|
||||
#pragma warning disable CS8604 // Possible null reference argument.
|
||||
TrayHelper.InitializeTray(appName, APIHelper.Extract("shell32.dll", 32, true));
|
||||
#pragma warning restore CS8604 // Possible null reference argument.
|
||||
|
||||
if (usePtConfig)
|
||||
{
|
||||
// Configuration file is used, therefore we disregard any other command-line parameter
|
||||
@ -192,10 +196,6 @@ namespace Espresso.Shell
|
||||
});
|
||||
}
|
||||
|
||||
#pragma warning disable CS8604 // Possible null reference argument.
|
||||
TrayHelper.InitializeTray(appName, APIHelper.Extract("shell32.dll", 21, true), null);
|
||||
#pragma warning restore CS8604 // Possible null reference argument.
|
||||
|
||||
new ManualResetEvent(false).WaitOne();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user