[Awake] Context menu bug fixes (#16903)

* Fix the path to the icon

* Need the reverse when not working in isolation

* Updating some tray behaviors

* Making sure we have constants separately, and a filter

* Update tray logic

* Remove unnecessary menus

* Cleaning up how exit is done.

* Adding handling for tray commands

* Update with settings for dynamic times

* Proper reaction to timed keep-awake from the tray

* Proper handling for timed keep-awake from the tray

* Making sure that code analysis works correctly

* Making sure that errors are set in native calls

* Making sure the right icon path is used after testing

* Proper disposal of the context menu

* Fix tray designation

* Update with latest information on changes to the builds

* Update with guidance on files

* Update changelog doc

* Fix project file

* Remove `VTABLE`
This commit is contained in:
Den Delimarsky
2022-03-23 07:46:37 -07:00
committed by GitHub
parent ada3a9ad88
commit d7617a47d3
14 changed files with 498 additions and 256 deletions

View File

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Diagnostics;
@@ -14,6 +15,7 @@ using System.Reactive.Linq;
using System.Reflection;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Awake.Core;
using Awake.Core.Models;
using interop;
@@ -72,6 +74,12 @@ namespace Awake
_log.Info($"OS: {Environment.OSVersion}");
_log.Info($"OS Build: {APIHelper.GetOperatingSystemBuild()}");
TaskScheduler.UnobservedTaskException += (sender, args) =>
{
Trace.WriteLine($"Task scheduler error: {args.Exception.Message}"); // somebody forgot to check!
args.SetObserved();
};
// To make it easier to diagnose future issues, let's get the
// system power capabilities and aggregate them in the log.
NativeMethods.GetPwrCapabilities(out _powerCapabilities);
@@ -159,18 +167,7 @@ namespace Awake
{
_log.Info(message);
APIHelper.SetNoKeepAwake();
TrayHelper.ClearTray();
// Because we are running a message loop for the tray, we can't just use Environment.Exit,
// but have to make sure that we properly send the termination message.
bool cwResult = System.Diagnostics.Process.GetCurrentProcess().CloseMainWindow();
_log.Info($"Request to close main window status: {cwResult}");
if (force)
{
Environment.Exit(exitCode);
}
APIHelper.CompleteExit(exitCode, force);
}
private static void HandleCommandLineArguments(bool usePtConfig, bool displayOn, uint timeLimit, int pid)
@@ -204,7 +201,7 @@ namespace Awake
}
}).Start();
TrayHelper.InitializeTray(InternalConstants.FullAppName, new Icon("modules/Awake/Images/Awake.ico"));
TrayHelper.InitializeTray(InternalConstants.FullAppName, new Icon("modules/awake/images/awake.ico"));
string? settingsPath = _settingsUtils.GetSettingsFilePath(InternalConstants.AppName);
_log.Info($"Reading configuration file: {settingsPath}");
@@ -293,6 +290,8 @@ namespace Awake
if (settings != null)
{
_log.Info($"Identified custom time shortcuts for the tray: {settings.Properties.TrayTimeShortcuts.Count}");
switch (settings.Properties.Mode)
{
case AwakeMode.PASSIVE: