mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-04-01 23:00:58 +00:00
Added ability to prevent application lock and account switch.
This commit is contained in:
parent
24b8377a2a
commit
dc7a754418
@ -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() {
|
||||
|
@ -277,6 +277,8 @@ public:
|
||||
void switchFreeType();
|
||||
void writeInstallBetaVersionsSetting();
|
||||
|
||||
void preventOrInvoke(Fn<void()> &&callback);
|
||||
|
||||
void call_handleObservables();
|
||||
|
||||
protected:
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -1897,10 +1897,8 @@ bool MainWidget::stackIsEmpty() const {
|
||||
return _stack.empty();
|
||||
}
|
||||
|
||||
bool MainWidget::preventsCloseSection(
|
||||
Fn<void()> callback,
|
||||
const SectionShow ¶ms) 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 ¶ms) const {
|
||||
return params.thirdColumn
|
||||
? false
|
||||
: preventsCloseSection(std::move(callback));
|
||||
}
|
||||
|
||||
void MainWidget::showBackFromStack(
|
||||
const SectionShow ¶ms) {
|
||||
|
||||
|
@ -223,6 +223,11 @@ public:
|
||||
void closeBothPlayers();
|
||||
void stopAndClosePlayer();
|
||||
|
||||
bool preventsCloseSection(Fn<void()> callback) const;
|
||||
bool preventsCloseSection(
|
||||
Fn<void()> callback,
|
||||
const SectionShow ¶ms) 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 ¶ms);
|
||||
void dropMainSection(Window::SectionWidget *widget);
|
||||
bool preventsCloseSection(
|
||||
Fn<void()> callback,
|
||||
const SectionShow ¶ms) const;
|
||||
|
||||
Window::SectionSlideParams prepareThirdSectionAnimation(Window::SectionWidget *section);
|
||||
|
||||
|
@ -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();
|
||||
|
@ -48,6 +48,8 @@ public:
|
||||
|
||||
void finishFirstShow();
|
||||
|
||||
void preventOrInvoke(Fn<void()> callback);
|
||||
|
||||
void setupPasscodeLock();
|
||||
void clearPasscodeLock();
|
||||
void setupIntro(Intro::EnterPoint point);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -72,6 +72,8 @@ public:
|
||||
void minimize();
|
||||
void close();
|
||||
|
||||
void preventOrInvoke(Fn<void()> &&callback);
|
||||
|
||||
QPoint getPointForCallPanelCenter() const;
|
||||
|
||||
private:
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user