Remove namespace App.

This commit is contained in:
John Preston 2022-11-30 17:28:09 +04:00
parent 01139e1b04
commit ad3f8e72a0
24 changed files with 80 additions and 74 deletions

View file

@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "boxes/abstract_box.h" #include "boxes/abstract_box.h"
#include "core/application.h"
#include "window/window_controller.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "mainwindow.h" #include "mainwindow.h"
@ -17,25 +19,30 @@ void showBox(
object_ptr<BoxContent> content, object_ptr<BoxContent> content,
LayerOptions options, LayerOptions options,
anim::type animated) { anim::type animated) {
if (auto w = App::wnd()) { const auto window = Core::IsAppLaunched()
w->ui_showBox(std::move(content), options, animated); ? Core::App().primaryWindow()
: nullptr;
if (window) {
window->show(std::move(content), options, animated);
} }
} }
} // namespace internal } // namespace internal
void hideLayer(anim::type animated) { void hideLayer(anim::type animated) {
if (auto w = App::wnd()) { const auto window = Core::IsAppLaunched()
w->ui_showBox( ? Core::App().primaryWindow()
{ nullptr }, : nullptr;
LayerOption::CloseOther, if (window) {
animated); window->hideLayer(animated);
} }
} }
bool isLayerShown() { bool isLayerShown() {
if (auto w = App::wnd()) return w->ui_isLayerShown(); const auto window = Core::IsAppLaunched()
return false; ? Core::App().primaryWindow()
: nullptr;
return window && window->isLayerShown();
} }
} // namespace Ui } // namespace Ui

View file

@ -47,6 +47,5 @@ QPointer<BoxType> show(
} }
void hideLayer(anim::type animated = anim::type::normal); void hideLayer(anim::type animated = anim::type::normal);
bool isLayerShown();
} // namespace Ui } // namespace Ui

View file

