diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 613fd52618cb0e..056d244830067f 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -17,6 +17,7 @@ For license and copyright information please follow this link: #include "styles/style_history.h" #include "styles/style_boxes.h" #include "lang/lang_keys.h" +#include "boxes/confirm_box.h" #include "data/data_abstract_structure.h" #include "data/data_media_types.h" #include "data/data_session.h" @@ -1589,7 +1590,13 @@ namespace App { } void quit() { - if (quitting()) return; + if (quitting()) { + return; + } else if (AuthSession::Exists() + && Auth().data().exportInProgress()) { + Auth().data().stopExportWithConfirmation([] { App::quit(); }); + return; + } setLaunchState(QuitRequested); if (auto window = wnd()) { diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 47a59151730602..990d829f19ee92 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -79,7 +79,7 @@ void Session::startExport() { _exportPanel->closed( ) | rpl::start_with_next([=] { - clearExport(); + stopExport(); }, _export->lifetime()); } @@ -88,7 +88,26 @@ rpl::producer Session::currentExportView( return _exportViewChanges.events_starting_with(_exportPanel.get()); } -void Session::clearExport() { +bool Session::exportInProgress() const { + return _export != nullptr; +} + +void Session::stopExportWithConfirmation(FnMut callback) { + if (!_exportPanel) { + callback(); + return; + } + auto closeAndCall = [=, callback = std::move(callback)]() mutable { + auto saved = std::move(callback); + stopExport(); + if (saved) { + saved(); + } + }; + _exportPanel->stopWithConfirmation(std::move(closeAndCall)); +} + +void Session::stopExport() { if (_exportPanel) { _exportPanel = nullptr; _exportViewChanges.fire(nullptr); diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index c1b254cb9a38d4..b0c0cd0ffe76e7 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -53,6 +53,9 @@ class Session final { void startExport(); rpl::producer currentExportView() const; + bool exportInProgress() const; + void stopExportWithConfirmation(FnMut callback); + void stopExport(); [[nodiscard]] base::Variable &contactsLoaded() { return _contactsLoaded; @@ -405,8 +408,6 @@ class Session final { } private: - void clearExport(); - void setupContactViewsViewer(); void setupChannelLeavingViewer(); void photoApplyFields( diff --git a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp index 878efff6194c11..b578af10c39f21 100644 --- a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp +++ b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp @@ -118,16 +118,37 @@ void PanelController::showProgress() { _panel->setHideOnDeactivate(true); } -void PanelController::stopWithConfirmation() { +void PanelController::stopWithConfirmation(FnMut callback) { + if (!_state.is()) { + stopExport(); + callback(); + return; + } + auto stop = [=, callback = std::move(callback)]() mutable { + auto saved = std::move(callback); + stopExport(); + if (saved) { + saved(); + } + }; + const auto hidden = _panel->isHidden(); + const auto old = _confirmStopBox; auto box = Box( lang(lng_export_sure_stop), lang(lng_export_stop), st::attentionBoxButton, - [=] { stopExport(); }); + std::move(stop)); + _confirmStopBox = box.data(); _panel->showBox( std::move(box), - LayerOption::KeepOther, - anim::type::normal); + LayerOption::CloseOther, + hidden ? anim::type::instant : anim::type::normal); + if (hidden) { + _panel->showAndActivate(); + } + if (old) { + old->closeBox(); + } } void PanelController::stopExport() { diff --git a/Telegram/SourceFiles/export/view/export_view_panel_controller.h b/Telegram/SourceFiles/export/view/export_view_panel_controller.h index 074a3e530fde8f..9b82af8a8c02cf 100644 --- a/Telegram/SourceFiles/export/view/export_view_panel_controller.h +++ b/Telegram/SourceFiles/export/view/export_view_panel_controller.h @@ -11,6 +11,8 @@ For license and copyright information please follow this link: #include "export/view/export_view_content.h" #include "base/unique_qptr.h" +class BoxContent; + namespace Ui { class SeparatePanel; } // namespace Ui @@ -25,7 +27,7 @@ class PanelController { PanelController(not_null process); void activatePanel(); - void stopWithConfirmation(); + void stopWithConfirmation(FnMut callback = nullptr); rpl::producer<> closed() const; @@ -54,6 +56,7 @@ class PanelController { base::unique_qptr _panel; State _state; + QPointer _confirmStopBox; rpl::event_stream> _panelCloseEvents; bool _stopRequested = false; rpl::lifetime _lifetime; diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 814de4d710faca..1a4207bf4f995d 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -8,6 +8,7 @@ For license and copyright information please follow this link: #include "mainwindow.h" #include "data/data_document.h" +#include "data/data_session.h" #include "dialogs/dialogs_layout.h" #include "styles/style_dialogs.h" #include "styles/style_window.h" @@ -618,11 +619,22 @@ void MainWindow::onLogout() { showFromTray(); } + const auto logout = [] { + Messenger::Instance().logOut(); + }; + const auto callback = [=] { + if (AuthSession::Exists() && Auth().data().exportInProgress()) { + Ui::hideLayer(); + Auth().data().stopExportWithConfirmation(logout); + } else { + logout(); + } + }; Ui::show(Box( lang(lng_sure_logout), lang(lng_settings_logout), st::attentionBoxButton, - [] { Messenger::Instance().logOut(); })); + callback)); } void MainWindow::quitFromTray() {