Added ability to prevent application lock and account switch.

This commit is contained in:
23rd 2020-12-13 16:08:16 +03:00 committed by John Preston
parent 24b8377a2a
commit dc7a754418
11 changed files with 53 additions and 11 deletions

View File

@ -789,9 +789,17 @@ bool Application::openCustomUrl(
}
void Application::preventOrInvoke(Fn<void()> &&callback) {
_window->preventOrInvoke(std::move(callback));
}
void Application::lockByPasscode() {
_passcodeLock = true;
_window->setupPasscodeLock();
preventOrInvoke([=] {
if (_window) {
_passcodeLock = true;
_window->setupPasscodeLock();
}
});
}
void Application::unlockPasscode() {

View File

@ -277,6 +277,8 @@ public:
void switchFreeType();
void writeInstallBetaVersionsSetting();
void preventOrInvoke(Fn<void()> &&callback);
void call_handleObservables();
protected:

View File

@ -385,6 +385,12 @@ void Domain::checkForLastProductionConfig(
Core::App().refreshFallbackProductionConfig(mtp->config());
}
void Domain::maybeActivate(not_null<Main::Account*> account) {
Core::App().preventOrInvoke(crl::guard(account, [=] {
activate(account);
}));
}
void Domain::activate(not_null<Main::Account*> account) {
if (_active.current() == account.get()) {
return;

View File

@ -63,6 +63,7 @@ public:
void notifyUnreadBadgeChanged();
[[nodiscard]] not_null<Main::Account*> add(MTP::Environment environment);
void maybeActivate(not_null<Main::Account*> account);
void activate(not_null<Main::Account*> account);
void addActivated(MTP::Environment environment);

View File

@ -1897,10 +1897,8 @@ bool MainWidget::stackIsEmpty() const {
return _stack.empty();
}
bool MainWidget::preventsCloseSection(
Fn<void()> callback,
const SectionShow &params) const {
if (params.thirdColumn || Core::App().passcodeLocked()) {
bool MainWidget::preventsCloseSection(Fn<void()> callback) const {
if (Core::App().passcodeLocked()) {
return false;
}
auto copy = callback;
@ -1908,6 +1906,14 @@ bool MainWidget::preventsCloseSection(
|| (_history && _history->preventsClose(std::move(callback)));
}
bool MainWidget::preventsCloseSection(
Fn<void()> callback,
const SectionShow &params) const {
return params.thirdColumn
? false
: preventsCloseSection(std::move(callback));
}
void MainWidget::showBackFromStack(
const SectionShow &params) {

View File

@ -223,6 +223,11 @@ public:
void closeBothPlayers();
void stopAndClosePlayer();
bool preventsCloseSection(Fn<void()> callback) const;
bool preventsCloseSection(
Fn<void()> callback,
const SectionShow &params) const;
public slots:
void inlineResultLoadProgress(FileLoader *loader);
void inlineResultLoadFailed(FileLoader *loader, bool started);
@ -274,9 +279,6 @@ private:
std::unique_ptr<Window::SectionMemento> &&memento,
const SectionShow &params);
void dropMainSection(Window::SectionWidget *widget);
bool preventsCloseSection(
Fn<void()> callback,
const SectionShow &params) const;
Window::SectionSlideParams prepareThirdSectionAnimation(Window::SectionWidget *section);

View File

@ -221,6 +221,13 @@ QPixmap MainWindow::grabInner() {
return {};
}
void MainWindow::preventOrInvoke(Fn<void()> callback) {
if (_main && _main->preventsCloseSection(callback)) {
return;
}
callback();
}
void MainWindow::setupPasscodeLock() {
auto animated = (_main || _intro);
auto bg = animated ? grabInner() : QPixmap();

View File

@ -48,6 +48,8 @@ public:
void finishFirstShow();
void preventOrInvoke(Fn<void()> callback);
void setupPasscodeLock();
void clearPasscodeLock();
void setupIntro(Intro::EnterPoint point);

View File

@ -317,6 +317,10 @@ void Controller::close() {
_widget.close();
}
void Controller::preventOrInvoke(Fn<void()> &&callback) {
_widget.preventOrInvoke(std::move(callback));
}
QPoint Controller::getPointForCallPanelCenter() const {
Expects(_widget.windowHandle() != nullptr);

View File

@ -72,6 +72,8 @@ public:
void minimize();
void close();
void preventOrInvoke(Fn<void()> &&callback);
QPoint getPointForCallPanelCenter() const;
private:

View File

@ -761,7 +761,7 @@ void MainMenu::rebuildAccounts() {
}
auto activate = [=, guard = _accountSwitchGuard.make_guard()]{
if (guard) {
Core::App().domain().activate(account);
Core::App().domain().maybeActivate(account);
}
};
base::call_delayed(
@ -815,7 +815,9 @@ not_null<Ui::SlideWrap<Ui::RippleButton>*> MainMenu::setupAddAccount(
}, button->lifetime());
const auto add = [=](MTP::Environment environment) {
Core::App().domain().addActivated(environment);
Core::App().preventOrInvoke([=] {
Core::App().domain().addActivated(environment);
});
};
button->setAcceptBoth(true);