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 "Application.hpp"
|
||||||
#include "common/Args.hpp"
|
#include "common/Args.hpp"
|
||||||
#include "singletons/Paths.hpp"
|
#include "singletons/Paths.hpp"
|
||||||
|
#include "singletons/Updates.hpp"
|
||||||
|
|
||||||
namespace chatterino::mock {
|
namespace chatterino::mock {
|
||||||
|
|
||||||
class EmptyApplication : public IApplication
|
class EmptyApplication : public IApplication
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
EmptyApplication()
|
||||||
|
: updates_(this->paths_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~EmptyApplication() = default;
|
virtual ~EmptyApplication() = default;
|
||||||
|
|
||||||
const Paths &getPaths() override
|
const Paths &getPaths() override
|
||||||
|
@ -174,9 +180,15 @@ public:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Updates &getUpdates() override
|
||||||
|
{
|
||||||
|
return this->updates_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Paths paths_;
|
Paths paths_;
|
||||||
Args args_;
|
Args args_;
|
||||||
|
Updates updates_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino::mock
|
} // namespace chatterino::mock
|
||||||
|
|
|
@ -108,7 +108,7 @@ IApplication::IApplication()
|
||||||
// to each other
|
// to each other
|
||||||
|
|
||||||
Application::Application(Settings &_settings, const Paths &paths,
|
Application::Application(Settings &_settings, const Paths &paths,
|
||||||
const Args &_args)
|
const Args &_args, Updates &_updates)
|
||||||
: paths_(paths)
|
: paths_(paths)
|
||||||
, args_(_args)
|
, args_(_args)
|
||||||
, themes(&this->emplace<Theme>())
|
, themes(&this->emplace<Theme>())
|
||||||
|
@ -137,6 +137,7 @@ Application::Application(Settings &_settings, const Paths &paths,
|
||||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||||
, plugins(&this->emplace(new PluginController(paths)))
|
, plugins(&this->emplace(new PluginController(paths)))
|
||||||
#endif
|
#endif
|
||||||
|
, updates(_updates)
|
||||||
{
|
{
|
||||||
Application::instance = this;
|
Application::instance = this;
|
||||||
|
|
||||||
|
@ -239,8 +240,8 @@ int Application::run(QApplication &qtApp)
|
||||||
}
|
}
|
||||||
|
|
||||||
getSettings()->betaUpdates.connect(
|
getSettings()->betaUpdates.connect(
|
||||||
[] {
|
[this] {
|
||||||
Updates::instance().checkForUpdates();
|
this->updates.checkForUpdates();
|
||||||
},
|
},
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ class Args;
|
||||||
class TwitchIrcServer;
|
class TwitchIrcServer;
|
||||||
class ITwitchIrcServer;
|
class ITwitchIrcServer;
|
||||||
class PubSub;
|
class PubSub;
|
||||||
|
class Updates;
|
||||||
|
|
||||||
class CommandController;
|
class CommandController;
|
||||||
class AccountController;
|
class AccountController;
|
||||||
|
@ -79,6 +80,7 @@ public:
|
||||||
virtual ITwitchLiveController *getTwitchLiveController() = 0;
|
virtual ITwitchLiveController *getTwitchLiveController() = 0;
|
||||||
virtual ImageUploader *getImageUploader() = 0;
|
virtual ImageUploader *getImageUploader() = 0;
|
||||||
virtual SeventvAPI *getSeventvAPI() = 0;
|
virtual SeventvAPI *getSeventvAPI() = 0;
|
||||||
|
virtual Updates &getUpdates() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Application : public IApplication
|
class Application : public IApplication
|
||||||
|
@ -92,7 +94,8 @@ class Application : public IApplication
|
||||||
public:
|
public:
|
||||||
static Application *instance;
|
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() override;
|
||||||
|
|
||||||
Application(const Application &) = delete;
|
Application(const Application &) = delete;
|
||||||
|
@ -220,6 +223,10 @@ public:
|
||||||
{
|
{
|
||||||
return this->seventvAPI;
|
return this->seventvAPI;
|
||||||
}
|
}
|
||||||
|
Updates &getUpdates() override
|
||||||
|
{
|
||||||
|
return this->updates;
|
||||||
|
}
|
||||||
|
|
||||||
pajlada::Signals::NoArgSignal streamerModeChanged;
|
pajlada::Signals::NoArgSignal streamerModeChanged;
|
||||||
|
|
||||||
|
@ -248,6 +255,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeMessagingServer nmServer{};
|
NativeMessagingServer nmServer{};
|
||||||
|
Updates &updates;
|
||||||
};
|
};
|
||||||
|
|
||||||
Application *getApp();
|
Application *getApp();
|
||||||
|
|
|
@ -224,7 +224,7 @@ namespace {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void runGui(QApplication &a, const Paths &paths, Settings &settings,
|
void runGui(QApplication &a, const Paths &paths, Settings &settings,
|
||||||
const Args &args)
|
const Args &args, Updates &updates)
|
||||||
{
|
{
|
||||||
initQt();
|
initQt();
|
||||||
initResources();
|
initResources();
|
||||||
|
@ -270,9 +270,9 @@ void runGui(QApplication &a, const Paths &paths, Settings &settings,
|
||||||
});
|
});
|
||||||
|
|
||||||
chatterino::NetworkManager::init();
|
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.initialize(settings, paths);
|
||||||
app.run(a);
|
app.run(a);
|
||||||
app.save();
|
app.save();
|
||||||
|
|
|
@ -7,8 +7,9 @@ namespace chatterino {
|
||||||
class Args;
|
class Args;
|
||||||
class Paths;
|
class Paths;
|
||||||
class Settings;
|
class Settings;
|
||||||
|
class Updates;
|
||||||
|
|
||||||
void runGui(QApplication &a, const Paths &paths, Settings &settings,
|
void runGui(QApplication &a, const Paths &paths, Settings &settings,
|
||||||
const Args &args);
|
const Args &args, Updates &updates);
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "singletons/CrashHandler.hpp"
|
#include "singletons/CrashHandler.hpp"
|
||||||
#include "singletons/Paths.hpp"
|
#include "singletons/Paths.hpp"
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
|
#include "singletons/Updates.hpp"
|
||||||
#include "util/AttachToConsole.hpp"
|
#include "util/AttachToConsole.hpp"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
@ -92,6 +93,8 @@ int main(int argc, char **argv)
|
||||||
attachToConsole();
|
attachToConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Updates updates(*paths);
|
||||||
|
|
||||||
NetworkConfigurationProvider::applyFromEnv(Env::get());
|
NetworkConfigurationProvider::applyFromEnv(Env::get());
|
||||||
|
|
||||||
IvrApi::initialize();
|
IvrApi::initialize();
|
||||||
|
@ -99,7 +102,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
Settings settings(paths->settingsDirectory);
|
Settings settings(paths->settingsDirectory);
|
||||||
|
|
||||||
runGui(a, *paths, settings, args);
|
runGui(a, *paths, settings, args, updates);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,21 +26,14 @@ namespace {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Updates::Updates()
|
Updates::Updates(const Paths &paths_)
|
||||||
: currentVersion_(CHATTERINO_VERSION)
|
: paths(paths_)
|
||||||
|
, currentVersion_(CHATTERINO_VERSION)
|
||||||
, updateGuideLink_("https://chatterino.com")
|
, updateGuideLink_("https://chatterino.com")
|
||||||
{
|
{
|
||||||
qCDebug(chatterinoUpdate) << "init UpdateManager";
|
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.
|
/// Checks if the online version is newer or older than the current version.
|
||||||
bool Updates::isDowngradeOf(const QString &online, const QString ¤t)
|
bool Updates::isDowngradeOf(const QString &online, const QString ¤t)
|
||||||
{
|
{
|
||||||
|
@ -97,7 +90,7 @@ void Updates::installUpdates()
|
||||||
box->exec();
|
box->exec();
|
||||||
QDesktopServices::openUrl(this->updateGuideLink_);
|
QDesktopServices::openUrl(this->updateGuideLink_);
|
||||||
#elif defined Q_OS_WIN
|
#elif defined Q_OS_WIN
|
||||||
if (getPaths()->isPortable())
|
if (this->paths.isPortable())
|
||||||
{
|
{
|
||||||
QMessageBox *box =
|
QMessageBox *box =
|
||||||
new QMessageBox(QMessageBox::Information, "Chatterino Update",
|
new QMessageBox(QMessageBox::Information, "Chatterino Update",
|
||||||
|
@ -136,7 +129,7 @@ void Updates::installUpdates()
|
||||||
|
|
||||||
QByteArray object = result.getData();
|
QByteArray object = result.getData();
|
||||||
auto filename =
|
auto filename =
|
||||||
combinePath(getPaths()->miscDirectory, "update.zip");
|
combinePath(this->paths.miscDirectory, "update.zip");
|
||||||
|
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
|
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
|
||||||
|
@ -196,7 +189,7 @@ void Updates::installUpdates()
|
||||||
|
|
||||||
QByteArray object = result.getData();
|
QByteArray object = result.getData();
|
||||||
auto filePath =
|
auto filePath =
|
||||||
combinePath(getPaths()->miscDirectory, "Update.exe");
|
combinePath(this->paths.miscDirectory, "Update.exe");
|
||||||
|
|
||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
|
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
|
||||||
|
|
|
@ -5,11 +5,15 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
|
class Paths;
|
||||||
|
|
||||||
class Updates
|
class Updates
|
||||||
{
|
{
|
||||||
Updates();
|
const Paths &paths;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
explicit Updates(const Paths &paths_);
|
||||||
|
|
||||||
enum Status {
|
enum Status {
|
||||||
None,
|
None,
|
||||||
Searching,
|
Searching,
|
||||||
|
@ -21,9 +25,6 @@ public:
|
||||||
WriteFileFailed,
|
WriteFileFailed,
|
||||||
};
|
};
|
||||||
|
|
||||||
// fourtf: don't add this class to the application class
|
|
||||||
static Updates &instance();
|
|
||||||
|
|
||||||
static bool isDowngradeOf(const QString &online, const QString ¤t);
|
static bool isDowngradeOf(const QString &online, const QString ¤t);
|
||||||
|
|
||||||
void checkForUpdates();
|
void checkForUpdates();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "util/InitUpdateButton.hpp"
|
#include "util/InitUpdateButton.hpp"
|
||||||
|
|
||||||
|
#include "Application.hpp"
|
||||||
#include "widgets/dialogs/UpdateDialog.hpp"
|
#include "widgets/dialogs/UpdateDialog.hpp"
|
||||||
#include "widgets/helper/Button.hpp"
|
#include "widgets/helper/Button.hpp"
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ void initUpdateButton(Button &button,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UpdateDialog::Install: {
|
case UpdateDialog::Install: {
|
||||||
Updates::instance().installUpdates();
|
getIApp()->getUpdates().installUpdates();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -52,17 +53,17 @@ void initUpdateButton(Button &button,
|
||||||
|
|
||||||
// update image when state changes
|
// update image when state changes
|
||||||
auto updateChange = [&button](auto) {
|
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/updateError.png"
|
||||||
: ":/buttons/update.png";
|
: ":/buttons/update.png";
|
||||||
button.setPixmap(QPixmap(imageUrl));
|
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](auto status) {
|
||||||
updateChange(status);
|
updateChange(status);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "UpdateDialog.hpp"
|
#include "widgets/dialogs/UpdateDialog.hpp"
|
||||||
|
|
||||||
|
#include "Application.hpp"
|
||||||
#include "singletons/Updates.hpp"
|
#include "singletons/Updates.hpp"
|
||||||
#include "util/LayoutCreator.hpp"
|
#include "util/LayoutCreator.hpp"
|
||||||
#include "widgets/Label.hpp"
|
#include "widgets/Label.hpp"
|
||||||
|
@ -26,7 +27,7 @@ UpdateDialog::UpdateDialog()
|
||||||
auto *dismiss = buttons->addButton("Dismiss", QDialogButtonBox::RejectRole);
|
auto *dismiss = buttons->addButton("Dismiss", QDialogButtonBox::RejectRole);
|
||||||
|
|
||||||
QObject::connect(install, &QPushButton::clicked, this, [this] {
|
QObject::connect(install, &QPushButton::clicked, this, [this] {
|
||||||
Updates::instance().installUpdates();
|
getIApp()->getUpdates().installUpdates();
|
||||||
this->close();
|
this->close();
|
||||||
});
|
});
|
||||||
QObject::connect(dismiss, &QPushButton::clicked, this, [this] {
|
QObject::connect(dismiss, &QPushButton::clicked, this, [this] {
|
||||||
|
@ -34,8 +35,8 @@ UpdateDialog::UpdateDialog()
|
||||||
this->close();
|
this->close();
|
||||||
});
|
});
|
||||||
|
|
||||||
this->updateStatusChanged(Updates::instance().getStatus());
|
this->updateStatusChanged(getIApp()->getUpdates().getStatus());
|
||||||
this->connections_.managedConnect(Updates::instance().statusUpdated,
|
this->connections_.managedConnect(getIApp()->getUpdates().statusUpdated,
|
||||||
[this](auto status) {
|
[this](auto status) {
|
||||||
this->updateStatusChanged(status);
|
this->updateStatusChanged(status);
|
||||||
});
|
});
|
||||||
|
@ -52,17 +53,17 @@ void UpdateDialog::updateStatusChanged(Updates::Status status)
|
||||||
{
|
{
|
||||||
case Updates::UpdateAvailable: {
|
case Updates::UpdateAvailable: {
|
||||||
this->ui_.label->setText((
|
this->ui_.label->setText((
|
||||||
Updates::instance().isDowngrade()
|
getIApp()->getUpdates().isDowngrade()
|
||||||
? QString(
|
? QString(
|
||||||
"The version online (%1) seems to be\nlower than the "
|
"The version online (%1) seems to be\nlower than the "
|
||||||
"current (%2).\nEither a version was reverted or "
|
"current (%2).\nEither a version was reverted or "
|
||||||
"you are\nrunning a newer build.\n\nDo you want to "
|
"you are\nrunning a newer build.\n\nDo you want to "
|
||||||
"download and install it?")
|
"download and install it?")
|
||||||
.arg(Updates::instance().getOnlineVersion(),
|
.arg(getIApp()->getUpdates().getOnlineVersion(),
|
||||||
Updates::instance().getCurrentVersion())
|
getIApp()->getUpdates().getCurrentVersion())
|
||||||
: QString("An update (%1) is available.\n\nDo you want to "
|
: QString("An update (%1) is available.\n\nDo you want to "
|
||||||
"download and install it?")
|
"download and install it?")
|
||||||
.arg(Updates::instance().getOnlineVersion())));
|
.arg(getIApp()->getUpdates().getOnlineVersion())));
|
||||||
this->updateGeometry();
|
this->updateGeometry();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue