refactor: Un-singletonize Paths & Updates (#5092)

This commit is contained in:
pajlada
2024-01-16 21:56:43 +01:00
committed by GitHub
parent 7f935665f9
commit 718696db53
60 changed files with 237 additions and 165 deletions
+2 -3
View File
@@ -43,7 +43,7 @@ namespace chatterino {
using namespace literals;
LastRunCrashDialog::LastRunCrashDialog(const Args &args)
LastRunCrashDialog::LastRunCrashDialog(const Args &args, const Paths &paths)
{
this->setWindowFlag(Qt::WindowContextHelpButtonHint, false);
this->setWindowTitle(u"Chatterino - " % randomMessage());
@@ -56,8 +56,7 @@ LastRunCrashDialog::LastRunCrashDialog(const Args &args)
"<i>You can disable automatic restarts in the settings.</i><br><br>";
#ifdef CHATTERINO_WITH_CRASHPAD
auto reportsDir =
QDir(getPaths()->crashdumpDirectory).filePath(u"reports"_s);
auto reportsDir = QDir(paths.crashdumpDirectory).filePath(u"reports"_s);
text += u"A <b>crash report</b> has been saved to "
"<a href=\"file:///" %
reportsDir % u"\">" % reportsDir % u"</a>.<br>";
+2 -1
View File
@@ -5,11 +5,12 @@
namespace chatterino {
class Args;
class Paths;
class LastRunCrashDialog : public QDialog
{
public:
explicit LastRunCrashDialog(const Args &args);
explicit LastRunCrashDialog(const Args &args, const Paths &paths);
};
} // namespace chatterino
+9 -8
View File
@@ -1,5 +1,6 @@
#include "UpdateDialog.hpp"
#include "widgets/dialogs/UpdateDialog.hpp"
#include "Application.hpp"
#include "singletons/Updates.hpp"
#include "util/LayoutCreator.hpp"
#include "widgets/Label.hpp"
@@ -26,7 +27,7 @@ UpdateDialog::UpdateDialog()
auto *dismiss = buttons->addButton("Dismiss", QDialogButtonBox::RejectRole);
QObject::connect(install, &QPushButton::clicked, this, [this] {
Updates::instance().installUpdates();
getIApp()->getUpdates().installUpdates();
this->close();
});
QObject::connect(dismiss, &QPushButton::clicked, this, [this] {
@@ -34,8 +35,8 @@ UpdateDialog::UpdateDialog()
this->close();
});
this->updateStatusChanged(Updates::instance().getStatus());
this->connections_.managedConnect(Updates::instance().statusUpdated,
this->updateStatusChanged(getIApp()->getUpdates().getStatus());
this->connections_.managedConnect(getIApp()->getUpdates().statusUpdated,
[this](auto status) {
this->updateStatusChanged(status);
});
@@ -52,17 +53,17 @@ void UpdateDialog::updateStatusChanged(Updates::Status status)
{
case Updates::UpdateAvailable: {
this->ui_.label->setText((
Updates::instance().isDowngrade()
getIApp()->getUpdates().isDowngrade()
? QString(
"The version online (%1) seems to be\nlower than the "
"current (%2).\nEither a version was reverted or "
"you are\nrunning a newer build.\n\nDo you want to "
"download and install it?")
.arg(Updates::instance().getOnlineVersion(),
Updates::instance().getCurrentVersion())
.arg(getIApp()->getUpdates().getOnlineVersion(),
getIApp()->getUpdates().getCurrentVersion())
: QString("An update (%1) is available.\n\nDo you want to "
"download and install it?")
.arg(Updates::instance().getOnlineVersion())));
.arg(getIApp()->getUpdates().getOnlineVersion())));
this->updateGeometry();
}
break;
+8 -7
View File
@@ -791,9 +791,10 @@ void GeneralPage::initLayout(GeneralPageView &layout)
"store in this directory.");
layout.addButton("Open AppData directory", [] {
#ifdef Q_OS_DARWIN
QDesktopServices::openUrl("file://" + getPaths()->rootAppDataDirectory);
QDesktopServices::openUrl("file://" +
getIApp()->getPaths().rootAppDataDirectory);
#else
QDesktopServices::openUrl(getPaths()->rootAppDataDirectory);
QDesktopServices::openUrl(getIApp()->getPaths().rootAppDataDirectory);
#endif
});
@@ -805,7 +806,7 @@ void GeneralPage::initLayout(GeneralPageView &layout)
auto *cachePathLabel = layout.addDescription("placeholder :D");
getSettings()->cachePath.connect([cachePathLabel](const auto &,
auto) mutable {
QString newPath = getPaths()->cacheDirectory();
QString newPath = getIApp()->getPaths().cacheDirectory();
QString pathShortened = "Cache saved at <a href=\"file:///" + newPath +
"\"><span style=\"color: white;\">" +
@@ -833,9 +834,9 @@ void GeneralPage::initLayout(GeneralPageView &layout)
if (reply == QMessageBox::Yes)
{
auto cacheDir = QDir(getPaths()->cacheDirectory());
auto cacheDir = QDir(getIApp()->getPaths().cacheDirectory());
cacheDir.removeRecursively();
cacheDir.mkdir(getPaths()->cacheDirectory());
cacheDir.mkdir(getIApp()->getPaths().cacheDirectory());
}
}));
box->addStretch(1);
@@ -947,7 +948,7 @@ void GeneralPage::initLayout(GeneralPageView &layout)
"When possible, restart Chatterino if the program crashes");
#if defined(Q_OS_LINUX) && !defined(NO_QTKEYCHAIN)
if (!getPaths()->isPortable())
if (!getIApp()->getPaths().isPortable())
{
layout.addCheckbox(
"Use libsecret/KWallet/Gnome keychain to secure passwords",
@@ -1232,7 +1233,7 @@ void GeneralPage::initExtra()
{
getSettings()->cachePath.connect(
[cachePath = this->cachePath_](const auto &, auto) mutable {
QString newPath = getPaths()->cacheDirectory();
QString newPath = getIApp()->getPaths().cacheDirectory();
QString pathShortened = "Current location: <a href=\"file:///" +
newPath + "\">" +
+3 -2
View File
@@ -54,7 +54,7 @@ QString formatSize(qint64 size)
QString fetchLogDirectorySize()
{
QString logsDirectoryPath = getSettings()->logPath.getValue().isEmpty()
? getPaths()->messageLogDirectory
? getIApp()->getPaths().messageLogDirectory
: getSettings()->logPath;
auto logsSize = dirSize(logsDirectoryPath);
@@ -82,7 +82,8 @@ ModerationPage::ModerationPage()
getSettings()->logPath.connect([logsPathLabel](const QString &logPath,
auto) mutable {
QString pathOriginal =
logPath.isEmpty() ? getPaths()->messageLogDirectory : logPath;
logPath.isEmpty() ? getIApp()->getPaths().messageLogDirectory
: logPath;
QString pathShortened =
"Logs are saved at <a href=\"file:///" + pathOriginal +
+6 -5
View File
@@ -37,11 +37,12 @@ PluginsPage::PluginsPage()
auto group = layout.emplace<QGroupBox>("General plugin settings");
this->generalGroup = group.getElement();
auto groupLayout = group.setLayoutType<QFormLayout>();
auto *description = new QLabel(
"You can load plugins by putting them into " +
formatRichNamedLink("file:///" + getPaths()->pluginsDirectory,
"the Plugins directory") +
". Each one is a new directory.");
auto *description =
new QLabel("You can load plugins by putting them into " +
formatRichNamedLink(
"file:///" + getIApp()->getPaths().pluginsDirectory,
"the Plugins directory") +
". Each one is a new directory.");
description->setOpenExternalLinks(true);
description->setWordWrap(true);
description->setStyleSheet("color: #bbb");