🧼 PowerToys Awake (#11593)

* Scrubbing name conventions

* Fix naming for projects

* Fix folder naming

* More folder cleanup

* More left-over file changes

* Reverting LCL files, because these will be handled by the loc team

* Remove legacy file that is no longer used.

* Update latest
This commit is contained in:
Den Delimarsky
2021-06-09 09:13:58 -07:00
committed by GitHub
parent c9c54b7780
commit c5e464a704
49 changed files with 272 additions and 271 deletions

View File

@@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\modules\Espresso</OutputPath>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\modules\Awake</OutputPath>
<Nullable>enable</Nullable>
<Platforms>x64</Platforms>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
@@ -11,9 +11,9 @@
<UseWindowsForms>true</UseWindowsForms>
<!--Per documentation: https://docs.microsoft.com/dotnet/core/compatibility/windows-forms/5.0/automatically-infer-winexe-output-type#outputtype-set-to-winexe-for-wpf-and-winforms-apps -->
<DisableWinExeOutputInference>true</DisableWinExeOutputInference>
<AssemblyName>PowerToys.Espresso</AssemblyName>
<AssemblyName>PowerToys.Awake</AssemblyName>
<Version>$(Version).0</Version>
<ApplicationIcon>Images\Espresso.ico</ApplicationIcon>
<ApplicationIcon>Images\Awake.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -78,6 +78,6 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Espresso.ico" />
<Resource Include="Images\Awake.ico" />
</ItemGroup>
</Project>

View File

@@ -10,7 +10,7 @@ using System.Threading.Tasks;
using Microsoft.Win32;
using NLog;
namespace Espresso.Shell.Core
namespace Awake.Core
{
[Flags]
public enum EXECUTION_STATE : uint

View File

@@ -12,7 +12,7 @@ using Microsoft.PowerToys.Settings.UI.Library;
#pragma warning disable CS8602 // Dereference of a possibly null reference.
#pragma warning disable CS8603 // Possible null reference return.
namespace Espresso.Shell.Core
namespace Awake.Core
{
internal static class TrayHelper
{
@@ -44,7 +44,7 @@ namespace Espresso.Shell.Core
}, TrayIcon);
}
internal static void SetTray(string text, EspressoSettings settings)
internal static void SetTray(string text, AwakeSettings settings)
{
SetTray(
text,
@@ -69,15 +69,15 @@ namespace Espresso.Shell.Core
{
return () =>
{
EspressoSettings currentSettings;
AwakeSettings currentSettings;
try
{
currentSettings = ModuleSettings.GetSettings<EspressoSettings>(moduleName);
currentSettings = ModuleSettings.GetSettings<AwakeSettings>(moduleName);
}
catch (FileNotFoundException)
{
currentSettings = new EspressoSettings();
currentSettings = new AwakeSettings();
}
currentSettings.Properties.KeepDisplayOn = !currentSettings.Properties.KeepDisplayOn;
@@ -90,18 +90,18 @@ namespace Espresso.Shell.Core
{
return (hours, minutes) =>
{
EspressoSettings currentSettings;
AwakeSettings currentSettings;
try
{
currentSettings = ModuleSettings.GetSettings<EspressoSettings>(moduleName);
currentSettings = ModuleSettings.GetSettings<AwakeSettings>(moduleName);
}
catch (FileNotFoundException)
{
currentSettings = new EspressoSettings();
currentSettings = new AwakeSettings();
}
currentSettings.Properties.Mode = EspressoMode.TIMED;
currentSettings.Properties.Mode = AwakeMode.TIMED;
currentSettings.Properties.Hours = hours;
currentSettings.Properties.Minutes = minutes;
@@ -113,18 +113,18 @@ namespace Espresso.Shell.Core
{
return () =>
{
EspressoSettings currentSettings;
AwakeSettings currentSettings;
try
{
currentSettings = ModuleSettings.GetSettings<EspressoSettings>(moduleName);
currentSettings = ModuleSettings.GetSettings<AwakeSettings>(moduleName);
}
catch (FileNotFoundException)
{
currentSettings = new EspressoSettings();
currentSettings = new AwakeSettings();
}
currentSettings.Properties.Mode = EspressoMode.PASSIVE;
currentSettings.Properties.Mode = AwakeMode.PASSIVE;
ModuleSettings.SaveSettings(JsonSerializer.Serialize(currentSettings), moduleName);
};
@@ -134,24 +134,24 @@ namespace Espresso.Shell.Core
{
return () =>
{
EspressoSettings currentSettings;
AwakeSettings currentSettings;
try
{
currentSettings = ModuleSettings.GetSettings<EspressoSettings>(moduleName);
currentSettings = ModuleSettings.GetSettings<AwakeSettings>(moduleName);
}
catch (FileNotFoundException)
{
currentSettings = new EspressoSettings();
currentSettings = new AwakeSettings();
}
currentSettings.Properties.Mode = EspressoMode.INDEFINITE;
currentSettings.Properties.Mode = AwakeMode.INDEFINITE;
ModuleSettings.SaveSettings(JsonSerializer.Serialize(currentSettings), moduleName);
};
}
public static void SetTray(string text, bool keepDisplayOn, EspressoMode mode, Action passiveKeepAwakeCallback, Action indefiniteKeepAwakeCallback, Action<uint, uint> timedKeepAwakeCallback, Action keepDisplayOnCallback, Action exitCallback)
public static void SetTray(string text, bool keepDisplayOn, AwakeMode mode, Action passiveKeepAwakeCallback, Action indefiniteKeepAwakeCallback, Action<uint, uint> timedKeepAwakeCallback, Action keepDisplayOnCallback, Action exitCallback)
{
var contextMenuStrip = new ContextMenuStrip();
@@ -167,7 +167,7 @@ namespace Espresso.Shell.Core
Text = "Off (Passive)",
};
if (mode == EspressoMode.PASSIVE)
if (mode == AwakeMode.PASSIVE)
{
passiveMenuItem.Checked = true;
}
@@ -188,7 +188,7 @@ namespace Espresso.Shell.Core
Text = "Keep awake indefinitely",
};
if (mode == EspressoMode.INDEFINITE)
if (mode == AwakeMode.INDEFINITE)
{
indefiniteMenuItem.Checked = true;
}
@@ -227,7 +227,7 @@ namespace Espresso.Shell.Core
{
Text = "Keep awake temporarily",
};
if (mode == EspressoMode.TIMED)
if (mode == AwakeMode.TIMED)
{
timedMenuItem.Checked = true;
}

View File

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

View File

@@ -2,21 +2,23 @@
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="espressoversion" value="0.0.1" />
<variable name="awakeversion" value="0.0.1" />
<targets async="true">
<target name="logfile"
xsi:type="File"
fileName="${specialfolder:folder=LocalApplicationData}/Microsoft/PowerToys/Espresso/Logs/${var:espressoversion}/log_${date:format=yyyy-MM-dd_HH}_DBG.txt"
fileName="${specialfolder:folder=LocalApplicationData}/Microsoft/PowerToys/Awake/Logs/${var:awakeversion}/log_${date:format=yyyy-MM-dd_HH}_DBG.txt"
layout="[${longdate} ${level:uppercase=true} ${logger}] ${message}"
archiveEvery="Day"
archiveNumbering="Rolling"
maxArchiveFiles="30"/>
<target name="logconsole" xsi:type="Console" layout="[${longdate} ${level:uppercase=true}] ${message}" />
<target name="logconsole"
xsi:type="Console"
layout="[${longdate} ${level:uppercase=true}] ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logconsole" />
<logger name="*" minlevel="Debug" writeTo="logfile" />
</rules>
</nlog>
</nlog>

View File

@@ -14,7 +14,7 @@ using System.Reactive.Linq;
using System.Reflection;
using System.Threading;
using System.Windows;
using Espresso.Shell.Core;
using Awake.Core;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using NLog;
@@ -22,12 +22,12 @@ using NLog;
#pragma warning disable CS8602 // Dereference of a possibly null reference.
#pragma warning disable CS8603 // Possible null reference return.
namespace Espresso.Shell
namespace Awake
{
internal class Program
{
private static Mutex? _mutex = null;
private const string AppName = "Espresso";
private const string AppName = "Awake";
private static FileSystemWatcher? _watcher = null;
private static SettingsUtils? _settingsUtils = null;
@@ -48,7 +48,7 @@ namespace Espresso.Shell
_log = LogManager.GetCurrentClassLogger();
_settingsUtils = new SettingsUtils();
_log.Info("Launching Espresso...");
_log.Info("Launching PowerToys Awake...");
_log.Info(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion);
_log.Info($"OS: {Environment.OSVersion}");
_log.Info($"OS Build: {APIHelper.GetOperatingSystemBuild()}");
@@ -58,7 +58,7 @@ namespace Espresso.Shell
var configOption = new Option<bool>(
aliases: new[] { "--use-pt-config", "-c" },
getDefaultValue: () => false,
description: "Specifies whether Espresso will be using the PowerToys configuration file for managing the state.")
description: "Specifies whether PowerToys Awake will be using the PowerToys configuration file for managing the state.")
{
Argument = new Argument<bool>(() => false)
{
@@ -97,7 +97,7 @@ namespace Espresso.Shell
var pidOption = new Option<int>(
aliases: new[] { "--pid", "-p" },
getDefaultValue: () => 0,
description: "Bind the execution of Espresso to another process.")
description: "Bind the execution of PowerToys Awake to another process.")
{
Argument = new Argument<int>(() => 0)
{
@@ -151,7 +151,7 @@ namespace Espresso.Shell
try
{
#pragma warning disable CS8604 // Possible null reference argument.
TrayHelper.InitializeTray(AppName, new Icon(Application.GetResourceStream(new Uri("/Images/Espresso.ico", UriKind.Relative)).Stream));
TrayHelper.InitializeTray(AppName, new Icon(Application.GetResourceStream(new Uri("/Images/Awake.ico", UriKind.Relative)).Stream));
#pragma warning restore CS8604 // Possible null reference argument.
var settingsPath = _settingsUtils.GetSettingsFilePath(AppName);
@@ -178,9 +178,9 @@ namespace Espresso.Shell
mergedObservable.Throttle(TimeSpan.FromMilliseconds(25))
.SubscribeOn(TaskPoolScheduler.Default)
.Select(e => e.EventArgs)
.Subscribe(HandleEspressoConfigChange);
.Subscribe(HandleAwakeConfigChange);
TrayHelper.SetTray(AppName, new EspressoSettings());
TrayHelper.SetTray(AppName, new AwakeSettings());
// Initially the file might not be updated, so we need to start processing
// settings right away.
@@ -195,9 +195,9 @@ namespace Espresso.Shell
}
else
{
var mode = timeLimit <= 0 ? EspressoMode.INDEFINITE : EspressoMode.TIMED;
var mode = timeLimit <= 0 ? AwakeMode.INDEFINITE : AwakeMode.TIMED;
if (mode == EspressoMode.INDEFINITE)
if (mode == AwakeMode.INDEFINITE)
{
SetupIndefiniteKeepAwake(displayOn);
}
@@ -226,7 +226,7 @@ namespace Espresso.Shell
APIHelper.SetIndefiniteKeepAwake(LogCompletedKeepAwakeThread, LogUnexpectedOrCancelledKeepAwakeThreadCompletion, displayOn);
}
private static void HandleEspressoConfigChange(FileSystemEventArgs fileEvent)
private static void HandleAwakeConfigChange(FileSystemEventArgs fileEvent)
{
_log.Info("Detected a settings file change. Updating configuration...");
_log.Info("Resetting keep-awake to normal state due to settings change.");
@@ -237,26 +237,26 @@ namespace Espresso.Shell
{
try
{
EspressoSettings settings = _settingsUtils.GetSettings<EspressoSettings>(AppName);
AwakeSettings settings = _settingsUtils.GetSettings<AwakeSettings>(AppName);
if (settings != null)
{
switch (settings.Properties.Mode)
{
case EspressoMode.PASSIVE:
case AwakeMode.PASSIVE:
{
SetupNoKeepAwake();
break;
}
case EspressoMode.INDEFINITE:
case AwakeMode.INDEFINITE:
{
// Indefinite keep awake.
SetupIndefiniteKeepAwake(settings.Properties.KeepDisplayOn);
break;
}
case EspressoMode.TIMED:
case AwakeMode.TIMED:
{
// Timed keep-awake.
uint computedTime = (settings.Properties.Hours * 60 * 60) + (settings.Properties.Minutes * 60);

View File

@@ -0,0 +1,7 @@
#include <string>
namespace AwakeConstants
{
// Name of the powertoy module.
inline const std::wstring ModuleKey = L"Awake";
}

View File

@@ -52,7 +52,7 @@ END
STRINGTABLE
BEGIN
IDS_ESPRESSO_NAME "Espresso"
IDS_AWAKE_NAME "Awake"
END
#endif // English (United States) resources

View File

@@ -15,8 +15,8 @@
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{5e7360a8-d048-4ed3-8f09-0bfd64c5529a}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Espresso</RootNamespace>
<ProjectName>EspressoModuleInterface</ProjectName>
<RootNamespace>Awake</RootNamespace>
<ProjectName>AwakeModuleInterface</ProjectName>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@@ -36,7 +36,7 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\modules\Espresso\</OutDir>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\modules\Awake\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
@@ -48,7 +48,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="EspressoConstants.h" />
<ClInclude Include="AwakeConstants.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="trace.h" />
@@ -72,7 +72,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="EspressoModuleInterface.rc" />
<ResourceCompile Include="AwakeModuleInterface.rc" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

View File

@@ -15,7 +15,7 @@
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EspressoConstants.h">
<ClInclude Include="AwakeConstants.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="trace.h">
@@ -43,7 +43,7 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="EspressoModuleInterface.rc">
<ResourceCompile Include="AwakeModuleInterface.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>

View File

@@ -4,7 +4,7 @@
#include <common/interop/shared_constants.h>
#include "trace.h"
#include "resource.h"
#include "EspressoConstants.h"
#include "AwakeConstants.h"
#include <common/logger/logger.h>
#include <common/SettingsAPI/settings_helpers.h>
@@ -34,13 +34,13 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
}
// The PowerToy name that will be shown in the settings.
const static wchar_t* MODULE_NAME = L"Espresso";
const static wchar_t* MODULE_NAME = L"Awake";
// Add a description that will we shown in the module settings page.
const static wchar_t* MODULE_DESC = L"<no description>";
const static wchar_t* MODULE_DESC = L"A module that keeps your computer awake on-demand.";
// Implement the PowerToy Module Interface and all the required methods.
class Espresso : public PowertoyModuleIface
class Awake : public PowertoyModuleIface
{
std::wstring app_name;
@@ -55,7 +55,7 @@ private:
HANDLE send_telemetry_event;
// Handle to event used to invoke Espresso
// Handle to event used to invoke PowerToys Awake
HANDLE m_hInvokeEvent;
bool is_process_running()
@@ -65,21 +65,21 @@ private:
void launch_process()
{
Logger::trace(L"Launching Espresso process");
Logger::trace(L"Launching PowerToys Awake process");
unsigned long powertoys_pid = GetCurrentProcessId();
std::wstring executable_args = L"--use-pt-config --pid " + std::to_wstring(powertoys_pid);
Logger::trace(L"Espresso launching with parameters: " + executable_args);
Logger::trace(L"PowerToys Awake launching with parameters: " + executable_args);
SHELLEXECUTEINFOW sei{ sizeof(sei) };
sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI };
sei.lpFile = L"modules\\Espresso\\PowerToys.Espresso.exe";
sei.lpFile = L"modules\\Awake\\PowerToys.Awake.exe";
sei.nShow = SW_SHOWNORMAL;
sei.lpParameters = executable_args.data();
if (!ShellExecuteExW(&sei))
{
DWORD error = GetLastError();
std::wstring message = L"Espresso failed to start with error = ";
std::wstring message = L"PowerToys Awake failed to start with error = ";
message += std::to_wstring(error);
Logger::error(message);
}
@@ -89,12 +89,12 @@ private:
public:
// Constructor
Espresso()
Awake()
{
app_name = GET_RESOURCE_STRING(IDS_ESPRESSO_NAME);
app_key = EspressoConstants::ModuleKey;
app_name = GET_RESOURCE_STRING(IDS_AWAKE_NAME);
app_key = AwakeConstants::ModuleKey;
std::filesystem::path logFilePath(PTSettingsHelper::get_module_save_folder_location(this->app_key));
logFilePath.append(LogSettings::espressoLogPath);
logFilePath.append(LogSettings::awakeLogPath);
Logger::init(LogSettings::launcherLoggerName, logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location());
Logger::info("Launcher object is constructing");
};
@@ -177,5 +177,5 @@ public:
extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create()
{
return new Espresso();
return new Awake();
}

View File

@@ -1,8 +1,8 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Espresso.rc
// Used by Awake.rc
//
#define IDS_ESPRESSO_NAME 101
#define IDS_AWAKE_NAME 101
// Next default values for new objects
//

View File

@@ -1,7 +0,0 @@
#include <string>
namespace EspressoConstants
{
// Name of the powertoy module.
inline const std::wstring ModuleKey = L"Espresso";
}