Skip to content

Commit

Permalink
Allow passing args to UWP app from command line
Browse files Browse the repository at this point in the history
  • Loading branch information
ferjm committed Oct 24, 2019
1 parent 0feb16f commit 7737610
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 23 deletions.
21 changes: 13 additions & 8 deletions support/hololens/ServoApp/App.cpp
Expand Up @@ -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<Frame>();
Expand Down Expand Up @@ -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<Windows::ApplicationModel::Activation::
CommandLineActivatedEventArgs>()};
auto cmdLineStr = cmdLineArgs.Operation().Arguments();
Frame rootFrame{nullptr};
this->createRootFrame(rootFrame, false, nullptr);
auto page = rootFrame.Content().try_as<BrowserPage>();
page->SetArgs(cmdLineStr);
return;
}

if (args.Kind() ==
Expand All @@ -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<ServoApp::BrowserPage>());
Window::Current().Content(rootFrame);
Window::Current().Activate();
this->createRootFrame(rootFrame, false, nullptr);
} else {
rootFrame = content.try_as<Frame>();
}
Expand Down
6 changes: 3 additions & 3 deletions support/hololens/ServoApp/App.h
Expand Up @@ -9,12 +9,12 @@ namespace winrt::ServoApp::implementation {
struct App : AppT<App> {
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(
Expand Down
2 changes: 2 additions & 0 deletions support/hololens/ServoApp/BrowserPage.cpp
Expand Up @@ -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 ****/
Expand Down
1 change: 1 addition & 0 deletions support/hololens/ServoApp/BrowserPage.h
Expand Up @@ -29,6 +29,7 @@ struct BrowserPage : BrowserPageT<BrowserPage> {
void Shutdown();
void LoadServoURI(Windows::Foundation::Uri uri);
void SetTransientMode(bool);
void SetArgs(hstring);

private:
void BindServoEvents();
Expand Down
4 changes: 2 additions & 2 deletions support/hololens/ServoApp/ServoControl/Servo.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion support/hololens/ServoApp/ServoControl/Servo.h
Expand Up @@ -43,7 +43,7 @@ class ServoDelegate {

class Servo {
public:
Servo(hstring, GLsizei, GLsizei, float, ServoDelegate &);
Servo(hstring, hstring, GLsizei, GLsizei, float, ServoDelegate &);
~Servo();
ServoDelegate &Delegate() { return mDelegate; }

Expand Down
17 changes: 8 additions & 9 deletions support/hololens/ServoApp/ServoControl/ServoControl.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -166,7 +165,8 @@ void ServoControl::Loop() {
if (mServo == nullptr) {
log("Entering loop");
ServoDelegate *sd = static_cast<ServoDelegate *>(this);
mServo = std::make_unique<Servo>(mInitialURL, panelWidth, panelHeight, mDPI, *sd);
mServo = std::make_unique<Servo>(mInitialURL, mArgs, panelWidth, panelHeight, mDPI,
*sd);
} else {
// FIXME: this will fail since create_task didn't pick the thread
// where Servo was running initially.
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 <typename Callable> void ServoControl::RunOnUIThread(Callable cb) {
Expand Down
3 changes: 3 additions & 0 deletions support/hololens/ServoApp/ServoControl/ServoControl.h
Expand Up @@ -72,6 +72,8 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {

void SetTransientMode(bool transient) { mTransient = transient; }

void SetArgs(hstring args) { mArgs = args; }

virtual void WakeUp();
virtual void OnServoLoadStarted();
virtual void OnServoLoadEnded();
Expand Down Expand Up @@ -139,6 +141,7 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
CRITICAL_SECTION mGLLock;
CONDITION_VARIABLE mGLCondVar;
std::unique_ptr<Concurrency::task<void>> mLoopTask;
hstring mArgs;
};
} // namespace winrt::ServoApp::implementation

Expand Down
1 change: 1 addition & 0 deletions support/hololens/ServoApp/ServoControl/ServoControl.idl
Expand Up @@ -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;
Expand Down

0 comments on commit 7737610

Please sign in to comment.