Confirm export stop on quit and logout.

This commit is contained in:
John Preston 2018-06-20 18:30:57 +01:00
parent 13e6b91ac7
commit 154e5660de
6 changed files with 74 additions and 11 deletions

View File

@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#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()) {

View File

@ -79,7 +79,7 @@ void Session::startExport() {
_exportPanel->closed(
) | rpl::start_with_next([=] {
clearExport();
stopExport();
}, _export->lifetime());
}
@ -88,7 +88,26 @@ rpl::producer<Export::View::PanelController*> Session::currentExportView(
return _exportViewChanges.events_starting_with(_exportPanel.get());
}
void Session::clearExport() {
bool Session::exportInProgress() const {
return _export != nullptr;
}
void Session::stopExportWithConfirmation(FnMut<void()> 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);

View File

@ -53,6 +53,9 @@ public:
void startExport();
rpl::producer<Export::View::PanelController*> currentExportView() const;
bool exportInProgress() const;
void stopExportWithConfirmation(FnMut<void()> callback);
void stopExport();
[[nodiscard]] base::Variable<bool> &contactsLoaded() {
return _contactsLoaded;
@ -405,8 +408,6 @@ public:
}
private:
void clearExport();
void setupContactViewsViewer();
void setupChannelLeavingViewer();
void photoApplyFields(

View File

@ -118,16 +118,37 @@ void PanelController::showProgress() {
_panel->setHideOnDeactivate(true);
}
void PanelController::stopWithConfirmation() {
void PanelController::stopWithConfirmation(FnMut<void()> callback) {
if (!_state.is<ProcessingState>()) {
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<ConfirmBox>(
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() {

View File

@ -11,6 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "export/view/export_view_content.h"
#include "base/unique_qptr.h"
class BoxContent;
namespace Ui {
class SeparatePanel;
} // namespace Ui
@ -25,7 +27,7 @@ public:
PanelController(not_null<ControllerWrap*> process);
void activatePanel();
void stopWithConfirmation();
void stopWithConfirmation(FnMut<void()> callback = nullptr);
rpl::producer<> closed() const;
@ -54,6 +56,7 @@ private:
base::unique_qptr<Ui::SeparatePanel> _panel;
State _state;
QPointer<BoxContent> _confirmStopBox;
rpl::event_stream<rpl::producer<>> _panelCloseEvents;
bool _stopRequested = false;
rpl::lifetime _lifetime;

View File

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#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<ConfirmBox>(
lang(lng_sure_logout),
lang(lng_settings_logout),
st::attentionBoxButton,
[] { Messenger::Instance().logOut(); }));
callback));
}
void MainWindow::quitFromTray() {