refactor: Make Args less of a singleton (#5041)
This means it's no longer a singleton, and its lifetime is bound to our application. This felt like a good small experiment to see how its changes would look if we did this. As a shortcut, `getApp` that is already a mega singleton keeps a reference to Args, this means places that are a bit more difficult to inject into call `getApp()->getArgs()` just like other things are accessed.
This commit is contained in:
@@ -64,13 +64,13 @@ bool FramelessEmbedWindow::nativeEvent(const QByteArray &eventType,
|
||||
|
||||
void FramelessEmbedWindow::showEvent(QShowEvent *)
|
||||
{
|
||||
if (!getArgs().parentWindowId)
|
||||
if (!getApp()->getArgs().parentWindowId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto parentHwnd =
|
||||
reinterpret_cast<HWND>(getArgs().parentWindowId.value()))
|
||||
reinterpret_cast<HWND>(getApp()->getArgs().parentWindowId.value()))
|
||||
{
|
||||
auto handle = reinterpret_cast<HWND>(this->winId());
|
||||
if (!::SetParent(handle, parentHwnd))
|
||||
|
||||
@@ -1347,7 +1347,7 @@ void SplitNotebook::addCustomButtons()
|
||||
auto settingsBtn = this->addCustomButton();
|
||||
|
||||
// This is to ensure you can't lock yourself out of the settings
|
||||
if (getArgs().safeMode)
|
||||
if (getApp()->getArgs().safeMode)
|
||||
{
|
||||
settingsBtn->setVisible(true);
|
||||
}
|
||||
|
||||
@@ -737,7 +737,7 @@ void Window::onAccountSelected()
|
||||
}
|
||||
#endif
|
||||
|
||||
if (getArgs().safeMode)
|
||||
if (getApp()->getArgs().safeMode)
|
||||
{
|
||||
windowTitle += " (safe mode)";
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace chatterino {
|
||||
|
||||
using namespace literals;
|
||||
|
||||
LastRunCrashDialog::LastRunCrashDialog()
|
||||
LastRunCrashDialog::LastRunCrashDialog(const Args &args)
|
||||
{
|
||||
this->setWindowFlag(Qt::WindowContextHelpButtonHint, false);
|
||||
this->setWindowTitle(u"Chatterino - " % randomMessage());
|
||||
@@ -62,14 +62,14 @@ LastRunCrashDialog::LastRunCrashDialog()
|
||||
"<a href=\"file:///" %
|
||||
reportsDir % u"\">" % reportsDir % u"</a>.<br>";
|
||||
|
||||
if (getArgs().exceptionCode)
|
||||
if (args.exceptionCode)
|
||||
{
|
||||
text += u"The last run crashed with code <code>0x" %
|
||||
QString::number(*getArgs().exceptionCode, 16) % u"</code>";
|
||||
QString::number(*args.exceptionCode, 16) % u"</code>";
|
||||
|
||||
if (getArgs().exceptionMessage)
|
||||
if (args.exceptionMessage)
|
||||
{
|
||||
text += u" (" % *getArgs().exceptionMessage % u")";
|
||||
text += u" (" % *args.exceptionMessage % u")";
|
||||
}
|
||||
|
||||
text += u".<br>"_s;
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Args;
|
||||
|
||||
class LastRunCrashDialog : public QDialog
|
||||
{
|
||||
public:
|
||||
LastRunCrashDialog();
|
||||
explicit LastRunCrashDialog(const Args &args);
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -411,7 +411,7 @@ void SettingsDialog::showEvent(QShowEvent *e)
|
||||
///// Widget creation helpers
|
||||
void SettingsDialog::onOkClicked()
|
||||
{
|
||||
if (!getArgs().dontSaveSettings)
|
||||
if (!getApp()->getArgs().dontSaveSettings)
|
||||
{
|
||||
getApp()->commands->save();
|
||||
pajlada::Settings::SettingManager::gSave();
|
||||
|
||||
@@ -53,7 +53,7 @@ PluginsPage::PluginsPage()
|
||||
this->rebuildContent();
|
||||
});
|
||||
groupLayout->addRow(box);
|
||||
if (getArgs().safeMode)
|
||||
if (getApp()->getArgs().safeMode)
|
||||
{
|
||||
box->setEnabled(false);
|
||||
auto *disabledLabel = new QLabel(this);
|
||||
@@ -197,7 +197,7 @@ void PluginsPage::rebuildContent()
|
||||
this->rebuildContent();
|
||||
});
|
||||
pluginEntry->addRow(reloadButton);
|
||||
if (getArgs().safeMode)
|
||||
if (getApp()->getArgs().safeMode)
|
||||
{
|
||||
reloadButton->setEnabled(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user