mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Create only one EmojiImageLoader to fix a crash.
This commit is contained in:
@@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "core/launcher.h"
|
||||
#include "core/ui_integration.h"
|
||||
#include "chat_helpers/emoji_keywords.h"
|
||||
#include "chat_helpers/stickers_emoji_image_loader.h"
|
||||
#include "base/platform/base_platform_info.h"
|
||||
#include "platform/platform_specific.h"
|
||||
#include "mainwindow.h"
|
||||
@@ -80,6 +81,7 @@ namespace {
|
||||
|
||||
constexpr auto kQuitPreventTimeoutMs = crl::time(1500);
|
||||
constexpr auto kAutoLockTimeoutLateMs = crl::time(3000);
|
||||
constexpr auto kClearEmojiImageSourceTimeout = 10 * crl::time(1000);
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -96,6 +98,7 @@ Application::Application(not_null<Launcher*> launcher)
|
||||
, _private(std::make_unique<Private>())
|
||||
, _databases(std::make_unique<Storage::Databases>())
|
||||
, _animationsManager(std::make_unique<Ui::Animations::Manager>())
|
||||
, _clearEmojiImageLoaderTimer([=] { clearEmojiSourceImages(); })
|
||||
, _fallbackProductionConfig(
|
||||
std::make_unique<MTP::Config>(MTP::Environment::Production))
|
||||
, _domain(std::make_unique<Main::Domain>(cDataFile()))
|
||||
@@ -207,6 +210,7 @@ void Application::run() {
|
||||
style::startManager(cScale());
|
||||
Ui::InitTextOptions();
|
||||
Ui::Emoji::Init();
|
||||
startEmojiImageLoader();
|
||||
Media::Player::start(_audio.get());
|
||||
|
||||
style::ShortAnimationPlaying(
|
||||
@@ -275,6 +279,24 @@ void Application::run() {
|
||||
}
|
||||
}
|
||||
|
||||
auto Application::prepareEmojiSourceImages()
|
||||
-> std::shared_ptr<Ui::Emoji::UniversalImages> {
|
||||
const auto &images = Ui::Emoji::SourceImages();
|
||||
if (_settings.largeEmoji()) {
|
||||
return images;
|
||||
}
|
||||
Ui::Emoji::ClearSourceImages(images);
|
||||
return std::make_shared<Ui::Emoji::UniversalImages>(images->id());
|
||||
}
|
||||
|
||||
void Application::clearEmojiSourceImages() {
|
||||
_emojiImageLoader.with([](Stickers::EmojiImageLoader &loader) {
|
||||
crl::on_main([images = loader.releaseImages()]{
|
||||
Ui::Emoji::ClearSourceImages(images);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
bool Application::hideMediaView() {
|
||||
if (_mediaView && !_mediaView->isHidden()) {
|
||||
_mediaView->hide();
|
||||
@@ -466,6 +488,34 @@ void Application::startLocalStorage() {
|
||||
_saveSettingsTimer.setCallback([=] { saveSettings(); });
|
||||
}
|
||||
|
||||
void Application::startEmojiImageLoader() {
|
||||
_emojiImageLoader.with([
|
||||
source = prepareEmojiSourceImages(),
|
||||
large = _settings.largeEmoji()
|
||||
](Stickers::EmojiImageLoader &loader) mutable {
|
||||
loader.init(std::move(source), large);
|
||||
});
|
||||
|
||||
_settings.largeEmojiChanges(
|
||||
) | rpl::start_with_next([=](bool large) {
|
||||
if (large) {
|
||||
_clearEmojiImageLoaderTimer.cancel();
|
||||
} else {
|
||||
_clearEmojiImageLoaderTimer.callOnce(
|
||||
kClearEmojiImageSourceTimeout);
|
||||
}
|
||||
}, _lifetime);
|
||||
|
||||
Ui::Emoji::Updated(
|
||||
) | rpl::start_with_next([=] {
|
||||
_emojiImageLoader.with([
|
||||
source = prepareEmojiSourceImages()
|
||||
](Stickers::EmojiImageLoader &loader) mutable {
|
||||
loader.switchTo(std::move(source));
|
||||
});
|
||||
}, _lifetime);
|
||||
}
|
||||
|
||||
void Application::logout(Main::Account *account) {
|
||||
if (account) {
|
||||
account->logOut();
|
||||
|
@@ -51,6 +51,9 @@ namespace Ui {
|
||||
namespace Animations {
|
||||
class Manager;
|
||||
} // namespace Animations
|
||||
namespace Emoji {
|
||||
class UniversalImages;
|
||||
} // namespace Emoji
|
||||
class BoxContent;
|
||||
} // namespace Ui
|
||||
|
||||
@@ -81,6 +84,10 @@ namespace Data {
|
||||
struct CloudTheme;
|
||||
} // namespace Data
|
||||
|
||||
namespace Stickers {
|
||||
class EmojiImageLoader;
|
||||
} // namespace Stickers
|
||||
|
||||
namespace Core {
|
||||
|
||||
class Launcher;
|
||||
@@ -195,6 +202,10 @@ public:
|
||||
[[nodiscard]] ChatHelpers::EmojiKeywords &emojiKeywords() {
|
||||
return *_emojiKeywords;
|
||||
}
|
||||
[[nodiscard]] auto emojiImageLoader() const
|
||||
-> const crl::object_on_queue<Stickers::EmojiImageLoader> & {
|
||||
return _emojiImageLoader;
|
||||
}
|
||||
|
||||
// Internal links.
|
||||
void checkStartUrl();
|
||||
@@ -256,8 +267,12 @@ private:
|
||||
friend bool IsAppLaunched();
|
||||
friend Application &App();
|
||||
|
||||
void clearEmojiSourceImages();
|
||||
[[nodiscard]] auto prepareEmojiSourceImages()
|
||||
-> std::shared_ptr<Ui::Emoji::UniversalImages>;
|
||||
void startLocalStorage();
|
||||
void startShortcuts();
|
||||
void startEmojiImageLoader();
|
||||
|
||||
void stateChanged(Qt::ApplicationState state);
|
||||
|
||||
@@ -293,6 +308,8 @@ private:
|
||||
|
||||
const std::unique_ptr<Storage::Databases> _databases;
|
||||
const std::unique_ptr<Ui::Animations::Manager> _animationsManager;
|
||||
crl::object_on_queue<Stickers::EmojiImageLoader> _emojiImageLoader;
|
||||
base::Timer _clearEmojiImageLoaderTimer;
|
||||
mutable std::unique_ptr<MTP::Config> _fallbackProductionConfig;
|
||||
const std::unique_ptr<Main::Domain> _domain;
|
||||
std::unique_ptr<Window::Controller> _window;
|
||||
|
Reference in New Issue
Block a user