mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
moved resources out of Application
This commit is contained in:
parent
da4714944d
commit
456065f508
13 changed files with 75 additions and 44 deletions
|
@ -1,5 +1,7 @@
|
|||
#include "Application.hpp"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/commands/CommandController.hpp"
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
|
@ -31,8 +33,6 @@
|
|||
#include "util/PostToThread.hpp"
|
||||
#include "widgets/Window.hpp"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
static std::atomic<bool> isAppInitialized{false};
|
||||
|
@ -44,9 +44,7 @@ Application *Application::instance = nullptr;
|
|||
// to each other
|
||||
|
||||
Application::Application(Settings &_settings, Paths &_paths)
|
||||
: resources(&this->emplace<Resources2>())
|
||||
|
||||
, themes(&this->emplace<Theme>())
|
||||
: themes(&this->emplace<Theme>())
|
||||
, fonts(&this->emplace<Fonts>())
|
||||
, emotes(&this->emplace<Emotes>())
|
||||
, windows(&this->emplace<WindowManager>())
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/Singleton.hpp"
|
||||
#include "singletons/NativeMessaging.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <memory>
|
||||
|
||||
#include "common/Singleton.hpp"
|
||||
#include "singletons/NativeMessaging.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class TwitchIrcServer;
|
||||
|
@ -28,7 +28,6 @@ class AccountManager;
|
|||
class Emotes;
|
||||
class Settings;
|
||||
class Fonts;
|
||||
class Resources2;
|
||||
class Toasts;
|
||||
class ChatterinoBadges;
|
||||
|
||||
|
@ -51,8 +50,6 @@ public:
|
|||
|
||||
friend void test();
|
||||
|
||||
Resources2 *const resources;
|
||||
|
||||
Theme *const themes{};
|
||||
Fonts *const fonts{};
|
||||
Emotes *const emotes{};
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "Application.hpp"
|
||||
#include "common/NetworkManager.hpp"
|
||||
#include "singletons/Paths.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
#include "singletons/Updates.hpp"
|
||||
#include "util/CombinePath.hpp"
|
||||
#include "widgets/dialogs/LastRunCrashDialog.hpp"
|
||||
|
@ -114,6 +115,8 @@ void runGui(QApplication &a, Paths &paths, Settings &settings)
|
|||
{
|
||||
initQt();
|
||||
|
||||
initResources();
|
||||
|
||||
auto thread = std::thread([dir = paths.miscDirectory] {
|
||||
{
|
||||
auto path = combinePath(dir, "Update.exe");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <QPixmap>
|
||||
|
||||
#include "common/Singleton.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
|
|
@ -65,17 +65,17 @@ ModerationAction::ModerationAction(const QString &action)
|
|||
// line1 = this->line1_;
|
||||
// line2 = this->line2_;
|
||||
// } else {
|
||||
// this->_moderationActions.emplace_back(app->resources->buttonTimeout,
|
||||
// this->_moderationActions.emplace_back(getResources().buttonTimeout,
|
||||
// str);
|
||||
// }
|
||||
}
|
||||
else if (action.startsWith("/ban "))
|
||||
{
|
||||
this->image_ = Image::fromPixmap(getApp()->resources->buttons.ban);
|
||||
this->image_ = Image::fromPixmap(getResources().buttons.ban);
|
||||
}
|
||||
else if (action.startsWith("/delete "))
|
||||
{
|
||||
this->image_ = Image::fromPixmap(getApp()->resources->buttons.trashCan);
|
||||
this->image_ = Image::fromPixmap(getResources().buttons.trashCan);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@ std::pair<MessagePtr, MessagePtr> makeAutomodMessage(
|
|||
|
||||
builder
|
||||
.emplace<ImageElement>(
|
||||
Image::fromPixmap(getApp()->resources->twitch.automod),
|
||||
Image::fromPixmap(getResources().twitch.automod),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
->setTooltip("AutoMod");
|
||||
builder.emplace<TextElement>("AutoMod:", MessageElementFlag::BoldUsername,
|
||||
|
|
|
@ -1174,21 +1174,21 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
|||
else if (badge == "staff/1")
|
||||
{
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.staff),
|
||||
Image::fromPixmap(getResources().twitch.staff),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Staff");
|
||||
}
|
||||
else if (badge == "admin/1")
|
||||
{
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.admin),
|
||||
Image::fromPixmap(getResources().twitch.admin),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Admin");
|
||||
}
|
||||
else if (badge == "global_mod/1")
|
||||
{
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.globalmod),
|
||||
Image::fromPixmap(getResources().twitch.globalmod),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Global Moderator");
|
||||
}
|
||||
|
@ -1203,35 +1203,35 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
|||
continue;
|
||||
}
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.moderator),
|
||||
Image::fromPixmap(getResources().twitch.moderator),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
->setTooltip("Twitch Channel Moderator");
|
||||
}
|
||||
else if (badge == "vip/1")
|
||||
{
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.vip),
|
||||
Image::fromPixmap(getResources().twitch.vip),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
->setTooltip("VIP");
|
||||
}
|
||||
else if (badge == "broadcaster/1")
|
||||
{
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.broadcaster),
|
||||
Image::fromPixmap(getResources().twitch.broadcaster),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
->setTooltip("Twitch Broadcaster");
|
||||
}
|
||||
else if (badge == "turbo/1")
|
||||
{
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.turbo),
|
||||
Image::fromPixmap(getResources().twitch.turbo),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip("Twitch Turbo Subscriber");
|
||||
}
|
||||
else if (badge == "premium/1")
|
||||
{
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.prime),
|
||||
Image::fromPixmap(getResources().twitch.prime),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip("Twitch Prime Subscriber");
|
||||
}
|
||||
|
@ -1243,7 +1243,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
|||
case 1:
|
||||
{
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.verified,
|
||||
Image::fromPixmap(getResources().twitch.verified,
|
||||
0.25),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip("Twitch Verified");
|
||||
|
@ -1271,7 +1271,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
|||
|
||||
// use default subscriber badge if custom one not found
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.subscriber, 0.25),
|
||||
Image::fromPixmap(getResources().twitch.subscriber, 0.25),
|
||||
MessageElementFlag::BadgeSubscription)
|
||||
->setTooltip("Twitch Subscriber");
|
||||
}
|
||||
|
|
|
@ -1 +1,24 @@
|
|||
#include "singletons/Resources.hpp"
|
||||
|
||||
#include "debug/AssertInGuiThread.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
static Resources2 *resources = nullptr;
|
||||
}
|
||||
|
||||
Resources2 &getResources()
|
||||
{
|
||||
assert(resources);
|
||||
|
||||
return *resources;
|
||||
}
|
||||
|
||||
void initResources()
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
resources = new Resources2;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "autogenerated/ResourcesAutogen.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
/// This class in thread safe but needs to be initialized from the gui thread
|
||||
/// first.
|
||||
Resources2 &getResources();
|
||||
void initResources();
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace {
|
|||
{
|
||||
auto label = box.emplace<Label>().assign(assign);
|
||||
auto button = box.emplace<Button>();
|
||||
button->setPixmap(getApp()->resources->buttons.copyDark);
|
||||
button->setPixmap(getResources().buttons.copyDark);
|
||||
button->setScaleIndependantSize(18, 18);
|
||||
button->setDim(Button::Dim::Lots);
|
||||
QObject::connect(button.getElement(), &Button::leftClicked,
|
||||
|
@ -111,10 +111,10 @@ UserInfoPopup::UserInfoPopup()
|
|||
usercard->getLabel().setText("Usercard");
|
||||
|
||||
auto mod = user.emplace<Button>(this);
|
||||
mod->setPixmap(app->resources->buttons.mod);
|
||||
mod->setPixmap(getResources().buttons.mod);
|
||||
mod->setScaleIndependantSize(30, 30);
|
||||
auto unmod = user.emplace<Button>(this);
|
||||
unmod->setPixmap(app->resources->buttons.unmod);
|
||||
unmod->setPixmap(getResources().buttons.unmod);
|
||||
unmod->setScaleIndependantSize(30, 30);
|
||||
|
||||
user->addStretch(1);
|
||||
|
@ -575,7 +575,7 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
|
|||
}
|
||||
};
|
||||
|
||||
addButton(Unban, "unban", getApp()->resources->buttons.unban);
|
||||
addButton(Unban, "unban", getResources().buttons.unban);
|
||||
|
||||
addTimeouts("sec", {{"1", 1}});
|
||||
addTimeouts("min", {
|
||||
|
@ -596,7 +596,7 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
|
|||
{"2", 2 * 60 * 60 * 24 * 7},
|
||||
});
|
||||
|
||||
addButton(Ban, "ban", getApp()->resources->buttons.ban);
|
||||
addButton(Ban, "ban", getResources().buttons.ban);
|
||||
}
|
||||
|
||||
void UserInfoPopup::TimeoutWidget::paintEvent(QPaintEvent *)
|
||||
|
|
|
@ -220,7 +220,7 @@ void SplitHeader::initializeLayout()
|
|||
}),
|
||||
// add split
|
||||
this->addButton_ = makeWidget<Button>([&](auto w) {
|
||||
w->setPixmap(getApp()->resources->buttons.addSplitDark);
|
||||
w->setPixmap(getResources().buttons.addSplitDark);
|
||||
w->setEnableMargin(false);
|
||||
|
||||
QObject::connect(w, &Button::leftClicked, this,
|
||||
|
@ -564,8 +564,8 @@ void SplitHeader::updateModerationModeIcon()
|
|||
!getApp()->moderationActions->items.empty();
|
||||
|
||||
this->moderationButton_->setPixmap(
|
||||
moderationMode ? getApp()->resources->buttons.modModeEnabled
|
||||
: getApp()->resources->buttons.modModeDisabled);
|
||||
moderationMode ? getResources().buttons.modModeEnabled
|
||||
: getResources().buttons.modModeDisabled);
|
||||
|
||||
auto channel = this->split_->getChannel();
|
||||
auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
||||
|
@ -713,14 +713,14 @@ void SplitHeader::themeChangedEvent()
|
|||
// --
|
||||
if (this->theme->isLightTheme())
|
||||
{
|
||||
this->dropdownButton_->setPixmap(getApp()->resources->buttons.menuDark);
|
||||
this->addButton_->setPixmap(getApp()->resources->buttons.addSplit);
|
||||
this->dropdownButton_->setPixmap(getResources().buttons.menuDark);
|
||||
this->addButton_->setPixmap(getResources().buttons.addSplit);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->dropdownButton_->setPixmap(
|
||||
getApp()->resources->buttons.menuLight);
|
||||
this->addButton_->setPixmap(getApp()->resources->buttons.addSplitDark);
|
||||
getResources().buttons.menuLight);
|
||||
this->addButton_->setPixmap(getResources().buttons.addSplitDark);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,15 +30,15 @@ SplitOverlay::SplitOverlay(Split *parent)
|
|||
layout->setColumnStretch(1, 1);
|
||||
layout->setColumnStretch(3, 1);
|
||||
|
||||
auto *move = new QPushButton(getApp()->resources->split.move, QString());
|
||||
auto *move = new QPushButton(getResources().split.move, QString());
|
||||
auto *left = this->left_ =
|
||||
new QPushButton(getApp()->resources->split.left, QString());
|
||||
new QPushButton(getResources().split.left, QString());
|
||||
auto *right = this->right_ =
|
||||
new QPushButton(getApp()->resources->split.right, QString());
|
||||
new QPushButton(getResources().split.right, QString());
|
||||
auto *up = this->up_ =
|
||||
new QPushButton(getApp()->resources->split.up, QString());
|
||||
new QPushButton(getResources().split.up, QString());
|
||||
auto *down = this->down_ =
|
||||
new QPushButton(getApp()->resources->split.down, QString());
|
||||
new QPushButton(getResources().split.down, QString());
|
||||
|
||||
move->setGraphicsEffect(new QGraphicsOpacityEffect(this));
|
||||
left->setGraphicsEffect(new QGraphicsOpacityEffect(this));
|
||||
|
|
Loading…
Reference in a new issue