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() { void Application::lockByPasscode() {
_passcodeLock = true; preventOrInvoke([=] {
_window->setupPasscodeLock(); if (_window) {
_passcodeLock = true;
_window->setupPasscodeLock();
}
});
} }
void Application::unlockPasscode() { void Application::unlockPasscode() {

View file

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

View file

@ -385,6 +385,12 @@ void Domain::checkForLastProductionConfig(
Core::App().refreshFallbackProductionConfig(mtp->config()); 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) { void Domain::activate(not_null<Main::Account*> account) {
if (_active.current() == account.get()) { if (_active.current() == account.get()) {
return; return;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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