mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 06:29:44 +08:00
Telemetry: add WebView init failure errors
This commit is contained in:
parent
482ad0e5ee
commit
360f7cf9c3
@ -8,6 +8,8 @@
|
||||
#include <common/dpi_aware.h>
|
||||
#include <common/common.h>
|
||||
|
||||
#include "trace.h"
|
||||
|
||||
#pragma comment(lib, "shlwapi.lib")
|
||||
#pragma comment(lib, "shcore.lib")
|
||||
#pragma comment(lib, "windowsapp")
|
||||
@ -272,6 +274,7 @@ void initialize_webview(int nShowCmd)
|
||||
else if (status == AsyncStatus::Error)
|
||||
{
|
||||
MessageBox(NULL, L"Failed to create the WebView control.\nPlease report the bug to https://github.com/microsoft/PowerToys/issues", L"PowerToys Settings Error", MB_OK);
|
||||
Trace::SettingsInitError(Trace::SettingsInitErrorCause::WebViewInitAsyncError);
|
||||
exit(1);
|
||||
}
|
||||
else if (status == AsyncStatus::Started)
|
||||
@ -286,6 +289,7 @@ void initialize_webview(int nShowCmd)
|
||||
}
|
||||
catch (hresult_error const& e)
|
||||
{
|
||||
Trace::SettingsInitError(Trace::SettingsInitErrorCause::WebViewInitWinRTException);
|
||||
WCHAR message[1024] = L"";
|
||||
StringCchPrintf(message, ARRAYSIZE(message), L"failed: %ls", e.message().c_str());
|
||||
MessageBox(g_main_wnd, message, L"Error", MB_OK);
|
||||
@ -553,6 +557,7 @@ bool initialize_com_security_policy_for_webview()
|
||||
|
||||
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
|
||||
{
|
||||
Trace::RegisterProvider();
|
||||
CoInitialize(nullptr);
|
||||
|
||||
const bool should_try_drop_privileges = !initialize_com_security_policy_for_webview() && is_process_elevated();
|
||||
@ -562,6 +567,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
|
||||
if (!drop_elevated_privileges())
|
||||
{
|
||||
MessageBox(NULL, L"Failed to drop admin privileges.\nPlease report the bug to https://github.com/microsoft/PowerToys/issues", L"PowerToys Settings Error", MB_OK);
|
||||
Trace::SettingsInitError(Trace::SettingsInitErrorCause::FailedToDropPrivileges);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@ -585,5 +591,6 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
Trace::UnregisterProvider();
|
||||
return (int)msg.wParam;
|
||||
}
|
||||
|
@ -15,3 +15,4 @@
|
||||
#pragma pop_macro("GetCurrentTime")
|
||||
#include <strsafe.h>
|
||||
#include <Shlwapi.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
|
@ -59,7 +59,7 @@
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..;..\common\Telemetry;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions>/Zm150 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<CustomBuildStep>
|
||||
@ -88,7 +88,7 @@
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..;..\common\Telemetry;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions>/Zm150 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@ -113,6 +113,7 @@
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="StreamUriResolverFromFile.h" />
|
||||
<ClInclude Include="trace.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
@ -121,6 +122,7 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="StreamURIResolverFromFile.cpp" />
|
||||
<ClCompile Include="trace.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="settings.rc" />
|
||||
|
@ -24,6 +24,9 @@
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="trace.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
@ -35,6 +38,9 @@
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="trace.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="settings.rc">
|
||||
|
45
src/settings/trace.cpp
Normal file
45
src/settings/trace.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
"Microsoft.PowerToys",
|
||||
// {38e8889b-9731-53f5-e901-e8a7c1753074}
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
const char* settingsInitErrorCauseAsString(Trace::SettingsInitErrorCause error_case)
|
||||
{
|
||||
switch (error_case)
|
||||
{
|
||||
case Trace::SettingsInitErrorCause::WebViewInitAsyncError:
|
||||
return "WebViewInitAsyncError";
|
||||
case Trace::SettingsInitErrorCause::WebViewInitWinRTException:
|
||||
return "WebViewInitWinRTException";
|
||||
case Trace::SettingsInitErrorCause::FailedToDropPrivileges:
|
||||
return "FailedToDropPrivileges";
|
||||
default:
|
||||
return "UnknownError";
|
||||
};
|
||||
}
|
||||
|
||||
void Trace::SettingsInitError(const Trace::SettingsInitErrorCause error_cause)
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
g_hProvider,
|
||||
"PowerToysSettings_SettingsInitError",
|
||||
TraceLoggingString(settingsInitErrorCauseAsString(error_cause), "Cause"),
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
}
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
17
src/settings/trace.h
Normal file
17
src/settings/trace.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
class Trace
|
||||
{
|
||||
public:
|
||||
enum class SettingsInitErrorCause : int32_t
|
||||
{
|
||||
WebViewInitAsyncError,
|
||||
WebViewInitWinRTException,
|
||||
FailedToDropPrivileges,
|
||||
};
|
||||
|
||||
static void SettingsInitError(const SettingsInitErrorCause error_cause);
|
||||
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
};
|
Loading…
Reference in New Issue
Block a user