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