From d2f4a1b32cc7d074d8e37c35a9e422fcdfae5f62 Mon Sep 17 00:00:00 2001 From: ZavaruKitsu Date: Thu, 21 Sep 2023 23:02:53 +0300 Subject: [PATCH] feat: refactor --- Telegram/CMakeLists.txt | 2 + Telegram/SourceFiles/ayu/ayu_infra.cpp | 39 +++++++++++++++++++ Telegram/SourceFiles/ayu/ayu_infra.h | 14 +++++++ Telegram/SourceFiles/ayu/ayu_lang.cpp | 1 - Telegram/SourceFiles/ayu/ui/ayu_lottie.cpp | 2 +- Telegram/SourceFiles/ayu/ui/ayu_lottie.h | 5 ++- Telegram/SourceFiles/storage/localstorage.cpp | 13 ++----- Telegram/lib_ui | 2 +- 8 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 Telegram/SourceFiles/ayu/ayu_infra.cpp create mode 100644 Telegram/SourceFiles/ayu/ayu_infra.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 802847e2bb..9bdfbc9b60 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -101,6 +101,8 @@ PRIVATE ayu/ayu_settings.h ayu/ayu_lang.cpp ayu/ayu_lang.h + ayu/ayu_infra.cpp + ayu/ayu_infra.h ayu/ayu_constants.h ayu/utils/ayu_mapper.cpp ayu/utils/ayu_mapper.h diff --git a/Telegram/SourceFiles/ayu/ayu_infra.cpp b/Telegram/SourceFiles/ayu/ayu_infra.cpp new file mode 100644 index 0000000000..951425141b --- /dev/null +++ b/Telegram/SourceFiles/ayu/ayu_infra.cpp @@ -0,0 +1,39 @@ +// This is the source code of AyuGram for Desktop. +// +// We do not and cannot prevent the use of our code, +// but be respectful and credit the original author. +// +// Copyright @Radolyn, 2023 +#include "ayu_infra.h" + +#include "ayu_lang.h" +#include "ayu/ayu_lottie.h" +#include "ayu/ui/ayu_lottie.h" +#include "lang/lang_instance.h" + +namespace AyuInfra +{ + +void initLang() +{ + QString langPackBaseId = Lang::GetInstance().baseId(); + QString langPackId = Lang::GetInstance().id(); + if (langPackId.isEmpty()) { + LOG(("Lang ID not found! Re-use old language pack...")); + return; + } + CustomLangPack::initInstance(); + CustomLangPack::currentInstance()->fetchCustomLangPack(langPackId, langPackBaseId); +} + +void initLottie() { + AyuUi::setLottieImpl(std::make_shared()); +} + +void init() +{ + initLang(); + initLottie(); +} + +} \ No newline at end of file diff --git a/Telegram/SourceFiles/ayu/ayu_infra.h b/Telegram/SourceFiles/ayu/ayu_infra.h new file mode 100644 index 0000000000..b4cf427664 --- /dev/null +++ b/Telegram/SourceFiles/ayu/ayu_infra.h @@ -0,0 +1,14 @@ +// This is the source code of AyuGram for Desktop. +// +// We do not and cannot prevent the use of our code, +// but be respectful and credit the original author. +// +// Copyright @Radolyn, 2023 +#pragma once + +namespace AyuInfra +{ + +void init(); + +} diff --git a/Telegram/SourceFiles/ayu/ayu_lang.cpp b/Telegram/SourceFiles/ayu/ayu_lang.cpp index 29af50cbbc..c6b5450a06 100644 --- a/Telegram/SourceFiles/ayu/ayu_lang.cpp +++ b/Telegram/SourceFiles/ayu/ayu_lang.cpp @@ -4,7 +4,6 @@ // but be respectful and credit the original author. // // Copyright @Radolyn, 2023 - #include "ayu_lang.h" #include "qjsondocument.h" diff --git a/Telegram/SourceFiles/ayu/ui/ayu_lottie.cpp b/Telegram/SourceFiles/ayu/ui/ayu_lottie.cpp index 7b68dd3ffb..0b57f59c08 100644 --- a/Telegram/SourceFiles/ayu/ui/ayu_lottie.cpp +++ b/Telegram/SourceFiles/ayu/ui/ayu_lottie.cpp @@ -10,7 +10,7 @@ namespace AyuUi { -std::unique_ptr getLottie(const QString &text) +std::unique_ptr AyuLottieImpl::getLottie(const QString &text) { // todo: some kind of mapping // Lottie::MakeIcon({.json = QString(), .sizeOverride = {24, 24}}); diff --git a/Telegram/SourceFiles/ayu/ui/ayu_lottie.h b/Telegram/SourceFiles/ayu/ui/ayu_lottie.h index 19350f6688..1481084cdf 100644 --- a/Telegram/SourceFiles/ayu/ui/ayu_lottie.h +++ b/Telegram/SourceFiles/ayu/ui/ayu_lottie.h @@ -7,10 +7,13 @@ #pragma once #include "lottie/lottie_icon.h" +#include "ayu/ayu_lottie.h" namespace AyuUi { -std::unique_ptr getLottie(const QString &text); +class AyuLottieImpl : public AyuLottie { + std::unique_ptr getLottie(const QString &text) override; +}; } diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 55cdc8e706..75dcc5acb1 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -32,8 +32,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include +// AyuGram includes +#include "ayu/ayu_infra.h" #include "ayu/ayu_settings.h" -#include "ayu/ayu_lang.h" #ifndef Q_OS_WIN #include @@ -425,6 +426,8 @@ void start() { } readLangPack(); + + AyuInfra::init(); } void writeSettings() { @@ -1133,14 +1136,6 @@ void readLangPack() { if (langpack.stream.status() == QDataStream::Ok) { Lang::GetInstance().fillFromSerialized(data, langpack.version); } - QString langPackBaseId = Lang::GetInstance().baseId(); - QString langPackId = Lang::GetInstance().id(); - if (langPackId.isEmpty()) { - LOG(("Lang ID not found! Re-use old language pack...")); - return; - } - CustomLangPack::initInstance(); - CustomLangPack::currentInstance()->fetchCustomLangPack(langPackId, langPackBaseId); } void writeLangPack() { diff --git a/Telegram/lib_ui b/Telegram/lib_ui index e69faa9d6b..ca3c91fb0b 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit e69faa9d6bac69fb44e440ca2cffd86f7ed6b26a +Subproject commit ca3c91fb0be7db2d61defe5c6b0670e0faa93d03