simplify the interface here a bit

This commit is contained in:
Mike Griese 2021-08-24 15:18:36 -05:00
parent 31b2763be5
commit 8707c03715
2 changed files with 19 additions and 15 deletions

View file

@ -13,7 +13,7 @@ using namespace winrt::Windows::UI::Composition;
using namespace winrt::Windows::UI::Xaml::Hosting;
using namespace winrt::Windows::Foundation::Numerics;
bool checkIfContentProcess(winrt::guid& contentProcessGuid, HANDLE& eventHandle)
static bool checkIfContentProcess(winrt::guid& contentProcessGuid, HANDLE& eventHandle)
{
std::vector<std::wstring> args;
@ -98,7 +98,7 @@ private:
winrt::guid _guid;
};
void doContentProcessThing(const winrt::guid& contentProcessGuid, const HANDLE& eventHandle)
static void doContentProcessThing(const winrt::guid& contentProcessGuid, const HANDLE& eventHandle)
{
// !! LOAD BEARING !! - important to be a MTA
winrt::init_apartment();
@ -118,3 +118,18 @@ void doContentProcessThing(const winrt::guid& contentProcessGuid, const HANDLE&
std::unique_lock<std::mutex> lk(m);
cv.wait(lk, [] { return dtored; });
}
void TryRunAsContentProcess()
{
winrt::guid contentProcessGuid{};
HANDLE eventHandle{ INVALID_HANDLE_VALUE };
if (checkIfContentProcess(contentProcessGuid, eventHandle))
{
doContentProcessThing(contentProcessGuid, eventHandle);
// If we were told to not have a window, exit early. Make sure to use
// ExitProcess to die here. If you try just `return 0`, then
// the XAML app host will crash during teardown. ExitProcess avoids
// that.
ExitProcess(0);
}
}

View file

@ -31,8 +31,7 @@ TRACELOGGING_DEFINE_PROVIDER(
#include <LibraryResources.h>
UTILS_DEFINE_LIBRARY_RESOURCE_SCOPE(L"TerminalApp/Resources");
bool checkIfContentProcess(winrt::guid& contentProcessGuid, HANDLE& eventHandle);
void doContentProcessThing(const winrt::guid& contentProcessGuid, const HANDLE& eventHandle);
void TryRunAsContentProcess();
// Routine Description:
// - Takes an image architecture and locates a string resource that maps to that architecture.
@ -122,17 +121,7 @@ int __stdcall wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
// should choose and install the correct one from the bundle.
EnsureNativeArchitecture();
winrt::guid contentProcessGuid{};
HANDLE eventHandle{ INVALID_HANDLE_VALUE };
if (checkIfContentProcess(contentProcessGuid, eventHandle))
{
doContentProcessThing(contentProcessGuid, eventHandle);
// If we were told to not have a window, exit early. Make sure to use
// ExitProcess to die here. If you try just `return 0`, then
// the XAML app host will crash during teardown. ExitProcess avoids
// that.
ExitProcess(0);
}
TryRunAsContentProcess();
// Make sure to call this so we get WM_POINTER messages.
EnableMouseInPointer(true);