chore: unsingletonize UserDataController (#5459)
The `user-data.json` file will save immediately on change, and on exit (on dtor) if necessary. So we don't need to manually call save
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
- Dev: Images are now loaded in worker threads. (#5431)
|
- Dev: Images are now loaded in worker threads. (#5431)
|
||||||
- Dev: Qt Creator now auto-configures Conan when loading the project and skips vcpkg. (#5305)
|
- Dev: Qt Creator now auto-configures Conan when loading the project and skips vcpkg. (#5305)
|
||||||
- Dev: The MSVC CRT is now bundled with Chatterino as it depends on having a recent version installed. (#5447)
|
- Dev: The MSVC CRT is now bundled with Chatterino as it depends on having a recent version installed. (#5447)
|
||||||
|
- Dev: Refactor/unsingletonize `UserDataController`. (#5459)
|
||||||
|
|
||||||
## 2.5.1
|
## 2.5.1
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -135,7 +135,7 @@ Application::Application(Settings &_settings, const Paths &paths,
|
|||||||
, twitch(new TwitchIrcServer)
|
, twitch(new TwitchIrcServer)
|
||||||
, ffzBadges(&this->emplace<FfzBadges>())
|
, ffzBadges(&this->emplace<FfzBadges>())
|
||||||
, seventvBadges(&this->emplace<SeventvBadges>())
|
, seventvBadges(&this->emplace<SeventvBadges>())
|
||||||
, userData(&this->emplace(new UserDataController(paths)))
|
, userData(new UserDataController(paths))
|
||||||
, sound(&this->emplace<ISoundController>(makeSoundController(_settings)))
|
, sound(&this->emplace<ISoundController>(makeSoundController(_settings)))
|
||||||
, twitchLiveController(&this->emplace<TwitchLiveController>())
|
, twitchLiveController(&this->emplace<TwitchLiveController>())
|
||||||
, twitchPubSub(new PubSub(TWITCH_PUBSUB_URL))
|
, twitchPubSub(new PubSub(TWITCH_PUBSUB_URL))
|
||||||
@@ -173,6 +173,7 @@ void Application::fakeDtor()
|
|||||||
this->seventvEmotes.reset();
|
this->seventvEmotes.reset();
|
||||||
// this->twitch.reset();
|
// this->twitch.reset();
|
||||||
this->fonts.reset();
|
this->fonts.reset();
|
||||||
|
this->userData.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::initialize(Settings &settings, const Paths &paths)
|
void Application::initialize(Settings &settings, const Paths &paths)
|
||||||
@@ -427,7 +428,7 @@ IUserDataController *Application::getUserData()
|
|||||||
{
|
{
|
||||||
assertInGuiThread();
|
assertInGuiThread();
|
||||||
|
|
||||||
return this->userData;
|
return this->userData.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
ISoundController *Application::getSound()
|
ISoundController *Application::getSound()
|
||||||
|
|||||||
+1
-1
@@ -160,7 +160,7 @@ private:
|
|||||||
std::unique_ptr<TwitchIrcServer> twitch;
|
std::unique_ptr<TwitchIrcServer> twitch;
|
||||||
FfzBadges *const ffzBadges{};
|
FfzBadges *const ffzBadges{};
|
||||||
SeventvBadges *const seventvBadges{};
|
SeventvBadges *const seventvBadges{};
|
||||||
UserDataController *const userData{};
|
std::unique_ptr<UserDataController> userData;
|
||||||
ISoundController *const sound{};
|
ISoundController *const sound{};
|
||||||
TwitchLiveController *const twitchLiveController{};
|
TwitchLiveController *const twitchLiveController{};
|
||||||
std::unique_ptr<PubSub> twitchPubSub;
|
std::unique_ptr<PubSub> twitchPubSub;
|
||||||
|
|||||||
@@ -37,11 +37,6 @@ UserDataController::UserDataController(const Paths &paths)
|
|||||||
this->users = this->setting.getValue();
|
this->users = this->setting.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserDataController::save()
|
|
||||||
{
|
|
||||||
this->sm->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<UserData> UserDataController::getUser(const QString &userID) const
|
std::optional<UserData> UserDataController::getUser(const QString &userID) const
|
||||||
{
|
{
|
||||||
std::shared_lock lock(this->usersMutex);
|
std::shared_lock lock(this->usersMutex);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/Singleton.hpp"
|
|
||||||
#include "controllers/userdata/UserData.hpp"
|
#include "controllers/userdata/UserData.hpp"
|
||||||
#include "util/QStringHash.hpp"
|
#include "util/QStringHash.hpp"
|
||||||
#include "util/RapidjsonHelpers.hpp"
|
#include "util/RapidjsonHelpers.hpp"
|
||||||
@@ -30,7 +29,7 @@ public:
|
|||||||
const QString &colorString) = 0;
|
const QString &colorString) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UserDataController : public IUserDataController, public Singleton
|
class UserDataController : public IUserDataController
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit UserDataController(const Paths &paths);
|
explicit UserDataController(const Paths &paths);
|
||||||
@@ -43,9 +42,6 @@ public:
|
|||||||
void setUserColor(const QString &userID,
|
void setUserColor(const QString &userID,
|
||||||
const QString &colorString) override;
|
const QString &colorString) override;
|
||||||
|
|
||||||
protected:
|
|
||||||
void save() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void update(std::unordered_map<QString, UserData> &&newUsers);
|
void update(std::unordered_map<QString, UserData> &&newUsers);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user