@ -855,7 +855,9 @@ void Application::switchDebugMode() {
Logs::SetDebugEnabled(true); Logs::SetDebugEnabled(true);
_launcher->writeDebugModeSetting(); _launcher->writeDebugModeSetting();
DEBUG_LOG(("Debug logs started.")); DEBUG_LOG(("Debug logs started."));
Ui::hideLayer(); if (_primaryWindow) {
_primaryWindow->hideLayer();
}
} }
} }
@ -966,6 +968,12 @@ bool Application::canApplyLangPackWithoutRestart() const {
return true; return true;
} }
void Application::checkSendPaths() {
if (!cSendPaths().isEmpty() && _primaryWindow && !_primaryWindow->locked()) {
_primaryWindow->widget()->sendPaths();
}
}
void Application::checkStartUrl() { void Application::checkStartUrl() {
if (!cStartUrl().isEmpty() && _primaryWindow && !_primaryWindow->locked()) { if (!cStartUrl().isEmpty() && _primaryWindow && !_primaryWindow->locked()) {
const auto url = cStartUrl(); const auto url = cStartUrl();

View file

@ -236,6 +236,7 @@ public:
// Internal links. // Internal links.
void checkStartUrl(); void checkStartUrl();
void checkSendPaths();
bool openLocalUrl(const QString &url, QVariant context); bool openLocalUrl(const QString &url, QVariant context);
bool openInternalUrl(const QString &url, QVariant context); bool openInternalUrl(const QString &url, QVariant context);
[[nodiscard]] QString changelogLink() const; [[nodiscard]] QString changelogLink() const;

View file

@ -162,7 +162,7 @@ void ShowInFolder(const QString &filepath) {
Ui::PreventDelayedActivation(); Ui::PreventDelayedActivation();
if (Platform::IsLinux()) { if (Platform::IsLinux()) {
// Hide mediaview to make other apps visible. // Hide mediaview to make other apps visible.
Ui::hideLayer(anim::type::instant); Core::App().hideMediaView();
} }
base::Platform::ShowInFolder(filepath); base::Platform::ShowInFolder(filepath);
}); });

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwindow.h" #include "mainwindow.h"
#include "storage/localstorage.h" #include "storage/localstorage.h"
#include "window/notifications_manager.h" #include "window/notifications_manager.h"
#include "window/window_controller.h"
#include "core/crash_reports.h" #include "core/crash_reports.h"
#include "core/crash_report_window.h" #include "core/crash_report_window.h"
#include "core/application.h" #include "core/application.h"
@ -460,10 +461,8 @@ void Sandbox::readClients() {
paths.append(toSend); paths.append(toSend);
cSetSendPaths(paths); cSetSendPaths(paths);
} }
if (!cSendPaths().isEmpty()) { if (_application) {
if (App::wnd()) { _application->checkSendPaths();
App::wnd()->sendPaths();
}
} }
if (!startUrl.isEmpty()) { if (!startUrl.isEmpty()) {
cSetStartUrl(startUrl); cSetStartUrl(startUrl);
@ -647,8 +646,8 @@ void Sandbox::closeApplication() {
void Sandbox::execExternal(const QString &cmd) { void Sandbox::execExternal(const QString &cmd) {
DEBUG_LOG(("Sandbox Info: executing external command '%1'").arg(cmd)); DEBUG_LOG(("Sandbox Info: executing external command '%1'").arg(cmd));
if (cmd == "show") { if (cmd == "show") {
if (App::wnd()) { if (Core::IsAppLaunched() && Core::App().primaryWindow()) {
App::wnd()->activate(); Core::App().primaryWindow()->activate();
} else if (PreLaunchWindow::instance()) { } else if (PreLaunchWindow::instance()) {
PreLaunchWindow::instance()->activate(); PreLaunchWindow::instance()->activate();
} }

View file

@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_account.h" #include "main/main_account.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "main/main_app_config.h" #include "main/main_app_config.h"
#include "window/window_controller.h"
#include "mainwindow.h" #include "mainwindow.h"
namespace Core { namespace Core {
@ -123,8 +124,8 @@ QString UiIntegration::angleBackendFilePath() {
} }
void UiIntegration::textActionsUpdated() { void UiIntegration::textActionsUpdated() {
if (const auto window = App::wnd()) { if (const auto window = Core::App().primaryWindow()) {
window->updateGlobalMenu(); window->widget()->updateGlobalMenu();
} }
} }

View file

@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_domain.h" #include "main/main_domain.h"
#include "info/info_memento.h" #include "info/info_memento.h"
#include "info/info_controller.h" #include "info/info_controller.h"
#include "window/window_controller.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "settings/settings_advanced.h" #include "settings/settings_advanced.h"
#include "settings/settings_intro.h" #include "settings/settings_intro.h"
@ -1648,7 +1649,10 @@ void UpdateApplication() {
UrlClickHandler::Open(url); UrlClickHandler::Open(url);
} else { } else {
cSetAutoUpdate(true); cSetAutoUpdate(true);
if (const auto window = App::wnd()) { const auto window = Core::IsAppLaunched()
? Core::App().primaryWindow()
: nullptr;
if (window) {
if (const auto controller = window->sessionController()) { if (const auto controller = window->sessionController()) {
controller->showSection( controller->showSection(
std::make_shared<Info::Memento>( std::make_shared<Info::Memento>(
@ -1656,11 +1660,11 @@ void UpdateApplication() {
::Settings::Advanced::Id()), ::Settings::Advanced::Id()),
Window::SectionShow()); Window::SectionShow());
} else { } else {
window->showSpecialLayer( window->widget()->showSpecialLayer(
Box<::Settings::LayerWidget>(&window->controller()), Box<::Settings::LayerWidget>(window),
anim::type::normal); anim::type::normal);
} }
window->showFromTray(); window->widget()->showFromTray();
} }
cSetLastUpdateCheck(0); cSetLastUpdateCheck(0);
Core::UpdateChecker().start(); Core::UpdateChecker().start();

View file

@ -3615,7 +3615,7 @@ void InnerWidget::setupShortcuts() {
Shortcuts::Requests( Shortcuts::Requests(
) | rpl::filter([=] { ) | rpl::filter([=] {
return isActiveWindow() return isActiveWindow()
&& !Ui::isLayerShown() && !_controller->isLayerShown()
&& !_controller->window().locked(); && !_controller->window().locked();
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) { }) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command; using Command = Shortcuts::Command;

View file

@ -663,7 +663,7 @@ void Widget::setupShortcuts() {
) | rpl::filter([=] { ) | rpl::filter([=] {
return isActiveWindow() return isActiveWindow()
&& Ui::InFocusChain(this) && Ui::InFocusChain(this)
&& !Ui::isLayerShown() && !controller()->isLayerShown()
&& !controller()->window().locked(); && !controller()->window().locked();
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) { }) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command; using Command = Shortcuts::Command;
@ -2027,7 +2027,7 @@ void Widget::showSearchFrom() {
auto box = SearchFromBox( auto box = SearchFromBox(
peer, peer,
crl::guard(this, [=](not_null<PeerData*> from) { crl::guard(this, [=](not_null<PeerData*> from) {
Ui::hideLayer(); controller()->hideLayer();
if (!chat.topic()) { if (!chat.topic()) {
setSearchInChat(chat, from); setSearchInChat(chat, from);
} else if (const auto strong = weak.get()) { } else if (const auto strong = weak.get()) {

View file

@ -397,7 +397,7 @@ void Widget::setupShortcuts() {
) | rpl::filter([=] { ) | rpl::filter([=] {
return Ui::AppInFocus() return Ui::AppInFocus()
&& Ui::InFocusChain(this) && Ui::InFocusChain(this)
&& !Ui::isLayerShown() && !controller()->isLayerShown()
&& isActiveWindow(); && isActiveWindow();
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) { }) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command; using Command = Shortcuts::Command;

View file

@ -1838,7 +1838,7 @@ void HistoryWidget::setupShortcuts() {
return _history return _history
&& Ui::AppInFocus() && Ui::AppInFocus()
&& Ui::InFocusChain(this) && Ui::InFocusChain(this)
&& !Ui::isLayerShown() && !controller()->isLayerShown()
&& (Core::App().activeWindow() == &controller()->window()); && (Core::App().activeWindow() == &controller()->window());
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) { }) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command; using Command = Shortcuts::Command;
@ -4059,7 +4059,7 @@ void HistoryWidget::checkSuggestToGigagroup() {
return; return;
} }
InvokeQueued(_list, [=] { InvokeQueued(_list, [=] {
if (!Ui::isLayerShown()) { if (!controller()->isLayerShown()) {
group->owner().setSuggestToGigagroup(group, false); group->owner().setSuggestToGigagroup(group, false);
group->session().api().request(MTPhelp_DismissSuggestion( group->session().api().request(MTPhelp_DismissSuggestion(
group->input, group->input,
@ -7351,7 +7351,8 @@ void HistoryWidget::updateTopBarSelection() {
: tr::lng_report_messages_none(tr::now))); : tr::lng_report_messages_none(tr::now)));
updateControlsVisibility(); updateControlsVisibility();
updateHistoryGeometry(); updateHistoryGeometry();
if (!Ui::isLayerShown() && !Core::App().passcodeLocked()) { if (!controller()->isLayerShown()
&& !Core::App().passcodeLocked()) {
if (isSearching()) { if (isSearching()) {
_composeSearch->setInnerFocus(); _composeSearch->setInnerFocus();
} else if (_nonEmptySelection } else if (_nonEmptySelection

View file

@ -2588,7 +2588,7 @@ void RepliesWidget::setupShortcuts() {
return _topic return _topic
&& Ui::AppInFocus() && Ui::AppInFocus()
&& Ui::InFocusChain(this) && Ui::InFocusChain(this)
&& !Ui::isLayerShown() && !controller()->isLayerShown()
&& (Core::App().activeWindow() == &controller()->window()); && (Core::App().activeWindow() == &controller()->window());
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) { }) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command; using Command = Shortcuts::Command;

View file

@ -493,7 +493,7 @@ void Widget::resetAccount() {
)).done([=] { )).done([=] {
_resetRequest = 0; _resetRequest = 0;
Ui::hideLayer(); getData()->controller->hideLayer();
if (getData()->phone.isEmpty()) { if (getData()->phone.isEmpty()) {
moveToStep( moveToStep(
new QrWidget(this, _account, getData()), new QrWidget(this, _account, getData()),
@ -556,7 +556,7 @@ void Widget::resetAccount() {
Ui::show(Ui::MakeInformBox( Ui::show(Ui::MakeInformBox(
tr::lng_signin_reset_cancelled())); tr::lng_signin_reset_cancelled()));
} else { } else {
Ui::hideLayer(); getData()->controller->hideLayer();
getStep()->showError(rpl::single(Lang::Hard::ServerError())); getStep()->showError(rpl::single(Lang::Hard::ServerError()));
} }
}).send(); }).send();

View file

@ -2676,7 +2676,7 @@ void MainWidget::activate() {
} else if (_hider) { } else if (_hider) {
Assert(_dialogs != nullptr); Assert(_dialogs != nullptr);
_dialogs->setInnerFocus(); _dialogs->setInnerFocus();
} else if (!Ui::isLayerShown()) { } else if (!_controller->isLayerShown()) {
if (_history->peer()) { if (_history->peer()) {
_history->activate(); _history->activate();
} else { } else {
@ -2702,14 +2702,3 @@ bool MainWidget::isNormalColumn() const {
bool MainWidget::isThreeColumn() const { bool MainWidget::isThreeColumn() const {
return _controller->adaptive().isThreeColumn(); return _controller->adaptive().isThreeColumn();
} }
namespace App {
MainWidget *main() {
if (const auto window = wnd()) {
return window->sessionContent();
}
return nullptr;
}
} // namespace App

View file

@ -390,7 +390,3 @@ private:
const std::unique_ptr<Core::Changelogs> _changelogs; const std::unique_ptr<Core::Changelogs> _changelogs;
}; };
namespace App {
MainWidget *main();
} // namespace App

View file

@ -724,13 +724,3 @@ void MainWindow::sendPaths() {
} }
MainWindow::~MainWindow() = default; MainWindow::~MainWindow() = default;
namespace App {
MainWindow *wnd() {
return (Core::IsAppLaunched() && Core::App().primaryWindow())
? Core::App().primaryWindow()->widget().get()
: nullptr;
}
} // namespace App

View file

@ -147,7 +147,3 @@ private:
object_ptr<Window::Theme::WarningWidget> _testingThemeWarning = { nullptr }; object_ptr<Window::Theme::WarningWidget> _testingThemeWarning = { nullptr };
}; };
namespace App {
MainWindow *wnd();
} // namespace App

View file

@ -308,7 +308,7 @@ void Instance::clearStreamed(not_null<Data*> data, bool savePosition) {
data->streamed = nullptr; data->streamed = nullptr;
_roundPlaying = false; _roundPlaying = false;
if (const auto window = App::wnd()) { if (const auto window = Core::App().primaryWindow()) {
if (const auto controller = window->sessionController()) { if (const auto controller = window->sessionController()) {
controller->disableGifPauseReason( controller->disableGifPauseReason(
Window::GifPauseReason::RoundPlaying); Window::GifPauseReason::RoundPlaying);
@ -1292,7 +1292,7 @@ void Instance::handleStreamingUpdate(
requestRoundVideoRepaint(); requestRoundVideoRepaint();
}); });
_roundPlaying = true; _roundPlaying = true;
if (const auto window = App::wnd()) { if (const auto window = Core::App().primaryWindow()) {
if (const auto controller = window->sessionController()) { if (const auto controller = window->sessionController()) {
controller->enableGifPauseReason( controller->enableGifPauseReason(
Window::GifPauseReason::RoundPlaying); Window::GifPauseReason::RoundPlaying);

View file

@ -303,8 +303,11 @@ void LaunchGApplication() {
app->signal_activate().connect([] { app->signal_activate().connect([] {
Core::Sandbox::Instance().customEnterFromEventLoop([] { Core::Sandbox::Instance().customEnterFromEventLoop([] {
if (const auto w = App::wnd()) { const auto window = Core::IsAppLaunched()
w->activate(); ? Core::App().primaryWindow()
: nullptr;
if (window) {
window->activate();
} }
}); });
}, true); }, true);
@ -329,17 +332,19 @@ void LaunchGApplication() {
continue; continue;
} }
if (Core::StartUrlRequiresActivate(url)) { if (Core::StartUrlRequiresActivate(url)) {
if (const auto w = App::wnd()) { const auto window = Core::IsAppLaunched()
w->activate(); ? Core::App().primaryWindow()
: nullptr;
if (window) {
window->activate();
} }
} }
cSetStartUrl(url); cSetStartUrl(url);
Core::App().checkStartUrl(); Core::App().checkStartUrl();
} }
if (!cSendPaths().isEmpty()) { if (!cSendPaths().isEmpty()) {
if (const auto w = App::wnd()) { Core::App().checkSendPaths();
w->sendPaths();
}
} }
}); });
}, true); }, true);
@ -429,7 +434,7 @@ bool GenerateDesktopFile(
} }
return std::string(); return std::string();
}(); }();
if (sourceText.empty()) { if (sourceText.empty()) {
if (!silent) { if (!silent) {
LOG(("App Error: Could not open '%1' for read").arg(sourceFile)); LOG(("App Error: Could not open '%1' for read").arg(sourceFile));

View file

@ -341,6 +341,10 @@ void Controller::hideSettingsAndLayer(anim::type animated) {
_widget.ui_hideSettingsAndLayer(animated); _widget.ui_hideSettingsAndLayer(animated);
} }
bool Controller::isLayerShown() const {
return _widget.ui_isLayerShown();
}
void Controller::sideBarChanged() { void Controller::sideBarChanged() {
_widget.recountGeometryConstraints(); _widget.recountGeometryConstraints();
} }

View file

@ -90,6 +90,7 @@ public:
void hideLayer(anim::type animated = anim::type::normal); void hideLayer(anim::type animated = anim::type::normal);
void hideSettingsAndLayer(anim::type animated = anim::type::normal); void hideSettingsAndLayer(anim::type animated = anim::type::normal);
[[nodiscard]] bool isLayerShown() const;
void activate(); void activate();
void reActivate(); void reActivate();

View file

@ -1769,6 +1769,10 @@ void SessionController::removeLayerBlackout() {
widget()->ui_removeLayerBlackout(); widget()->ui_removeLayerBlackout();
} }
bool SessionController::isLayerShown() const {
return _window->isLayerShown();
}
not_null<MainWidget*> SessionController::content() const { not_null<MainWidget*> SessionController::content() const {
return widget()->sessionContent(); return widget()->sessionContent();
} }

View file

@ -446,6 +446,7 @@ public:
showSpecialLayer(nullptr, animated); showSpecialLayer(nullptr, animated);
} }
void removeLayerBlackout(); void removeLayerBlackout();
[[nodiscard]] bool isLayerShown() const;
void showCalendar( void showCalendar(
Dialogs::Key chat, Dialogs::Key chat,