mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Make Updates non-singletonized, removing usage of getPaths()
This commit is contained in:
parent
b3d9f72206
commit
c98d54812c
10 changed files with 60 additions and 39 deletions
|
@ -3,12 +3,18 @@
|
|||
#include "Application.hpp"
|
||||
#include "common/Args.hpp"
|
||||
#include "singletons/Paths.hpp"
|
||||
#include "singletons/Updates.hpp"
|
||||
|
||||
namespace chatterino::mock {
|
||||
|
||||
class EmptyApplication : public IApplication
|
||||
{
|
||||
public:
|
||||
EmptyApplication()
|
||||
: updates_(this->paths_)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~EmptyApplication() = default;
|
||||
|
||||
const Paths &getPaths() override
|
||||
|
@ -174,9 +180,15 @@ public:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Updates &getUpdates() override
|
||||
{
|
||||
return this->updates_;
|
||||
}
|
||||
|
||||
private:
|
||||
Paths paths_;
|
||||
Args args_;
|
||||
Updates updates_;
|
||||
};
|
||||
|
||||
} // namespace chatterino::mock
|
||||
|
|
|
@ -108,7 +108,7 @@ IApplication::IApplication()
|
|||
// to each other
|
||||
|
||||
Application::Application(Settings &_settings, const Paths &paths,
|
||||
const Args &_args)
|
||||
const Args &_args, Updates &_updates)
|
||||
: paths_(paths)
|
||||
, args_(_args)
|
||||
, themes(&this->emplace<Theme>())
|
||||
|
@ -137,6 +137,7 @@ Application::Application(Settings &_settings, const Paths &paths,
|
|||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
, plugins(&this->emplace(new PluginController(paths)))
|
||||
#endif
|
||||
, updates(_updates)
|
||||
{
|
||||
Application::instance = this;
|
||||
|
||||
|
@ -239,8 +240,8 @@ int Application::run(QApplication &qtApp)
|
|||
}
|
||||
|
||||
getSettings()->betaUpdates.connect(
|
||||
[] {
|
||||
Updates::instance().checkForUpdates();
|
||||
[this] {
|
||||
this->updates.checkForUpdates();
|
||||
},
|
||||
false);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ class Args;
|
|||
class TwitchIrcServer;
|
||||
class ITwitchIrcServer;
|
||||
class PubSub;
|
||||
class Updates;
|
||||
|
||||
class CommandController;
|
||||
class AccountController;
|
||||
|
@ -79,6 +80,7 @@ public:
|
|||
virtual ITwitchLiveController *getTwitchLiveController() = 0;
|
||||
virtual ImageUploader *getImageUploader() = 0;
|
||||
virtual SeventvAPI *getSeventvAPI() = 0;
|
||||
virtual Updates &getUpdates() = 0;
|
||||
};
|
||||
|
||||
class Application : public IApplication
|
||||
|
@ -92,7 +94,8 @@ class Application : public IApplication
|
|||
public:
|
||||
static Application *instance;
|
||||
|
||||
Application(Settings &_settings, const Paths &paths, const Args &_args);
|
||||
Application(Settings &_settings, const Paths &paths, const Args &_args,
|
||||
Updates &_updates);
|
||||
~Application() override;
|
||||
|
||||
Application(const Application &) = delete;
|
||||
|
@ -220,6 +223,10 @@ public:
|
|||
{
|
||||
return this->seventvAPI;
|
||||
}
|
||||
Updates &getUpdates() override
|
||||
{
|
||||
return this->updates;
|
||||
}
|
||||
|
||||
pajlada::Signals::NoArgSignal streamerModeChanged;
|
||||
|
||||
|
@ -248,6 +255,7 @@ private:
|
|||
}
|
||||
|
||||
NativeMessagingServer nmServer{};
|
||||
Updates &updates;
|
||||
};
|
||||
|
||||
Application *getApp();
|
||||
|
|
|
@ -224,7 +224,7 @@ namespace {
|
|||
} // namespace
|
||||
|
||||
void runGui(QApplication &a, const Paths &paths, Settings &settings,
|
||||
const Args &args)
|
||||
const Args &args, Updates &updates)
|
||||
{
|
||||
initQt();
|
||||
initResources();
|
||||
|
@ -270,9 +270,9 @@ void runGui(QApplication &a, const Paths &paths, Settings &settings,
|
|||
});
|
||||
|
||||
chatterino::NetworkManager::init();
|
||||
chatterino::Updates::instance().checkForUpdates();
|
||||
updates.checkForUpdates();
|
||||
|
||||
Application app(settings, paths, args);
|
||||
Application app(settings, paths, args, updates);
|
||||
app.initialize(settings, paths);
|
||||
app.run(a);
|
||||
app.save();
|
||||
|
|
|
@ -7,8 +7,9 @@ namespace chatterino {
|
|||
class Args;
|
||||
class Paths;
|
||||
class Settings;
|
||||
class Updates;
|
||||
|
||||
void runGui(QApplication &a, const Paths &paths, Settings &settings,
|
||||
const Args &args);
|
||||
const Args &args, Updates &updates);
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "singletons/CrashHandler.hpp"
|
||||
#include "singletons/Paths.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/Updates.hpp"
|
||||
#include "util/AttachToConsole.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
|
@ -92,6 +93,8 @@ int main(int argc, char **argv)
|
|||
attachToConsole();
|
||||
}
|
||||
|
||||
Updates updates(*paths);
|
||||
|
||||
NetworkConfigurationProvider::applyFromEnv(Env::get());
|
||||
|
||||
IvrApi::initialize();
|
||||
|
@ -99,7 +102,7 @@ int main(int argc, char **argv)
|
|||
|
||||
Settings settings(paths->settingsDirectory);
|
||||
|
||||
runGui(a, *paths, settings, args);
|
||||
runGui(a, *paths, settings, args, updates);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -26,21 +26,14 @@ namespace {
|
|||
|
||||
} // namespace
|
||||
|
||||
Updates::Updates()
|
||||
: currentVersion_(CHATTERINO_VERSION)
|
||||
Updates::Updates(const Paths &paths_)
|
||||
: paths(paths_)
|
||||
, currentVersion_(CHATTERINO_VERSION)
|
||||
, updateGuideLink_("https://chatterino.com")
|
||||
{
|
||||
qCDebug(chatterinoUpdate) << "init UpdateManager";
|
||||
}
|
||||
|
||||
Updates &Updates::instance()
|
||||
{
|
||||
// fourtf: don't add this class to the application class
|
||||
static Updates instance;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/// Checks if the online version is newer or older than the current version.
|
||||
bool Updates::isDowngradeOf(const QString &online, const QString ¤t)
|
||||
{
|
||||
|
@ -97,7 +90,7 @@ void Updates::installUpdates()
|
|||
box->exec();
|
||||
QDesktopServices::openUrl(this->updateGuideLink_);
|
||||
#elif defined Q_OS_WIN
|
||||
if (getPaths()->isPortable())
|
||||
if (this->paths.isPortable())
|
||||
{
|
||||
QMessageBox *box =
|
||||
new QMessageBox(QMessageBox::Information, "Chatterino Update",
|
||||
|
@ -136,7 +129,7 @@ void Updates::installUpdates()
|
|||
|
||||
QByteArray object = result.getData();
|
||||
auto filename =
|
||||
combinePath(getPaths()->miscDirectory, "update.zip");
|
||||
combinePath(this->paths.miscDirectory, "update.zip");
|
||||
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
|
||||
|
@ -196,7 +189,7 @@ void Updates::installUpdates()
|
|||
|
||||
QByteArray object = result.getData();
|
||||
auto filePath =
|
||||
combinePath(getPaths()->miscDirectory, "Update.exe");
|
||||
combinePath(this->paths.miscDirectory, "Update.exe");
|
||||
|
||||
QFile file(filePath);
|
||||
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
|
||||
|
|
|
@ -5,11 +5,15 @@
|
|||
|
||||
namespace chatterino {
|
||||
|
||||
class Paths;
|
||||
|
||||
class Updates
|
||||
{
|
||||
Updates();
|
||||
const Paths &paths;
|
||||
|
||||
public:
|
||||
explicit Updates(const Paths &paths_);
|
||||
|
||||
enum Status {
|
||||
None,
|
||||
Searching,
|
||||
|
@ -21,9 +25,6 @@ public:
|
|||
WriteFileFailed,
|
||||
};
|
||||
|
||||
// fourtf: don't add this class to the application class
|
||||
static Updates &instance();
|
||||
|
||||
static bool isDowngradeOf(const QString &online, const QString ¤t);
|
||||
|
||||
void checkForUpdates();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "util/InitUpdateButton.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "widgets/dialogs/UpdateDialog.hpp"
|
||||
#include "widgets/helper/Button.hpp"
|
||||
|
||||
|
@ -40,7 +41,7 @@ void initUpdateButton(Button &button,
|
|||
}
|
||||
break;
|
||||
case UpdateDialog::Install: {
|
||||
Updates::instance().installUpdates();
|
||||
getIApp()->getUpdates().installUpdates();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -52,17 +53,17 @@ void initUpdateButton(Button &button,
|
|||
|
||||
// update image when state changes
|
||||
auto updateChange = [&button](auto) {
|
||||
button.setVisible(Updates::instance().shouldShowUpdateButton());
|
||||
button.setVisible(getIApp()->getUpdates().shouldShowUpdateButton());
|
||||
|
||||
const auto *imageUrl = Updates::instance().isError()
|
||||
const auto *imageUrl = getIApp()->getUpdates().isError()
|
||||
? ":/buttons/updateError.png"
|
||||
: ":/buttons/update.png";
|
||||
button.setPixmap(QPixmap(imageUrl));
|
||||
};
|
||||
|
||||
updateChange(Updates::instance().getStatus());
|
||||
updateChange(getIApp()->getUpdates().getStatus());
|
||||
|
||||
signalHolder.managedConnect(Updates::instance().statusUpdated,
|
||||
signalHolder.managedConnect(getIApp()->getUpdates().statusUpdated,
|
||||
[updateChange](auto status) {
|
||||
updateChange(status);
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue