diff --git a/ContactsViewModel.cpp b/ContactsViewModel.cpp index 0d21e361c12db9526d7a33f9a0395a7c98617ed8..554073fe18cfe2059b4b2224f34edc63191ee0e8 100644 --- a/ContactsViewModel.cpp +++ b/ContactsViewModel.cpp @@ -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; diff --git a/MainPage.xaml.cpp b/MainPage.xaml.cpp index 6a13b2291e27e1fdd6e2b07611cbe61c46bc1877..666c07cb380a2e2d8a2c492eff4eec882b23a598 100644 --- a/MainPage.xaml.cpp +++ b/MainPage.xaml.cpp @@ -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 diff --git a/MainPage.xaml.h b/MainPage.xaml.h index 428c5395714f21a321f32671b387d6e0cd98e223..a8b1934f524ab3fdd9c432f58226983540a15182 100644 --- a/MainPage.xaml.h +++ b/MainPage.xaml.h @@ -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); diff --git a/RingD.cpp b/RingD.cpp index 712e088a6073e74934f64a964c4d168c6a7901fe..cf6c52955c856e7eb416a6d1de67c8e52e0594ba 100644 --- a/RingD.cpp +++ b/RingD.cpp @@ -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); + } })); } }),