This commit is contained in:
yuyoyuppe
2022-09-13 17:14:13 +02:00
parent 88452054b0
commit adfc1e1f69
4 changed files with 10 additions and 10 deletions

View File

@@ -43,7 +43,7 @@ public partial class App : Application, IDisposable
{ {
Logger.LogWarning("Another running TextExtractor instance was detected. Exiting TextExtractor"); Logger.LogWarning("Another running TextExtractor instance was detected. Exiting TextExtractor");
_instanceMutex = null; _instanceMutex = null;
Dispatcher.Invoke(() => Shutdown()); Shutdown();
return; return;
} }

View File

@@ -210,7 +210,7 @@ namespace Awake.Core
try try
{ {
exitSignal?.Set(); exitSignal?.Set();
Application.Current.Shutdown(); PInvoke.DestroyWindow(windowHandle);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -2,6 +2,7 @@ AllocConsole
CreateFile CreateFile
CreatePopupMenu CreatePopupMenu
DestroyMenu DestroyMenu
DestroyWindow
FindWindowEx FindWindowEx
GetClassName GetClassName
GetCurrentThreadId GetCurrentThreadId

View File

@@ -19,6 +19,7 @@ using Awake.Core;
using interop; using interop;
using ManagedCommon; using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Telemetry.Events;
using NLog; using NLog;
using Windows.Win32; using Windows.Win32;
using Windows.Win32.Foundation; using Windows.Win32.Foundation;
@@ -89,7 +90,7 @@ namespace Awake
_log.Info("Parsing parameters..."); _log.Info("Parsing parameters...");
Option<bool>? configOption = new ( var configOption = new Option<bool>(
aliases: new[] { "--use-pt-config", "-c" }, aliases: new[] { "--use-pt-config", "-c" },
getDefaultValue: () => false, getDefaultValue: () => false,
description: $"Specifies whether {InternalConstants.AppName} will be using the PowerToys configuration file for managing the state.") description: $"Specifies whether {InternalConstants.AppName} will be using the PowerToys configuration file for managing the state.")
@@ -102,7 +103,7 @@ namespace Awake
configOption.Required = false; configOption.Required = false;
Option<bool>? displayOption = new ( var displayOption = new Option<bool>(
aliases: new[] { "--display-on", "-d" }, aliases: new[] { "--display-on", "-d" },
getDefaultValue: () => true, getDefaultValue: () => true,
description: "Determines whether the display should be kept awake.") description: "Determines whether the display should be kept awake.")
@@ -115,7 +116,7 @@ namespace Awake
displayOption.Required = false; displayOption.Required = false;
Option<uint>? timeOption = new ( var timeOption = new Option<uint>(
aliases: new[] { "--time-limit", "-t" }, aliases: new[] { "--time-limit", "-t" },
getDefaultValue: () => 0, getDefaultValue: () => 0,
description: "Determines the interval, in seconds, during which the computer is kept awake.") description: "Determines the interval, in seconds, during which the computer is kept awake.")
@@ -128,7 +129,7 @@ namespace Awake
timeOption.Required = false; timeOption.Required = false;
Option<int>? pidOption = new ( var pidOption = new Option<int>(
aliases: new[] { "--pid", "-p" }, aliases: new[] { "--pid", "-p" },
getDefaultValue: () => 0, getDefaultValue: () => 0,
description: $"Bind the execution of {InternalConstants.AppName} to another process.") description: $"Bind the execution of {InternalConstants.AppName} to another process.")
@@ -194,16 +195,14 @@ namespace Awake
// and instead watch for changes in the file. // and instead watch for changes in the file.
try try
{ {
// TODO: native event handler var eventHandle = new EventWaitHandle(false, EventResetMode.ManualReset, Constants.AwakeExitEvent());
new Thread(() => new Thread(() =>
{ {
EventWaitHandle? eventHandle = new EventWaitHandle(false, EventResetMode.ManualReset, Constants.AwakeExitEvent()); if (WaitHandle.WaitAny(new WaitHandle[] { _exitSignal, eventHandle }) == 1)
if (eventHandle.WaitOne())
{ {
Exit("Received a signal to end the process. Making sure we quit...", 0, _exitSignal, true); Exit("Received a signal to end the process. Making sure we quit...", 0, _exitSignal, true);
} }
}).Start(); }).Start();
TrayHelper.InitializeTray(InternalConstants.FullAppName, new Icon("modules/awake/images/awake.ico"), _exitSignal); TrayHelper.InitializeTray(InternalConstants.FullAppName, new Icon("modules/awake/images/awake.ico"), _exitSignal);
string? settingsPath = _settingsUtils.GetSettingsFilePath(InternalConstants.AppName); string? settingsPath = _settingsUtils.GetSettingsFilePath(InternalConstants.AppName);