diff options
author | Benoit Foucher <benoit@zeroc.com> | 2018-02-08 11:40:30 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2018-02-08 11:40:30 +0100 |
commit | 5a937ede89579d88f294094165633cc120e10a97 (patch) | |
tree | c5c9ae0ecd9bfe2d7367a4826a30e3c06851745c /cpp/test/uwp/controller | |
parent | Add Matlab mapping only if matlab is installed (diff) | |
download | ice-5a937ede89579d88f294094165633cc120e10a97.tar.bz2 ice-5a937ede89579d88f294094165633cc120e10a97.tar.xz ice-5a937ede89579d88f294094165633cc120e10a97.zip |
Fixed UWP controller to also run when in the background (ICE-8305)
Diffstat (limited to 'cpp/test/uwp/controller')
-rw-r--r-- | cpp/test/uwp/controller/App.xaml.cpp | 34 | ||||
-rw-r--r-- | cpp/test/uwp/controller/App.xaml.h | 2 | ||||
-rw-r--r-- | cpp/test/uwp/controller/Package.appxmanifest | 4 |
3 files changed, 36 insertions, 4 deletions
diff --git a/cpp/test/uwp/controller/App.xaml.cpp b/cpp/test/uwp/controller/App.xaml.cpp index ea67c113cc6..dfb97c7000d 100644 --- a/cpp/test/uwp/controller/App.xaml.cpp +++ b/cpp/test/uwp/controller/App.xaml.cpp @@ -9,6 +9,7 @@ #include "pch.h" #include "ViewController.xaml.h" +#include <ppltasks.h> using namespace Controller; @@ -25,6 +26,7 @@ using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Interop; using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Navigation; +using namespace Windows::ApplicationModel::ExtendedExecution::Foreground; // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227 @@ -48,20 +50,20 @@ void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEvent { // Do not repeat app initialization when already running, just ensure that // the window is active - if (pArgs->PreviousExecutionState == ApplicationExecutionState::Running) + if(pArgs->PreviousExecutionState == ApplicationExecutionState::Running) { Window::Current->Activate(); return; } - if (pArgs->PreviousExecutionState == ApplicationExecutionState::Terminated) + if(pArgs->PreviousExecutionState == ApplicationExecutionState::Terminated) { //TODO: Load state from previously suspended application } // Create a Frame to act navigation context and navigate to the first page auto rootFrame = ref new Frame(); - if (!rootFrame->Navigate(TypeName(ViewController::typeid))) + if(!rootFrame->Navigate(TypeName(ViewController::typeid))) { throw ref new FailureException("Failed to create initial page"); } @@ -69,6 +71,32 @@ void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEvent // Place the frame in the current Window and ensure that it is active Window::Current->Content = rootFrame; Window::Current->Activate(); + + if(!_session) + { + ExtendedExecutionForegroundSession^ session = ref new ExtendedExecutionForegroundSession(); + session->Reason = ExtendedExecutionForegroundReason::Unconstrained; + session->Revoked += ref new TypedEventHandler<Object^, ExtendedExecutionForegroundRevokedEventArgs^>(this, &App::SessionRevoked); + concurrency::create_task(session->RequestExtensionAsync()).then([this, session](ExtendedExecutionForegroundResult result) + { + switch(result) + { + case ExtendedExecutionForegroundResult::Allowed: + _session = session; + break; + case ExtendedExecutionForegroundResult::Denied: + break; + } + }); + } +} + +void App::SessionRevoked(Object^ sender, ExtendedExecutionForegroundRevokedEventArgs^ args) +{ + if(_session != nullptr) + { + _session = nullptr; + } } /// <summary> diff --git a/cpp/test/uwp/controller/App.xaml.h b/cpp/test/uwp/controller/App.xaml.h index 354d2726504..2305d464a81 100644 --- a/cpp/test/uwp/controller/App.xaml.h +++ b/cpp/test/uwp/controller/App.xaml.h @@ -24,5 +24,7 @@ public: private: void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e); + void SessionRevoked(Platform::Object^, Windows::ApplicationModel::ExtendedExecution::Foreground::ExtendedExecutionForegroundRevokedEventArgs^); + Windows::ApplicationModel::ExtendedExecution::Foreground::ExtendedExecutionForegroundSession^ _session; }; } diff --git a/cpp/test/uwp/controller/Package.appxmanifest b/cpp/test/uwp/controller/Package.appxmanifest index e5a1aa1d6f5..85f47d15719 100644 --- a/cpp/test/uwp/controller/Package.appxmanifest +++ b/cpp/test/uwp/controller/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:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap mp rescap"> <Identity Name="ice-uwp-controller" Publisher="CN=ZeroC" Version="1.0.0.0" /> <mp:PhoneIdentity PhoneProductId="f4c6cdff-3ef9-43fb-8094-d50c547e70f6" PhonePublisherId="00000000-0000-0000-0000-000000000000" /> <Properties> @@ -26,6 +26,8 @@ <Capability Name="internetClientServer" /> <Capability Name="internetClient" /> <Capability Name="privateNetworkClientServer" /> + <rescap:Capability Name="extendedBackgroundTaskTime" /> + <rescap:Capability Name="extendedExecutionUnconstrained" /> </Capabilities> <Extensions> <Extension Category="windows.certificates"> |