mirror of https://github.com/procxx/kepka.git
Confirm export stop on quit and logout.
This commit is contained in:
parent
13e6b91ac7
commit
154e5660de
|
@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_history.h"
|
#include "styles/style_history.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
#include "boxes/confirm_box.h"
|
||||||
#include "data/data_abstract_structure.h"
|
#include "data/data_abstract_structure.h"
|
||||||
#include "data/data_media_types.h"
|
#include "data/data_media_types.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
@ -1589,7 +1590,13 @@ namespace App {
|
||||||
}
|
}
|
||||||
|
|
||||||
void quit() {
|
void quit() {
|
||||||
if (quitting()) return;
|
if (quitting()) {
|
||||||
|
return;
|
||||||
|
} else if (AuthSession::Exists()
|
||||||
|
&& Auth().data().exportInProgress()) {
|
||||||
|
Auth().data().stopExportWithConfirmation([] { App::quit(); });
|
||||||
|
return;
|
||||||
|
}
|
||||||
setLaunchState(QuitRequested);
|
setLaunchState(QuitRequested);
|
||||||
|
|
||||||
if (auto window = wnd()) {
|
if (auto window = wnd()) {
|
||||||
|
|
|
@ -79,7 +79,7 @@ void Session::startExport() {
|
||||||
|
|
||||||
_exportPanel->closed(
|
_exportPanel->closed(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
clearExport();
|
stopExport();
|
||||||
}, _export->lifetime());
|
}, _export->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,26 @@ rpl::producer<Export::View::PanelController*> Session::currentExportView(
|
||||||
return _exportViewChanges.events_starting_with(_exportPanel.get());
|
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) {
|
if (_exportPanel) {
|
||||||
_exportPanel = nullptr;
|
_exportPanel = nullptr;
|
||||||
_exportViewChanges.fire(nullptr);
|
_exportViewChanges.fire(nullptr);
|
||||||
|
|
|
@ -53,6 +53,9 @@ public:
|
||||||
|
|
||||||
void startExport();
|
void startExport();
|
||||||
rpl::producer<Export::View::PanelController*> currentExportView() const;
|
rpl::producer<Export::View::PanelController*> currentExportView() const;
|
||||||
|
bool exportInProgress() const;
|
||||||
|
void stopExportWithConfirmation(FnMut<void()> callback);
|
||||||
|
void stopExport();
|
||||||
|
|
||||||
[[nodiscard]] base::Variable<bool> &contactsLoaded() {
|
[[nodiscard]] base::Variable<bool> &contactsLoaded() {
|
||||||
return _contactsLoaded;
|
return _contactsLoaded;
|
||||||
|
@ -405,8 +408,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void clearExport();
|
|
||||||
|
|
||||||
void setupContactViewsViewer();
|
void setupContactViewsViewer();
|
||||||
void setupChannelLeavingViewer();
|
void setupChannelLeavingViewer();
|
||||||
void photoApplyFields(
|
void photoApplyFields(
|
||||||
|
|
|
@ -118,16 +118,37 @@ void PanelController::showProgress() {
|
||||||
_panel->setHideOnDeactivate(true);
|
_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>(
|
auto box = Box<ConfirmBox>(
|
||||||
lang(lng_export_sure_stop),
|
lang(lng_export_sure_stop),
|
||||||
lang(lng_export_stop),
|
lang(lng_export_stop),
|
||||||
st::attentionBoxButton,
|
st::attentionBoxButton,
|
||||||
[=] { stopExport(); });
|
std::move(stop));
|
||||||
|
_confirmStopBox = box.data();
|
||||||
_panel->showBox(
|
_panel->showBox(
|
||||||
std::move(box),
|
std::move(box),
|
||||||
LayerOption::KeepOther,
|
LayerOption::CloseOther,
|
||||||
anim::type::normal);
|
hidden ? anim::type::instant : anim::type::normal);
|
||||||
|
if (hidden) {
|
||||||
|
_panel->showAndActivate();
|
||||||
|
}
|
||||||
|
if (old) {
|
||||||
|
old->closeBox();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PanelController::stopExport() {
|
void PanelController::stopExport() {
|
||||||
|
|
|
@ -11,6 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "export/view/export_view_content.h"
|
#include "export/view/export_view_content.h"
|
||||||
#include "base/unique_qptr.h"
|
#include "base/unique_qptr.h"
|
||||||
|
|
||||||
|
class BoxContent;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class SeparatePanel;
|
class SeparatePanel;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
@ -25,7 +27,7 @@ public:
|
||||||
PanelController(not_null<ControllerWrap*> process);
|
PanelController(not_null<ControllerWrap*> process);
|
||||||
|
|
||||||
void activatePanel();
|
void activatePanel();
|
||||||
void stopWithConfirmation();
|
void stopWithConfirmation(FnMut<void()> callback = nullptr);
|
||||||
|
|
||||||
rpl::producer<> closed() const;
|
rpl::producer<> closed() const;
|
||||||
|
|
||||||
|
@ -54,6 +56,7 @@ private:
|
||||||
base::unique_qptr<Ui::SeparatePanel> _panel;
|
base::unique_qptr<Ui::SeparatePanel> _panel;
|
||||||
|
|
||||||
State _state;
|
State _state;
|
||||||
|
QPointer<BoxContent> _confirmStopBox;
|
||||||
rpl::event_stream<rpl::producer<>> _panelCloseEvents;
|
rpl::event_stream<rpl::producer<>> _panelCloseEvents;
|
||||||
bool _stopRequested = false;
|
bool _stopRequested = false;
|
||||||
rpl::lifetime _lifetime;
|
rpl::lifetime _lifetime;
|
||||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
|
#include "data/data_session.h"
|
||||||
#include "dialogs/dialogs_layout.h"
|
#include "dialogs/dialogs_layout.h"
|
||||||
#include "styles/style_dialogs.h"
|
#include "styles/style_dialogs.h"
|
||||||
#include "styles/style_window.h"
|
#include "styles/style_window.h"
|
||||||
|
@ -618,11 +619,22 @@ void MainWindow::onLogout() {
|
||||||
showFromTray();
|
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>(
|
Ui::show(Box<ConfirmBox>(
|
||||||
lang(lng_sure_logout),
|
lang(lng_sure_logout),
|
||||||
lang(lng_settings_logout),
|
lang(lng_settings_logout),
|
||||||
st::attentionBoxButton,
|
st::attentionBoxButton,
|
||||||
[] { Messenger::Instance().logOut(); }));
|
callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::quitFromTray() {
|
void MainWindow::quitFromTray() {
|
||||||
|
|
Loading…
Reference in New Issue