diff --git a/CHANGELOG.md b/CHANGELOG.md index 681693df..7be5dffa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ - Dev: Added a `run-and-kill.sh` script to help debug crash-on-exit bugs. (#6188) - Dev: Updated GoogleTest to v1.17.0. (#6180) - Dev: Mini refactor of `TwitchAccount`. (#6182) +- Dev: Refactored away some `getApp` usages in `WindowManager`. (#6194) - Dev: Simplified string literals to be a re-export of Qt functions. (#6175) ## 2.5.3 diff --git a/src/Application.cpp b/src/Application.cpp index afd96485..1e50664c 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -166,7 +166,8 @@ Application::Application(Settings &_settings, const Paths &paths, , accounts(new AccountController) , eventSub(makeEventSubController(_settings)) , hotkeys(new HotkeyController) - , windows(new WindowManager(paths, _settings, *this->themes, *this->fonts)) + , windows(new WindowManager(_args, paths, _settings, *this->themes, + *this->fonts)) , toasts(new Toasts) , imageUploader(new ImageUploader) , seventvAPI(new SeventvAPI) diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index 7fd2f5a4..94b9f66e 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -72,7 +72,7 @@ using SplitNode = SplitContainer::Node; void WindowManager::showSettingsDialog(QWidget *parent, SettingsDialogPreference preference) { - if (getApp()->getArgs().dontSaveSettings) + if (this->appArgs.dontSaveSettings) { QMessageBox::critical(parent, "Chatterino - Editing Settings Forbidden", "Settings cannot be edited when running with\n" @@ -103,9 +103,10 @@ void WindowManager::showAccountSelectPopup(QPoint point) w->setFocus(); } -WindowManager::WindowManager(const Paths &paths, Settings &settings, - Theme &themes_, Fonts &fonts) +WindowManager::WindowManager(const Args &appArgs_, const Paths &paths, + Settings &settings, Theme &themes_, Fonts &fonts) : themes(themes_) + , appArgs(appArgs_) , windowLayoutFilePath(combinePath(paths.settingsDirectory, WindowManager::WINDOW_LAYOUT_FILENAME)) , updateWordTypeMaskListener([this] { @@ -411,16 +412,16 @@ void WindowManager::initialize() { WindowLayout windowLayout; - if (getApp()->getArgs().customChannelLayout) + if (this->appArgs.customChannelLayout) { - windowLayout = getApp()->getArgs().customChannelLayout.value(); + windowLayout = this->appArgs.customChannelLayout.value(); } else { windowLayout = this->loadWindowLayoutFromFile(); } - auto desired = getApp()->getArgs().activateChannel; + auto desired = this->appArgs.activateChannel; if (desired) { windowLayout.activateOrAddChannel(desired->provider, desired->name); @@ -431,7 +432,7 @@ void WindowManager::initialize() this->applyWindowLayout(windowLayout); } - if (getApp()->getArgs().isFramelessEmbed) + if (this->appArgs.isFramelessEmbed) { this->framelessEmbedWindow_.reset(new FramelessEmbedWindow); this->framelessEmbedWindow_->show(); @@ -444,7 +445,7 @@ void WindowManager::initialize() this->mainWindow_->getNotebook().addPage(true); // TODO: don't create main window if it's a frameless embed - if (getApp()->getArgs().isFramelessEmbed) + if (this->appArgs.isFramelessEmbed) { this->mainWindow_->hide(); } @@ -453,7 +454,7 @@ void WindowManager::initialize() void WindowManager::save() { - if (getApp()->getArgs().dontSaveSettings) + if (this->appArgs.dontSaveSettings) { return; } @@ -817,7 +818,7 @@ WindowLayout WindowManager::loadWindowLayoutFromFile() const void WindowManager::applyWindowLayout(const WindowLayout &layout) { - if (getApp()->getArgs().dontLoadMainWindow) + if (this->appArgs.dontLoadMainWindow) { return; } diff --git a/src/singletons/WindowManager.hpp b/src/singletons/WindowManager.hpp index f5957bdf..066cf5d1 100644 --- a/src/singletons/WindowManager.hpp +++ b/src/singletons/WindowManager.hpp @@ -14,6 +14,7 @@ namespace chatterino { class Settings; +class Args; class Paths; class Window; class ChannelView; @@ -38,12 +39,13 @@ class FramelessEmbedWindow; class WindowManager final { Theme &themes; + const Args &appArgs; public: static const QString WINDOW_LAYOUT_FILENAME; - explicit WindowManager(const Paths &paths, Settings &settings, - Theme &themes_, Fonts &fonts); + explicit WindowManager(const Args &appArgs_, const Paths &paths, + Settings &settings, Theme &themes_, Fonts &fonts); ~WindowManager(); WindowManager(const WindowManager &) = delete; diff --git a/tests/src/MessageLayout.cpp b/tests/src/MessageLayout.cpp index 72b50f87..5c438be7 100644 --- a/tests/src/MessageLayout.cpp +++ b/tests/src/MessageLayout.cpp @@ -26,7 +26,8 @@ class MockApplication : public mock::BaseApplication { public: MockApplication() - : windowManager(this->paths_, this->settings, this->theme, this->fonts) + : windowManager(this->args, this->paths_, this->settings, this->theme, + this->fonts) { } diff --git a/tests/src/Scrollbar.cpp b/tests/src/Scrollbar.cpp index 37a7de6e..a772a8fb 100644 --- a/tests/src/Scrollbar.cpp +++ b/tests/src/Scrollbar.cpp @@ -21,7 +21,8 @@ class MockApplication : public mock::BaseApplication { public: MockApplication() - : windowManager(this->paths_, this->settings, this->theme, this->fonts) + : windowManager(this->args, this->paths_, this->settings, this->theme, + this->fonts) { } diff --git a/tests/src/SplitInput.cpp b/tests/src/SplitInput.cpp index edd9431d..55705d10 100644 --- a/tests/src/SplitInput.cpp +++ b/tests/src/SplitInput.cpp @@ -28,7 +28,8 @@ class MockApplication : public mock::BaseApplication { public: MockApplication() - : windowManager(this->paths_, this->settings, this->theme, this->fonts) + : windowManager(this->args, this->paths_, this->settings, this->theme, + this->fonts) , commands(this->paths_) { }