Add logging for default terminal (#11458)
This PR adds some `TraceLogging` for default terminal, namely: - [x] successfully receiving terminal handoffs - [x] failing to receive terminal handoffs - [x] default terminal selection changes Closes #11452
This commit is contained in:
parent
b036cab850
commit
08e36123b3
|
@ -99,29 +99,57 @@ static HRESULT _duplicateHandle(const HANDLE in, HANDLE& out) noexcept
|
||||||
// from the registered handler event function.
|
// from the registered handler event function.
|
||||||
HRESULT CTerminalHandoff::EstablishPtyHandoff(HANDLE in, HANDLE out, HANDLE signal, HANDLE ref, HANDLE server, HANDLE client)
|
HRESULT CTerminalHandoff::EstablishPtyHandoff(HANDLE in, HANDLE out, HANDLE signal, HANDLE ref, HANDLE server, HANDLE client)
|
||||||
{
|
{
|
||||||
// Stash a local copy of _pfnHandoff before we stop listening.
|
try
|
||||||
auto localPfnHandoff = _pfnHandoff;
|
{
|
||||||
|
// Stash a local copy of _pfnHandoff before we stop listening.
|
||||||
|
auto localPfnHandoff = _pfnHandoff;
|
||||||
|
|
||||||
// Because we are REGCLS_SINGLEUSE... we need to `CoRevokeClassObject` after we handle this ONE call.
|
// Because we are REGCLS_SINGLEUSE... we need to `CoRevokeClassObject` after we handle this ONE call.
|
||||||
// COM does not automatically clean that up for us. We must do it.
|
// COM does not automatically clean that up for us. We must do it.
|
||||||
s_StopListening();
|
s_StopListening();
|
||||||
|
|
||||||
std::unique_lock lock{ _mtx };
|
std::unique_lock lock{ _mtx };
|
||||||
|
|
||||||
// Report an error if no one registered a handoff function before calling this.
|
// Report an error if no one registered a handoff function before calling this.
|
||||||
RETURN_HR_IF_NULL(E_NOT_VALID_STATE, localPfnHandoff);
|
THROW_HR_IF_NULL(E_NOT_VALID_STATE, localPfnHandoff);
|
||||||
|
|
||||||
// Duplicate the handles from what we received.
|
// Duplicate the handles from what we received.
|
||||||
// The contract with COM specifies that any HANDLEs we receive from the caller belong
|
// The contract with COM specifies that any HANDLEs we receive from the caller belong
|
||||||
// to the caller and will be freed when we leave the scope of this method.
|
// to the caller and will be freed when we leave the scope of this method.
|
||||||
// Making our own duplicate copy ensures they hang around in our lifetime.
|
// Making our own duplicate copy ensures they hang around in our lifetime.
|
||||||
RETURN_IF_FAILED(_duplicateHandle(in, in));
|
THROW_IF_FAILED(_duplicateHandle(in, in));
|
||||||
RETURN_IF_FAILED(_duplicateHandle(out, out));
|
THROW_IF_FAILED(_duplicateHandle(out, out));
|
||||||
RETURN_IF_FAILED(_duplicateHandle(signal, signal));
|
THROW_IF_FAILED(_duplicateHandle(signal, signal));
|
||||||
RETURN_IF_FAILED(_duplicateHandle(ref, ref));
|
THROW_IF_FAILED(_duplicateHandle(ref, ref));
|
||||||
RETURN_IF_FAILED(_duplicateHandle(server, server));
|
THROW_IF_FAILED(_duplicateHandle(server, server));
|
||||||
RETURN_IF_FAILED(_duplicateHandle(client, client));
|
THROW_IF_FAILED(_duplicateHandle(client, client));
|
||||||
|
|
||||||
// Call registered handler from when we started listening.
|
// Call registered handler from when we started listening.
|
||||||
return localPfnHandoff(in, out, signal, ref, server, client);
|
THROW_IF_FAILED(localPfnHandoff(in, out, signal, ref, server, client));
|
||||||
|
|
||||||
|
#pragma warning(suppress : 26477)
|
||||||
|
TraceLoggingWrite(
|
||||||
|
g_hTerminalConnectionProvider,
|
||||||
|
"ReceiveTerminalHandoff_Success",
|
||||||
|
TraceLoggingDescription("successfully received a terminal handoff"),
|
||||||
|
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
|
||||||
|
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
const auto hr = wil::ResultFromCaughtException();
|
||||||
|
|
||||||
|
#pragma warning(suppress : 26477)
|
||||||
|
TraceLoggingWrite(
|
||||||
|
g_hTerminalConnectionProvider,
|
||||||
|
"ReceiveTerminalHandoff_Failed",
|
||||||
|
TraceLoggingDescription("failed while receiving a terminal handoff"),
|
||||||
|
TraceLoggingHResult(hr),
|
||||||
|
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
|
||||||
|
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
|
||||||
|
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,4 +86,12 @@ bool DefaultTerminal::HasCurrent()
|
||||||
void DefaultTerminal::Current(const Model::DefaultTerminal& term)
|
void DefaultTerminal::Current(const Model::DefaultTerminal& term)
|
||||||
{
|
{
|
||||||
THROW_IF_FAILED(DelegationConfig::s_SetDefaultByPackage(winrt::get_self<DefaultTerminal>(term)->_pkg, true));
|
THROW_IF_FAILED(DelegationConfig::s_SetDefaultByPackage(winrt::get_self<DefaultTerminal>(term)->_pkg, true));
|
||||||
|
|
||||||
|
TraceLoggingWrite(g_hSettingsModelProvider,
|
||||||
|
"DefaultTerminalChanged",
|
||||||
|
TraceLoggingWideString(term.Name().c_str(), "TerminalName", "the name of the default terminal"),
|
||||||
|
TraceLoggingWideString(term.Version().c_str(), "TerminalVersion", "the version of the default terminal"),
|
||||||
|
TraceLoggingWideString(term.Author().c_str(), "TerminalAuthor", "the author of the default terminal"),
|
||||||
|
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
|
||||||
|
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue