Skip to content

Commit

Permalink
Merge branch 'master' into chore/unsingletonize-sound
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada authored Jun 16, 2024
2 parents 17c70de + 85d6ff1 commit 8550dc6
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
- Dev: Refactor `TwitchIrcServer`, making it abstracted. (#5421, #5435)
- Dev: Reduced the amount of scale events. (#5404, #5406)
- Dev: Removed unused timegate settings. (#5361)
- Dev: Unsingletonize `Resources2`. (#5460)
- Dev: All Lua globals now show in the `c2` global in the LuaLS metadata. (#5385)
- 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: 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

Expand Down
5 changes: 2 additions & 3 deletions cmake/resources/ResourcesAutogen.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include <QPixmap>
#include "common/Singleton.hpp"

namespace chatterino {

class Resources2 : public Singleton
class Resources2
{
public:
Resources2();

@RES_HEADER_CONTENT@
};
} // namespace chatterino
} // namespace chatterino
5 changes: 3 additions & 2 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Application::Application(Settings &_settings, const Paths &paths,
, twitch(new TwitchIrcServer)
, ffzBadges(&this->emplace<FfzBadges>())
, seventvBadges(&this->emplace<SeventvBadges>())
, userData(&this->emplace(new UserDataController(paths)))
, userData(new UserDataController(paths))
, sound(makeSoundController(_settings))
, twitchLiveController(&this->emplace<TwitchLiveController>())
, twitchPubSub(new PubSub(TWITCH_PUBSUB_URL))
Expand Down Expand Up @@ -174,6 +174,7 @@ void Application::fakeDtor()
// this->twitch.reset();
this->fonts.reset();
this->sound.reset();
this->userData.reset();
}

void Application::initialize(Settings &settings, const Paths &paths)
Expand Down Expand Up @@ -428,7 +429,7 @@ IUserDataController *Application::getUserData()
{
assertInGuiThread();

return this->userData;
return this->userData.get();
}

ISoundController *Application::getSound()
Expand Down
2 changes: 1 addition & 1 deletion src/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class Application : public IApplication
std::unique_ptr<TwitchIrcServer> twitch;
FfzBadges *const ffzBadges{};
SeventvBadges *const seventvBadges{};
UserDataController *const userData{};
std::unique_ptr<UserDataController> userData;
std::unique_ptr<ISoundController> sound;
TwitchLiveController *const twitchLiveController{};
std::unique_ptr<PubSub> twitchPubSub;
Expand Down
5 changes: 0 additions & 5 deletions src/controllers/userdata/UserDataController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ UserDataController::UserDataController(const Paths &paths)
this->users = this->setting.getValue();
}

void UserDataController::save()
{
this->sm->save();
}

std::optional<UserData> UserDataController::getUser(const QString &userID) const
{
std::shared_lock lock(this->usersMutex);
Expand Down
6 changes: 1 addition & 5 deletions src/controllers/userdata/UserDataController.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "common/Singleton.hpp"
#include "controllers/userdata/UserData.hpp"
#include "util/QStringHash.hpp"
#include "util/RapidjsonHelpers.hpp"
Expand Down Expand Up @@ -30,7 +29,7 @@ class IUserDataController
const QString &colorString) = 0;
};

class UserDataController : public IUserDataController, public Singleton
class UserDataController : public IUserDataController
{
public:
explicit UserDataController(const Paths &paths);
Expand All @@ -43,9 +42,6 @@ class UserDataController : public IUserDataController, public Singleton
void setUserColor(const QString &userID,
const QString &colorString) override;

protected:
void save() override;

private:
void update(std::unordered_map<QString, UserData> &&newUsers);

Expand Down
11 changes: 8 additions & 3 deletions src/singletons/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

#include "debug/AssertInGuiThread.hpp"

namespace chatterino {
namespace {
static Resources2 *resources = nullptr;
}

using namespace chatterino;

static Resources2 *resources = nullptr;

} // namespace

namespace chatterino {

Resources2 &getResources()
{
Expand Down
9 changes: 1 addition & 8 deletions tests/src/TwitchPubSubClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,7 @@ TEST(TwitchPubSubClient, DisconnectedAfter1s)
ASSERT_EQ(pubSub.diag.messagesReceived, 2); // Listen RESPONSE & Pong
ASSERT_EQ(pubSub.diag.listenResponses, 1);

std::this_thread::sleep_for(350ms);

ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
ASSERT_EQ(pubSub.diag.messagesReceived, 2);

std::this_thread::sleep_for(600ms);
std::this_thread::sleep_for(950ms);

ASSERT_EQ(pubSub.diag.connectionsOpened, 2);
ASSERT_EQ(pubSub.diag.connectionsClosed, 1);
Expand Down

0 comments on commit 8550dc6

Please sign in to comment.