Skip to content

Commit

Permalink
Allow launching 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 e265303 commit 0feb16f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
23 changes: 16 additions & 7 deletions support/hololens/ServoApp/App.cpp
Expand Up @@ -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) {
Expand All @@ -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<ServoApp::BrowserPage>(),
box_value(e.Arguments()));
rootFrame.Navigate(xaml_typename<ServoApp::BrowserPage>(), args);
}
Window::Current().Content(rootFrame);
Window::Current().Activate();
}
} else {
if (e.PrelaunchActivated() == false) {
if (prelaunchActivated == false) {
if (rootFrame.Content() == nullptr) {
rootFrame.Navigate(xaml_typename<ServoApp::BrowserPage>(),
box_value(e.Arguments()));
rootFrame.Navigate(xaml_typename<ServoApp::BrowserPage>(), 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<
Expand Down
2 changes: 2 additions & 0 deletions support/hololens/ServoApp/App.h
Expand Up @@ -9,6 +9,8 @@ namespace winrt::ServoApp::implementation {
struct App : AppT<App> {
App();

void createRootFrame(bool prelaunchActivated,
winrt::Windows::Foundation::IInspectable const &args);
void OnLaunched(
Windows::ApplicationModel::Activation::LaunchActivatedEventArgs const &);
void App::OnActivated(
Expand Down
10 changes: 9 additions & 1 deletion support/hololens/ServoApp/Package.appxmanifest
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5" IgnorableNamespaces="uap mp uap5">
<Identity Name="1d265729-8836-4bd3-9992-4cb111d1068b" Publisher="CN=Allizom" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="1d265729-8836-4bd3-9992-4cb111d1068b" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
Expand Down Expand Up @@ -32,6 +32,14 @@
<uap:DisplayName>Firefox Reality URL</uap:DisplayName>
</uap:Protocol>
</uap:Extension>
<uap5:Extension
Category="windows.appExecutionAlias"
Executable="ServoApp.exe"
EntryPoint="ServoApp.App">
<uap5:AppExecutionAlias>
<uap5:ExecutionAlias Alias="Servo.exe" />
</uap5:AppExecutionAlias>
</uap5:Extension>
</Extensions>
</Application>
</Applications>
Expand Down

0 comments on commit 0feb16f

Please sign in to comment.