Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Color Picker] Logs #12157

Merged
merged 2 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/modules/colorPicker/ColorPicker/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <colorPicker/ColorPicker/ColorPickerConstants.h>
#include <common/interop/shared_constants.h>
#include <common/utils/logger_helper.h>
#include <common/utils/winapi_error.h>

BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
Expand Down Expand Up @@ -108,7 +110,7 @@ class ColorPicker : public PowertoyModuleIface

void launch_process()
{
Logger::trace(L"Launching ColorPicker process");
Logger::trace(L"Starting ColorPicker process");
unsigned long powertoys_pid = GetCurrentProcessId();

std::wstring executable_args = L"";
Expand All @@ -119,12 +121,13 @@ class ColorPicker : public PowertoyModuleIface
sei.lpFile = L"modules\\ColorPicker\\ColorPickerUI.exe";
sei.nShow = SW_SHOWNORMAL;
sei.lpParameters = executable_args.data();
if (!ShellExecuteExW(&sei))
if (ShellExecuteExW(&sei))
{
DWORD error = GetLastError();
std::wstring message = L"ColorPicker failed to start with error = ";
message += std::to_wstring(error);
Logger::error(message);
Logger::trace("Successfully started the Color Picker process");
}
else
{
Logger::error( L"ColorPicker failed to start. {}", get_last_error_or_default(GetLastError()));
}

m_hProcess = sei.hProcess;
Expand Down Expand Up @@ -153,6 +156,7 @@ class ColorPicker : public PowertoyModuleIface
{
app_name = GET_RESOURCE_STRING(IDS_COLORPICKER_NAME);
app_key = ColorPickerConstants::ModuleKey;
LoggerHelpers::init_logger(app_key, L"ModuleInterface", "ColorPicker");
send_telemetry_event = CreateDefaultEvent(CommonSharedConstants::COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT);
m_hInvokeEvent = CreateDefaultEvent(CommonSharedConstants::SHOW_COLOR_PICKER_SHARED_EVENT);
init_settings();
Expand All @@ -169,6 +173,7 @@ class ColorPicker : public PowertoyModuleIface
// Destroy the powertoy and free memory
virtual void destroy() override
{
Logger::trace("ColorPicker::destroy()");
delete this;
}

Expand Down Expand Up @@ -224,6 +229,7 @@ class ColorPicker : public PowertoyModuleIface

virtual void enable()
{
Logger::trace("ColorPicker::enable()");
ResetEvent(send_telemetry_event);
ResetEvent(m_hInvokeEvent);
launch_process();
Expand All @@ -232,6 +238,7 @@ class ColorPicker : public PowertoyModuleIface

virtual void disable()
{
Logger::trace("ColorPicker::disable()");
if (m_enabled)
{
ResetEvent(send_telemetry_event);
Expand Down
4 changes: 4 additions & 0 deletions src/modules/colorPicker/ColorPickerUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Threading;
using System.Windows;
using ColorPicker.Helpers;
using ColorPicker.Mouse;
using ManagedCommon;
using Microsoft.PowerToys.Common.UI;
Expand All @@ -30,6 +31,7 @@ protected override void OnStartup(StartupEventArgs e)
_instanceMutex = new Mutex(true, @"Local\PowerToys_ColorPicker_InstanceMutex", out bool createdNew);
if (!createdNew)
{
Logger.LogWarning("There is ColorPicker instance running. Exiting Color Picker");
_instanceMutex = null;
Environment.Exit(0);
return;
Expand All @@ -39,8 +41,10 @@ protected override void OnStartup(StartupEventArgs e)
{
_ = int.TryParse(_args[0], out _powerToysRunnerPid);

Logger.LogInfo($"Color Picker started from the PowerToys Runner. Runner pid={_powerToysRunnerPid}");
RunnerHelper.WaitForPowerToysRunner(_powerToysRunnerPid, () =>
{
Logger.LogInfo("PowerToys Runner exited. Exiting ColorPicker");
Environment.Exit(0);
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/modules/colorPicker/ColorPickerUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;

using System.Diagnostics;
using ColorPicker.Helpers;
using ColorPicker.Mouse;

Expand All @@ -19,6 +19,7 @@ public static class Program
public static void Main(string[] args)
{
_args = args;
Logger.LogInfo($"Color Picker started with pid={Process.GetCurrentProcess().Id}");
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
try
{
Expand Down