From 3642db51d78f4acd42262b8d2d5c8191e4f43a95 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Mon, 3 Feb 2020 14:28:59 +0300 Subject: [PATCH] Basic changelogs --- Telegram/Resources/langs/lang.strings | 2 +- Telegram/Resources/langs/rewrites/ru.json | 2 +- Telegram/SourceFiles/core/changelogs.cpp | 44 ++++++++++++++++--- Telegram/SourceFiles/core/changelogs.h | 4 +- Telegram/SourceFiles/core/kotato_settings.cpp | 2 + Telegram/SourceFiles/settings.cpp | 2 + Telegram/SourceFiles/settings.h | 2 + Telegram/SourceFiles/storage/localstorage.cpp | 34 ++++++++++++++ Telegram/SourceFiles/storage/localstorage.h | 5 +++ 9 files changed, 88 insertions(+), 9 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index b9cee9486..10b277af8 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2280,6 +2280,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_about_text1_tdesktop" = "Telegram Desktop"; "ktg_about_text3" = "Visit {channel_link} or {faq_link} for more info."; "ktg_about_text3_channel" = "Kotatogram channel"; +"ktg_new_version" = "Kotatogram Desktop has been updated to {version} (TD {td_version})\n\nFull version history is available here:\n{link}"; // Replaces "ktg_open_from_tray" = "Open Kotatogram"; @@ -2295,7 +2296,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_passcode_about" = "When a local passcode is set, a lock icon appears at the top of your chats list. Click it to lock the app.\n\nNote: if you forget your local passcode, you'll need to relogin in Kotatogram Desktop."; "ktg_message_unsupported" = "This message is not supported by your version of Kotatogram Desktop. Please update to the latest version in Settings, or install it from {link}"; "ktg_bot_share_location_unavailable" = "Sorry, location sharing is currently unavailable in Kotatogram Desktop."; -"ktg_new_version_wrap" = "Kotatogram Desktop was rebased on Telegram Desktop {version}\n\n{changes}\n\nFull version history is available here:\n{link}"; "ktg_theme_editor_need_unlock" = "You need to unlock Kotatogram to save your theme."; "ktg_payments_not_supported" = "Sorry, Kotatogram Desktop doesn't support payments yet. Please use one of our mobile apps to do this."; "ktg_no_mic_permission" = "Kotatogram needs access to your microphone so that you can make calls and record voice messages."; diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json index 40384b1ee..a224497d1 100644 --- a/Telegram/Resources/langs/rewrites/ru.json +++ b/Telegram/Resources/langs/rewrites/ru.json @@ -9,6 +9,7 @@ "ktg_about_text1": "Экспериментальный неофициальный форк {tdesktop_link}.", "ktg_about_text3": "Посетите {channel_link} или {faq_link} (англ.), чтобы узнать больше.", "ktg_about_text3_channel": "канал Kotatogram", + "ktg_new_version": "Kotatogram Desktop обновлён до версии {version} (TD {td_version})\n\nПолную историю изменений можно прочитать здесь:\n{link}", "ktg_open_from_tray": "Открыть Kotatogram", "ktg_quit_from_tray": "Закрыть Kotatogram", "ktg_tray_icon_text": "Kotatogram продолжает работать,\nВы можете изменить это в настройках.\nЕсли значок исчезнет из области уведомлений,\nего можно перенести из скрытых значков.", @@ -22,7 +23,6 @@ "ktg_passcode_about": "Когда код-пароль включен, в списке чатов появляется значок замка для блокировки и разблокировки приложения.\n\nВажно: если Вы забудете код-пароль, нужно будет выйти и заново авторизоваться в Kotatogram Desktop.", "ktg_message_unsupported": "Это сообщение не поддерживается в вашей версии Kotatogram. Пожалуйста, обновитесь до последней версии через Настройки или установите её по ссылке {link}", "ktg_bot_share_location_unavailable": "В Kotatogram Desktop пока нельзя делиться геопозицией.", - "ktg_new_version_wrap": "Kotatogram Desktop обновил исходники Telegram Desktop до {version}\n\n{changes}\n\nВся история изменений доступна здесь:\n{link}", "ktg_theme_editor_need_unlock": "Чтобы сохранить тему, необходимо разблокировать приложение.", "ktg_payments_not_supported": "К сожалению, Kotatogram Desktop ещё не поддерживает платежи. Пожалуйста, используйте для этого мобильные приложения.", "ktg_no_mic_permission": "Чтобы Вы могли пользоваться звонками и записывать голосовые сообщения, Kotatogram требуется доступ к микрофону.", diff --git a/Telegram/SourceFiles/core/changelogs.cpp b/Telegram/SourceFiles/core/changelogs.cpp index 688a722e8..1dcbf5413 100644 --- a/Telegram/SourceFiles/core/changelogs.cpp +++ b/Telegram/SourceFiles/core/changelogs.cpp @@ -64,25 +64,57 @@ QString FormatVersionPrecise(int version) { } // namespace -Changelogs::Changelogs(not_null session, int oldVersion) +Changelogs::Changelogs(not_null session, int oldVersion, int oldKotatoVersion) : _session(session) -, _oldVersion(oldVersion) { +, _oldVersion(oldVersion) +, _oldKotatoVersion(oldKotatoVersion) { + _session->data().chatsListChanges( ) | rpl::filter([](Data::Folder *folder) { return !folder; }) | rpl::start_with_next([=] { - requestCloudLogs(); + addKotatoLogs(); }, _chatsSubscription); } std::unique_ptr Changelogs::Create( not_null session) { const auto oldVersion = Local::oldMapVersion(); - return (oldVersion > 0 && oldVersion < AppVersion) - ? std::make_unique(session, oldVersion) + const auto oldKotatoVersion = Local::oldKotatoVersion(); + return (!cKotatoFirstRun() && oldKotatoVersion < AppKotatoVersion) + ? std::make_unique(session, oldVersion, oldKotatoVersion) : nullptr; } +void Changelogs::addKotatoLogs() { + _chatsSubscription.destroy(); + + auto baseLang = Lang::Current().baseId(); + auto currentLang = Lang::Current().id(); + QString channelLink; + + for (const auto language : { "ru", "uk", "be" }) { + if (baseLang.startsWith(QLatin1String(language)) || currentLang == QString(language)) { + channelLink = "https://t.me/kotatogram_ru"; + break; + } + } + + if (channelLink.isEmpty()) { + channelLink = "https://t.me/kotatogram"; + } + + const auto text = tr::ktg_new_version( + tr::now, + lt_version, + QString::fromLatin1(AppKotatoVersionStr), + lt_td_version, + QString::fromLatin1(AppVersionStr), + lt_link, + channelLink); + addLocalLog(text.trimmed()); +} + void Changelogs::requestCloudLogs() { _chatsSubscription.destroy(); @@ -121,7 +153,7 @@ void Changelogs::addLocalLogs() { addBetaLogs(); } if (!_addedSomeLocal) { - const auto text = tr::ktg_new_version_wrap( + const auto text = tr::lng_new_version_wrap( tr::now, lt_version, QString::fromLatin1(AppVersionStr), diff --git a/Telegram/SourceFiles/core/changelogs.h b/Telegram/SourceFiles/core/changelogs.h index 598f4eb5f..ab3a4c5fe 100644 --- a/Telegram/SourceFiles/core/changelogs.h +++ b/Telegram/SourceFiles/core/changelogs.h @@ -17,12 +17,13 @@ namespace Core { class Changelogs : public base::has_weak_ptr, private base::Subscriber { public: - Changelogs(not_null session, int oldVersion); + Changelogs(not_null session, int oldVersion, int oldKotatoVersion); static std::unique_ptr Create( not_null session); private: + void addKotatoLogs(); void requestCloudLogs(); void addLocalLogs(); void addLocalLog(const QString &text); @@ -31,6 +32,7 @@ private: const not_null _session; const int _oldVersion = 0; + const int _oldKotatoVersion = 0; rpl::lifetime _chatsSubscription; bool _addedSomeLocal = false; diff --git a/Telegram/SourceFiles/core/kotato_settings.cpp b/Telegram/SourceFiles/core/kotato_settings.cpp index ef185e5e3..ab65f0c96 100644 --- a/Telegram/SourceFiles/core/kotato_settings.cpp +++ b/Telegram/SourceFiles/core/kotato_settings.cpp @@ -97,8 +97,10 @@ void Manager::write(bool force) { bool Manager::readCustomFile() { QFile file(CustomFilePath()); if (!file.exists()) { + cSetKotatoFirstRun(true); return false; } + cSetKotatoFirstRun(false); if (!file.open(QIODevice::ReadOnly)) { return true; } diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index 3848db5a2..6982bdf05 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -207,6 +207,8 @@ rpl::producer<> UpdatedRecentEmoji() { return UpdatesRecentEmoji.events(); } +bool gKotatoFirstRun = true; + QString gMainFont, gSemiboldFont, gMonospaceFont; bool gSemiboldFontIsBold = false; diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index e5b2bda4e..cf5f81f2e 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -179,6 +179,8 @@ inline void ValidateScale() { style::SetScale(cEvalScale(cConfigScale())); } +DeclareSetting(bool, KotatoFirstRun); + DeclareSetting(QString, MainFont); DeclareSetting(QString, SemiboldFont); DeclareSetting(bool, SemiboldFontIsBold); diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 89c280cc7..65f8556cc 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -702,6 +702,7 @@ FileKey _languagesKey = 0; bool _mapChanged = false; int32 _oldMapVersion = 0, _oldSettingsVersion = 0; +int32 _oldKotatoVersion = 0; enum class WriteMapWhen { Now, @@ -2578,6 +2579,9 @@ void readLangPack(); void start() { Expects(!_manager); + _oldKotatoVersion = readKotatoVersion(); + writeKotatoVersion(AppKotatoVersion); + _manager = new internal::Manager(); _localLoader = new TaskQueue(kFileLoaderQueueStopTimeout); @@ -2917,6 +2921,10 @@ int32 oldSettingsVersion() { return _oldSettingsVersion; } +int32 oldKotatoVersion() { + return _oldKotatoVersion; +} + void writeDrafts(const PeerId &peer, const MessageDraft &localDraft, const MessageDraft &editDraft) { if (!_working()) return; @@ -4967,6 +4975,32 @@ bool decrypt(const void *src, void *dst, uint32 len, const void *key128) { return true; } +qint32 readKotatoVersion() { + qint32 version = 0; + QFile f(cWorkingDir() + qsl("tdata/ktg_version")); + if (f.open(QIODevice::ReadOnly)) { + QDataStream stream(&f); + stream.setVersion(QDataStream::Qt_5_1); + while (!stream.atEnd()) { + stream >> version; + break; + } + f.close(); + } + + return version; +} + +void writeKotatoVersion(int version) { + qint32 writtenVersion = version; + QFile f(cWorkingDir() + qsl("tdata/ktg_version")); + if (f.open(QIODevice::WriteOnly)) { + QDataStream stream(&f); + stream << writtenVersion; + f.close(); + } +} + struct ClearManagerData { QThread *thread; QMutex mutex; diff --git a/Telegram/SourceFiles/storage/localstorage.h b/Telegram/SourceFiles/storage/localstorage.h index d75ce8a75..f94c5e212 100644 --- a/Telegram/SourceFiles/storage/localstorage.h +++ b/Telegram/SourceFiles/storage/localstorage.h @@ -98,6 +98,8 @@ int32 oldMapVersion(); int32 oldSettingsVersion(); +int32 oldKotatoVersion(); + struct MessageDraft { MessageDraft(MsgId msgId = 0, TextWithTags textWithTags = TextWithTags(), bool previewCancelled = false) : msgId(msgId) @@ -184,6 +186,9 @@ bool isBotTrusted(UserData *bot); bool encrypt(const void *src, void *dst, uint32 len, const void *key128); bool decrypt(const void *src, void *dst, uint32 len, const void *key128); +qint32 readKotatoVersion(); +void writeKotatoVersion(int version); + namespace internal { class Manager : public QObject {