Commit 6290cc3b authored by atraczyk's avatar atraczyk Committed by Andreas Traczyk

internal: add application ExtendedExecution state

- adds exetended execution after quitting
- hangs up calls upon quitting
- cleans camera objects on termination
- only fades loading screen when last account is registered

Change-Id: I50336c43690c0d7dc38377ea846cedddfc3f0f44
Tuleap: #1208
parent d57809fd
......@@ -172,7 +172,7 @@ ContactsViewModel::Destringify(String^ data)
void RingClientUWP::ViewModel::ContactsViewModel::OnincomingMessage(Platform::String ^callId, Platform::String ^payload)
{
auto itemlist = SmartPanelItemsViewModel::instance->itemsList;
auto item = SmartPanelItemsViewModel::instance->findItem(callId);
auto contact = item->_contact;
......
......@@ -71,6 +71,13 @@ MainPage::MainPage()
DisplayInformation^ displayInformation = DisplayInformation::GetForCurrentView();
dpiChangedtoken = (displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^,
Platform::Object^>(this, &MainPage::DisplayProperties_DpiChanged));
visibilityChangedEventToken = Window::Current->VisibilityChanged +=
ref new WindowVisibilityChangedEventHandler(this, &MainPage::Application_VisibilityChanged);
applicationSuspendingEventToken = Application::Current->Suspending +=
ref new SuspendingEventHandler(this, &MainPage::Application_Suspending);
applicationResumingEventToken = Application::Current->Resuming +=
ref new EventHandler<Object^>(this, &MainPage::Application_Resuming);
}
void
......@@ -251,21 +258,34 @@ void RingClientUWP::MainPage::OnstateChange(Platform::String ^callId, RingClient
}
}
#include <dring.h>
#include "callmanager_interface.h"
void
MainPage::Application_Suspending(Object^, Windows::ApplicationModel::SuspendingEventArgs^ e)
{
WriteLine("Application_Suspending");
if (Frame->CurrentSourcePageType.Name ==
Interop::TypeName(MainPage::typeid).Name)
{
if (Video::VideoManager::instance->captureManager()->captureTaskTokenSource)
Video::VideoManager::instance->captureManager()->captureTaskTokenSource->cancel();
//displayInformation->OrientationChanged -= displayInformationEventToken;
Interop::TypeName(MainPage::typeid).Name) {
auto deferral = e->SuspendingOperation->GetDeferral();
Video::VideoManager::instance->captureManager()->CleanupCameraAsync()
.then([this, deferral]() {
deferral->Complete();
BeginExtendedExecution()
.then([=](task<void> previousTask) {
try {
previousTask.get();
}
catch (Exception^ e) {
WriteLine("Exception: Extended Execution Begin");
}
})
.then([this, deferral](task<void> previousTask) {
try {
previousTask.get();
WriteLine("deferral->Complete()");
deferral->Complete();
}
catch (Exception^ e) {
WriteLine("Exception: Extended Execution");
deferral->Complete();
}
});
}
}
......@@ -273,16 +293,76 @@ MainPage::Application_Suspending(Object^, Windows::ApplicationModel::SuspendingE
void
MainPage::Application_VisibilityChanged(Object^ sender, VisibilityChangedEventArgs^ e)
{
if (e->Visible)
{
if (e->Visible) {
WriteLine("->Visible");
if (Video::VideoManager::instance->captureManager()->isInitialized) {
Video::VideoManager::instance->captureManager()->InitializeCameraAsync();
}
//Video::VideoManager::instance->
}
else
{
else {
WriteLine("->Invisible");
//Video::VideoManager::instance->captureManager()->CleanupCameraAsync();
}
}
void MainPage::Application_Resuming(Object^, Object^)
{
WriteLine("Application_Resuming");
}
void
MainPage::SessionRevoked(Object^ sender, ExtendedExecutionRevokedEventArgs^ args)
{
Dispatcher->RunAsync(CoreDispatcherPriority::High, ref new DispatchedHandler([=]() {
ClearExtendedExecution();
}));
}
void
MainPage::ClearExtendedExecution()
{
if (session != nullptr) {
WriteLine("End Extended Execution");
session->Revoked -= sessionRevokedToken;
}
}
task<void>
MainPage::BeginExtendedExecution()
{
ClearExtendedExecution();
auto newSession = ref new ExtendedExecutionSession();
newSession->Reason = ExtendedExecutionReason::SavingData;
newSession->Description = "Extended Execution";
sessionRevokedToken = (newSession->Revoked += ref new TypedEventHandler<Object^,
ExtendedExecutionRevokedEventArgs^>(this, &MainPage::SessionRevoked));
return create_task(newSession->RequestExtensionAsync())
.then([=](ExtendedExecutionResult result){
try {
switch (result)
{
case ExtendedExecutionResult::Allowed:
session = newSession;
WriteLine("Request Extended Execution Allowed");
WriteLine("Clean up camera...");
Video::VideoManager::instance->captureManager()->CleanupCameraAsync()
.then([](){
WriteLine("Hang up calls...");
for (auto item : SmartPanelItemsViewModel::instance->itemsList) {
if (item->_callId && item->_callStatus != CallStatus::NONE) {
DRing::hangUp(Utils::toString(item->_callId));
}
}
});
break;
default:
case ExtendedExecutionResult::Denied:
WriteLine("Request Extended Execution Denied");
break;
}
}
catch (Exception^ e) {
WriteLine("Exception: Extended Execution Request");
}
});
}
\ No newline at end of file
......@@ -21,6 +21,7 @@
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::Foundation;
using namespace Windows::ApplicationModel::ExtendedExecution;
namespace RingClientUWP
{
......@@ -45,13 +46,25 @@ protected:
void OnResize(Platform::Object^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ e);
private:
// event handlers
// Visibility and suspension
void Application_Suspending(Object^, Windows::ApplicationModel::SuspendingEventArgs^ e);
EventRegistrationToken applicationSuspendingEventToken;
void Application_VisibilityChanged(Object^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ e);
EventRegistrationToken visibilityChangedEventToken;
void Application_Resuming(Object^ sender, Object^ args);
EventRegistrationToken applicationResumingEventToken;
//void Application_Closing(Object^ sender, Windows::UI::Core::^ e);
//EventRegistrationToken applicationClosingEventToken;
ExtendedExecutionSession^ session;
void SessionRevoked(Object^ sender, ExtendedExecutionRevokedEventArgs^ args);
EventRegistrationToken sessionRevokedToken;
task<void> BeginExtendedExecution();
void ClearExtendedExecution();
// Multi-monitor, DPI, scale factor change, and window resize detection
void DisplayProperties_DpiChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args);
Windows::Foundation::EventRegistrationToken dpiChangedtoken;
EventRegistrationToken dpiChangedtoken;
Rect bounds;
void _toggleSmartBoxButton__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
......
......@@ -296,9 +296,6 @@ RingClientUWP::RingD::startDaemon()
auto callId2 = toPlatformString(callId);
auto from2 = toPlatformString(from);
///from2 = Utils::TrimFrom(from2);
const std::string PROFILE_VCF = "x-ring/ring.profile.vcard";
static const unsigned int profileSize = PROFILE_VCF.size();
......@@ -328,8 +325,12 @@ RingClientUWP::RingD::startDaemon()
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High,
ref new DispatchedHandler([=]() {
reloadAccountList();
auto frame = dynamic_cast<Frame^>(Window::Current->Content);
dynamic_cast<RingClientUWP::MainPage^>(frame->Content)->showLoadingOverlay(false, false);
std::vector<std::string> accountList = DRing::getAccountList();
auto last_id = accountList.back();
if (!account_id.compare(last_id)) {
auto frame = dynamic_cast<Frame^>(Window::Current->Content);
dynamic_cast<RingClientUWP::MainPage^>(frame->Content)->showLoadingOverlay(false, false);
}
}));
}
}),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment