From 0feb16fe8d7d8ff8e3cc7e642ae2b7b7b84411b9 Mon Sep 17 00:00:00 2001 From: Fernando Jimenez Moreno Date: Tue, 22 Oct 2019 19:16:07 +0200 Subject: [PATCH 1/3] Allow launching UWP app from command line --- support/hololens/ServoApp/App.cpp | 23 +++++++++++++------ support/hololens/ServoApp/App.h | 2 ++ .../hololens/ServoApp/Package.appxmanifest | 10 +++++++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/support/hololens/ServoApp/App.cpp b/support/hololens/ServoApp/App.cpp index 8d80c800f4e..917226dc4ef 100644 --- a/support/hololens/ServoApp/App.cpp +++ b/support/hololens/ServoApp/App.cpp @@ -31,7 +31,9 @@ App::App() { #endif } -void App::OnLaunched(LaunchActivatedEventArgs const &e) { +void App::createRootFrame( + bool prelaunchActivated, + winrt::Windows::Foundation::IInspectable const &args) { Frame rootFrame{nullptr}; auto content = Window::Current().Content(); if (content) { @@ -43,26 +45,33 @@ void App::OnLaunched(LaunchActivatedEventArgs const &e) { rootFrame.NavigationFailed({this, &App::OnNavigationFailed}); - if (e.PrelaunchActivated() == false) { + if (prelaunchActivated == false) { if (rootFrame.Content() == nullptr) { - rootFrame.Navigate(xaml_typename(), - box_value(e.Arguments())); + rootFrame.Navigate(xaml_typename(), args); } Window::Current().Content(rootFrame); Window::Current().Activate(); } } else { - if (e.PrelaunchActivated() == false) { + if (prelaunchActivated == false) { if (rootFrame.Content() == nullptr) { - rootFrame.Navigate(xaml_typename(), - box_value(e.Arguments())); + rootFrame.Navigate(xaml_typename(), args); } Window::Current().Activate(); } } } +void App::OnLaunched(LaunchActivatedEventArgs const &e) { + this->createRootFrame(e.PrelaunchActivated(), box_value(e.Arguments())); +} + void App::OnActivated(IActivatedEventArgs const &args) { + if (args.Kind() == Windows::ApplicationModel::Activation::ActivationKind:: + CommandLineLaunch) { + return this->createRootFrame(false, nullptr); + } + if (args.Kind() == Windows::ApplicationModel::Activation::ActivationKind::Protocol) { auto protocolActivatedEventArgs{args.as< diff --git a/support/hololens/ServoApp/App.h b/support/hololens/ServoApp/App.h index 2c46c102d77..8abc9bc8d2e 100644 --- a/support/hololens/ServoApp/App.h +++ b/support/hololens/ServoApp/App.h @@ -9,6 +9,8 @@ namespace winrt::ServoApp::implementation { struct App : AppT { App(); + void createRootFrame(bool prelaunchActivated, + winrt::Windows::Foundation::IInspectable const &args); void OnLaunched( Windows::ApplicationModel::Activation::LaunchActivatedEventArgs const &); void App::OnActivated( diff --git a/support/hololens/ServoApp/Package.appxmanifest b/support/hololens/ServoApp/Package.appxmanifest index af3a17005e6..0a74082b073 100644 --- a/support/hololens/ServoApp/Package.appxmanifest +++ b/support/hololens/ServoApp/Package.appxmanifest @@ -1,5 +1,5 @@  - + @@ -32,6 +32,14 @@ Firefox Reality URL + + + + + From 773761087072f7a228865a03e5db0b66cd3014eb Mon Sep 17 00:00:00 2001 From: Fernando Jimenez Moreno Date: Wed, 23 Oct 2019 15:55:51 +0200 Subject: [PATCH 2/3] Allow passing args to UWP app from command line --- support/hololens/ServoApp/App.cpp | 21 ++++++++++++------- support/hololens/ServoApp/App.h | 6 +++--- support/hololens/ServoApp/BrowserPage.cpp | 2 ++ support/hololens/ServoApp/BrowserPage.h | 1 + .../hololens/ServoApp/ServoControl/Servo.cpp | 4 ++-- .../hololens/ServoApp/ServoControl/Servo.h | 2 +- .../ServoApp/ServoControl/ServoControl.cpp | 17 +++++++-------- .../ServoApp/ServoControl/ServoControl.h | 3 +++ .../ServoApp/ServoControl/ServoControl.idl | 1 + 9 files changed, 34 insertions(+), 23 deletions(-) diff --git a/support/hololens/ServoApp/App.cpp b/support/hololens/ServoApp/App.cpp index 917226dc4ef..a505da34d5a 100644 --- a/support/hololens/ServoApp/App.cpp +++ b/support/hololens/ServoApp/App.cpp @@ -32,9 +32,8 @@ App::App() { } void App::createRootFrame( - bool prelaunchActivated, + Frame &rootFrame, bool prelaunchActivated, winrt::Windows::Foundation::IInspectable const &args) { - Frame rootFrame{nullptr}; auto content = Window::Current().Content(); if (content) { rootFrame = content.try_as(); @@ -63,13 +62,22 @@ void App::createRootFrame( } void App::OnLaunched(LaunchActivatedEventArgs const &e) { - this->createRootFrame(e.PrelaunchActivated(), box_value(e.Arguments())); + Frame rootFrame{nullptr}; + this->createRootFrame(rootFrame, e.PrelaunchActivated(), + box_value(e.Arguments())); } void App::OnActivated(IActivatedEventArgs const &args) { if (args.Kind() == Windows::ApplicationModel::Activation::ActivationKind:: CommandLineLaunch) { - return this->createRootFrame(false, nullptr); + auto cmdLineArgs{args.as()}; + auto cmdLineStr = cmdLineArgs.Operation().Arguments(); + Frame rootFrame{nullptr}; + this->createRootFrame(rootFrame, false, nullptr); + auto page = rootFrame.Content().try_as(); + page->SetArgs(cmdLineStr); + return; } if (args.Kind() == @@ -82,10 +90,7 @@ void App::OnActivated(IActivatedEventArgs const &args) { auto content = Window::Current().Content(); bool isRunning = content != nullptr; if (!isRunning) { - rootFrame = Frame(); - rootFrame.Navigate(xaml_typename()); - Window::Current().Content(rootFrame); - Window::Current().Activate(); + this->createRootFrame(rootFrame, false, nullptr); } else { rootFrame = content.try_as(); } diff --git a/support/hololens/ServoApp/App.h b/support/hololens/ServoApp/App.h index 8abc9bc8d2e..4772306e91f 100644 --- a/support/hololens/ServoApp/App.h +++ b/support/hololens/ServoApp/App.h @@ -9,12 +9,12 @@ namespace winrt::ServoApp::implementation { struct App : AppT { App(); - void createRootFrame(bool prelaunchActivated, - winrt::Windows::Foundation::IInspectable const &args); + void createRootFrame(winrt::Windows::UI::Xaml::Controls::Frame &, bool, + winrt::Windows::Foundation::IInspectable const &); void OnLaunched( Windows::ApplicationModel::Activation::LaunchActivatedEventArgs const &); void App::OnActivated( - Windows::ApplicationModel::Activation::IActivatedEventArgs const &args); + Windows::ApplicationModel::Activation::IActivatedEventArgs const &); void OnSuspending(IInspectable const &, Windows::ApplicationModel::SuspendingEventArgs const &); void OnNavigationFailed( diff --git a/support/hololens/ServoApp/BrowserPage.cpp b/support/hololens/ServoApp/BrowserPage.cpp index a4d5fcd2a94..558b403a43d 100644 --- a/support/hololens/ServoApp/BrowserPage.cpp +++ b/support/hololens/ServoApp/BrowserPage.cpp @@ -67,6 +67,8 @@ void BrowserPage::SetTransientMode(bool transient) { : Visibility::Visible); } +void BrowserPage::SetArgs(hstring args) { servoControl().SetArgs(args); } + void BrowserPage::Shutdown() { servoControl().Shutdown(); } /**** USER INTERACTIONS WITH UI ****/ diff --git a/support/hololens/ServoApp/BrowserPage.h b/support/hololens/ServoApp/BrowserPage.h index 89372c9af3b..8c3a540d4c1 100644 --- a/support/hololens/ServoApp/BrowserPage.h +++ b/support/hololens/ServoApp/BrowserPage.h @@ -29,6 +29,7 @@ public: void Shutdown(); void LoadServoURI(Windows::Foundation::Uri uri); void SetTransientMode(bool); + void SetArgs(hstring); private: void BindServoEvents(); diff --git a/support/hololens/ServoApp/ServoControl/Servo.cpp b/support/hololens/ServoApp/ServoControl/Servo.cpp index c315cb98409..70a5b9c6bf5 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.cpp +++ b/support/hololens/ServoApp/ServoControl/Servo.cpp @@ -56,12 +56,12 @@ const char* get_clipboard_contents() { return nullptr; } -Servo::Servo(hstring url, GLsizei width, GLsizei height, float dpi, +Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, float dpi, ServoDelegate &aDelegate) : mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) { capi::CInitOptions o; - o.args = "--pref dom.webxr.enabled"; + o.args = *hstring2char(args); o.url = *hstring2char(url); o.width = mWindowWidth; o.height = mWindowHeight; diff --git a/support/hololens/ServoApp/ServoControl/Servo.h b/support/hololens/ServoApp/ServoControl/Servo.h index 170bc466e4b..26e268bd7a7 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.h +++ b/support/hololens/ServoApp/ServoControl/Servo.h @@ -43,7 +43,7 @@ protected: class Servo { public: - Servo(hstring, GLsizei, GLsizei, float, ServoDelegate &); + Servo(hstring, hstring, GLsizei, GLsizei, float, ServoDelegate &); ~Servo(); ServoDelegate &Delegate() { return mDelegate; } diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.cpp b/support/hololens/ServoApp/ServoControl/ServoControl.cpp index dc721410b89..1d409e86c95 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.cpp +++ b/support/hololens/ServoApp/ServoControl/ServoControl.cpp @@ -40,20 +40,19 @@ void ServoControl::OnLoaded(IInspectable const &, RoutedEventArgs const &) { std::bind(&ServoControl::OnSurfaceClicked, this, _1, _2)); panel.ManipulationStarted( [=](IInspectable const &, - Input::ManipulationStartedRoutedEventArgs const &e) { + Input::ManipulationStartedRoutedEventArgs const &e) { mOnCaptureGesturesStartedEvent(); e.Handled(true); }); panel.ManipulationCompleted( [=](IInspectable const &, - Input::ManipulationCompletedRoutedEventArgs const &e) { + Input::ManipulationCompletedRoutedEventArgs const &e) { mOnCaptureGesturesEndedEvent(); e.Handled(true); }); panel.ManipulationDelta( std::bind(&ServoControl::OnSurfaceManipulationDelta, this, _1, _2)); - Panel().SizeChanged( - std::bind(&ServoControl::OnSurfaceResized, this, _1, _2)); + Panel().SizeChanged(std::bind(&ServoControl::OnSurfaceResized, this, _1, _2)); InitializeConditionVariable(&mGLCondVar); InitializeCriticalSection(&mGLLock); CreateRenderSurface(); @@ -166,7 +165,8 @@ void ServoControl::Loop() { if (mServo == nullptr) { log("Entering loop"); ServoDelegate *sd = static_cast(this); - mServo = std::make_unique(mInitialURL, panelWidth, panelHeight, mDPI, *sd); + mServo = std::make_unique(mInitialURL, mArgs, panelWidth, panelHeight, mDPI, + *sd); } else { // FIXME: this will fail since create_task didn't pick the thread // where Servo was running initially. @@ -273,9 +273,7 @@ void ServoControl::WakeUp() { bool ServoControl::OnServoAllowNavigation(hstring uri) { if (mTransient) { - RunOnUIThread([=] { - Launcher::LaunchUriAsync(Uri{uri}); - }); + RunOnUIThread([=] { Launcher::LaunchUriAsync(Uri{uri}); }); } return !mTransient; } @@ -288,7 +286,8 @@ void ServoControl::OnServoAnimatingChanged(bool animating) { } void ServoControl::OnServoIMEStateChanged(bool aShow) { - // FIXME: https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-implementingtextandtextrange + // FIXME: + // https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-implementingtextandtextrange } template void ServoControl::RunOnUIThread(Callable cb) { diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.h b/support/hololens/ServoApp/ServoControl/ServoControl.h index 1476b4ba7b5..4baa861d463 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.h +++ b/support/hololens/ServoApp/ServoControl/ServoControl.h @@ -72,6 +72,8 @@ struct ServoControl : ServoControlT, public servo::ServoDelegate { void SetTransientMode(bool transient) { mTransient = transient; } + void SetArgs(hstring args) { mArgs = args; } + virtual void WakeUp(); virtual void OnServoLoadStarted(); virtual void OnServoLoadEnded(); @@ -139,6 +141,7 @@ private: CRITICAL_SECTION mGLLock; CONDITION_VARIABLE mGLCondVar; std::unique_ptr> mLoopTask; + hstring mArgs; }; } // namespace winrt::ServoApp::implementation diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.idl b/support/hololens/ServoApp/ServoControl/ServoControl.idl index a8f6328c552..597fe3320da 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.idl +++ b/support/hololens/ServoApp/ServoControl/ServoControl.idl @@ -11,6 +11,7 @@ namespace ServoApp { void Stop(); Windows.Foundation.Uri LoadURIOrSearch(String url); void SetTransientMode(Boolean transient); + void SetArgs(String args); void Shutdown(); event EventDelegate OnLoadStarted; event EventDelegate OnLoadEnded; From aeac55af5e1bb32e70bfbd0a22c9cbac7832524e Mon Sep 17 00:00:00 2001 From: Fernando Jimenez Moreno Date: Thu, 24 Oct 2019 17:16:55 +0200 Subject: [PATCH 3/3] Append default prefs to UWP app args --- support/hololens/ServoApp/ServoControl/Servo.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/support/hololens/ServoApp/ServoControl/Servo.cpp b/support/hololens/ServoApp/ServoControl/Servo.cpp index 70a5b9c6bf5..17aeb0d64e6 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.cpp +++ b/support/hololens/ServoApp/ServoControl/Servo.cpp @@ -61,7 +61,8 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, float dpi : mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) { capi::CInitOptions o; - o.args = *hstring2char(args); + hstring defaultPrefs = L" --pref dom.webxr.enabled"; + o.args = *hstring2char(args + defaultPrefs); o.url = *hstring2char(url); o.width = mWindowWidth; o.height = mWindowHeight;