Catch exception when trying to share (#1203)

* Fix crash

* Fix errors
This commit is contained in:
Pepe Rivera 2020-05-05 09:36:09 -07:00 committed by GitHub
parent f9a1ae1a28
commit 9817738307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 12 deletions

View File

@ -282,12 +282,27 @@ void GraphingCalculator::ViewModel::set(GraphingCalculatorViewModel ^ vm)
}
}
void CalculatorApp::GraphingCalculator::OnShareClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
void GraphingCalculator::OnShareClick(Object ^ sender, RoutedEventArgs ^ e)
{
// Ask the OS to start a share action.
try
{
DataTransferManager::ShowShareUI();
TraceLogger::GetInstance()->LogGraphButtonClicked(GraphButton::Share, GraphButtonValue::None);
}
catch (COMException ^ ex)
{
if (ex->HResult == RPC_E_SERVERCALL_RETRYLATER)
{
ShowShareError();
TraceLogger::GetInstance()->LogPlatformException(ViewMode::Graphing, __FUNCTIONW__, ex);
}
else
{
throw;
}
}
}
// When share is invoked (by the user or programmatically) the event handler we registered will be called to populate the data package with the
// data to be shared. We will request the current graph image from the grapher as a stream that will pass to the share request.
@ -394,16 +409,20 @@ void GraphingCalculator::OnDataRequested(DataTransferManager ^ sender, DataReque
}
catch (Exception ^ ex)
{
ShowShareError();
TraceLogger::GetInstance()->LogPlatformException(ViewMode::Graphing, __FUNCTIONW__, ex);
}
}
void GraphingCalculator::ShowShareError()
{
// Something went wrong, notify the user.
auto resourceLoader = ResourceLoader::GetForCurrentView();
auto errDialog = ref new ContentDialog();
errDialog->Content = resourceLoader->GetString(L"ShareActionErrorMessage");
errDialog->CloseButtonText = resourceLoader->GetString(L"ShareActionErrorOk");
errDialog->ShowAsync();
}
}
void GraphingCalculator::GraphingControl_VariablesUpdated(Object ^, Object ^)
{

View File

@ -106,6 +106,7 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo
void OnVisualStateChanged(Platform::Object ^ sender, Windows::UI::Xaml::VisualStateChangedEventArgs ^ e);
std::wstringstream FormatTraceValue(double min, double max, float pointValue);
void GraphViewButton_Click(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void ShowShareError();
};
}