diff --git a/src/modules/espresso/Espresso/Core/TrayHelper.cs b/src/modules/espresso/Espresso/Core/TrayHelper.cs index 1d0472ee6e..fe03a731d1 100644 --- a/src/modules/espresso/Espresso/Core/TrayHelper.cs +++ b/src/modules/espresso/Espresso/Core/TrayHelper.cs @@ -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(text); currentSettings.Properties.Mode = EspressoMode.INDEFINITE; ModuleSettings.SaveSettings(JsonConvert.SerializeObject(currentSettings), text); }, - () => { + (hours, minutes) => { // Set timed keep awake. var currentSettings = ModuleSettings.GetSettings(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 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); diff --git a/src/modules/espresso/Espresso/Program.cs b/src/modules/espresso/Espresso/Program.cs index 8579c00baf..c9be92c806 100644 --- a/src/modules/espresso/Espresso/Program.cs +++ b/src/modules/espresso/Espresso/Program.cs @@ -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(); }