2017-02-23 10:59:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-02-23 10:59:19 +00:00
|
|
|
*/
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_photo.h"
|
|
|
|
#include "data/data_document.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2017-04-29 20:06:32 +00:00
|
|
|
#include "base/timer.h"
|
2019-02-19 06:57:53 +00:00
|
|
|
#include "base/concurrent_timer.h"
|
2020-12-03 16:34:18 +00:00
|
|
|
#include "base/qt_signal_producer.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2018-04-18 15:42:02 +00:00
|
|
|
#include "core/update_checker.h"
|
2018-11-16 12:15:14 +00:00
|
|
|
#include "core/shortcuts.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/sandbox.h"
|
2018-11-26 11:55:02 +00:00
|
|
|
#include "core/local_url_handlers.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/launcher.h"
|
2019-09-19 09:34:37 +00:00
|
|
|
#include "core/ui_integration.h"
|
2020-07-14 16:36:55 +00:00
|
|
|
#include "core/core_settings.h"
|
2019-03-28 08:48:32 +00:00
|
|
|
#include "chat_helpers/emoji_keywords.h"
|
2020-06-22 19:01:19 +00:00
|
|
|
#include "chat_helpers/stickers_emoji_image_loader.h"
|
2020-06-03 05:43:59 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2020-10-29 19:56:13 +00:00
|
|
|
#include "base/platform/base_platform_last_input.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "platform/platform_specific.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "mainwindow.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "dialogs/dialogs_entry.h"
|
|
|
|
#include "history/history.h"
|
2017-04-29 20:06:32 +00:00
|
|
|
#include "apiwrap.h"
|
2020-06-11 09:41:03 +00:00
|
|
|
#include "api/api_updates.h"
|
2017-04-29 20:06:32 +00:00
|
|
|
#include "calls/calls_instance.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_file_parser.h"
|
2017-04-13 08:45:58 +00:00
|
|
|
#include "lang/lang_translator.h"
|
2017-04-18 15:21:03 +00:00
|
|
|
#include "lang/lang_cloud_manager.h"
|
2018-05-24 13:40:19 +00:00
|
|
|
#include "lang/lang_hardcoded.h"
|
2020-09-30 09:11:44 +00:00
|
|
|
#include "lang/lang_instance.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "mainwidget.h"
|
2020-04-28 08:26:12 +00:00
|
|
|
#include "core/file_utilities.h"
|
2019-04-30 11:12:30 +00:00
|
|
|
#include "main/main_account.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "main/main_domain.h"
|
2020-06-15 16:25:02 +00:00
|
|
|
#include "main/main_session.h"
|
2019-02-12 11:00:47 +00:00
|
|
|
#include "media/view/media_view_overlay_widget.h"
|
2020-06-17 09:36:25 +00:00
|
|
|
#include "mtproto/mtproto_dc_options.h"
|
|
|
|
#include "mtproto/mtproto_config.h"
|
2017-02-24 17:15:41 +00:00
|
|
|
#include "mtproto/mtp_instance.h"
|
2019-02-13 12:36:59 +00:00
|
|
|
#include "media/audio/media_audio.h"
|
|
|
|
#include "media/audio/media_audio_track.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "media/player/media_player_instance.h"
|
2020-06-25 14:17:37 +00:00
|
|
|
#include "media/player/media_player_float.h"
|
2019-04-02 10:29:28 +00:00
|
|
|
#include "media/clip/media_clip_reader.h" // For Media::Clip::Finish().
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "window/notifications_manager.h"
|
|
|
|
#include "window/themes/window_theme.h"
|
2018-06-03 13:30:40 +00:00
|
|
|
#include "window/window_lock_widgets.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "history/history_location_manager.h"
|
|
|
|
#include "ui/widgets/tooltip.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "ui/text/text_options.h"
|
2018-10-13 17:35:30 +00:00
|
|
|
#include "ui/emoji_config.h"
|
2019-02-04 13:34:50 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/serialize_common.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "storage/storage_domain.h"
|
2020-06-15 16:25:02 +00:00
|
|
|
#include "storage/storage_databases.h"
|
|
|
|
#include "storage/localstorage.h"
|
2020-06-25 07:14:05 +00:00
|
|
|
#include "export/export_manager.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2019-06-06 11:20:21 +00:00
|
|
|
#include "window/window_controller.h"
|
2017-06-27 20:11:38 +00:00
|
|
|
#include "base/qthelp_regex.h"
|
|
|
|
#include "base/qthelp_url.h"
|
|
|
|
#include "boxes/connection_box.h"
|
|
|
|
#include "boxes/confirm_phone_box.h"
|
2018-05-24 13:40:19 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2017-06-27 20:11:38 +00:00
|
|
|
#include "boxes/share_box.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
|
|
|
#include "app.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtWidgets/QDesktopWidget>
|
|
|
|
#include <QtCore/QMimeDatabase>
|
|
|
|
#include <QtGui/QGuiApplication>
|
2020-11-04 15:50:17 +00:00
|
|
|
#include <QtGui/QScreen>
|
2019-09-04 07:19:15 +00:00
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
namespace Core {
|
2017-02-23 10:59:19 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-06-08 15:56:52 +00:00
|
|
|
constexpr auto kQuitPreventTimeoutMs = crl::time(1500);
|
|
|
|
constexpr auto kAutoLockTimeoutLateMs = crl::time(3000);
|
2020-06-22 19:01:19 +00:00
|
|
|
constexpr auto kClearEmojiImageSourceTimeout = 10 * crl::time(1000);
|
2017-04-29 20:06:32 +00:00
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-02-04 13:34:50 +00:00
|
|
|
Application *Application::Instance = nullptr;
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
struct Application::Private {
|
2017-04-29 20:06:32 +00:00
|
|
|
base::Timer quitTimer;
|
2019-09-16 11:14:06 +00:00
|
|
|
UiIntegration uiIntegration;
|
2017-02-24 17:15:41 +00:00
|
|
|
};
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
Application::Application(not_null<Launcher*> launcher)
|
2017-12-11 14:45:29 +00:00
|
|
|
: QObject()
|
|
|
|
, _launcher(launcher)
|
2017-05-03 11:36:39 +00:00
|
|
|
, _private(std::make_unique<Private>())
|
2018-08-29 13:23:16 +00:00
|
|
|
, _databases(std::make_unique<Storage::Databases>())
|
2019-02-04 13:34:50 +00:00
|
|
|
, _animationsManager(std::make_unique<Ui::Animations::Manager>())
|
2020-06-22 19:01:19 +00:00
|
|
|
, _clearEmojiImageLoaderTimer([=] { clearEmojiSourceImages(); })
|
2020-06-25 17:57:36 +00:00
|
|
|
, _audio(std::make_unique<Media::Audio::Instance>())
|
2020-06-17 09:36:25 +00:00
|
|
|
, _fallbackProductionConfig(
|
|
|
|
std::make_unique<MTP::Config>(MTP::Environment::Production))
|
2020-06-18 18:04:16 +00:00
|
|
|
, _domain(std::make_unique<Main::Domain>(cDataFile()))
|
2020-06-25 07:14:05 +00:00
|
|
|
, _exportManager(std::make_unique<Export::Manager>())
|
2020-06-25 17:57:36 +00:00
|
|
|
, _calls(std::make_unique<Calls::Instance>())
|
2017-04-13 17:59:05 +00:00
|
|
|
, _langpack(std::make_unique<Lang::Instance>())
|
2019-11-27 08:02:56 +00:00
|
|
|
, _langCloudManager(std::make_unique<Lang::CloudManager>(langpack()))
|
2019-03-28 08:48:32 +00:00
|
|
|
, _emojiKeywords(std::make_unique<ChatHelpers::EmojiKeywords>())
|
2017-05-12 15:27:19 +00:00
|
|
|
, _logo(Window::LoadLogo())
|
2020-06-08 15:56:52 +00:00
|
|
|
, _logoNoMargin(Window::LoadLogoNoMargin())
|
|
|
|
, _autoLockTimer([=] { checkAutoLock(); }) {
|
2017-05-12 15:27:19 +00:00
|
|
|
Expects(!_logo.isNull());
|
|
|
|
Expects(!_logoNoMargin.isNull());
|
2019-02-04 13:34:50 +00:00
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
Ui::Integration::Set(&_private->uiIntegration);
|
|
|
|
|
2020-06-08 15:56:52 +00:00
|
|
|
passcodeLockChanges(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_shouldLockAt = 0;
|
|
|
|
}, _lifetime);
|
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
passcodeLockChanges(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_notifications->updateAll();
|
|
|
|
}, _lifetime);
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
_domain->activeSessionChanges(
|
2020-06-10 10:49:10 +00:00
|
|
|
) | rpl::start_with_next([=](Main::Session *session) {
|
2020-06-10 14:52:44 +00:00
|
|
|
if (session && !UpdaterDisabled()) { // #TODO multi someSessionValue
|
2020-06-10 13:24:41 +00:00
|
|
|
UpdateChecker().setMtproto(session);
|
2020-06-10 10:49:10 +00:00
|
|
|
}
|
2019-07-24 08:46:23 +00:00
|
|
|
}, _lifetime);
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
_domain->activeValue(
|
2020-06-17 09:36:25 +00:00
|
|
|
) | rpl::filter(rpl::mappers::_1 != nullptr
|
|
|
|
) | rpl::take(1) | rpl::start_with_next([=] {
|
2020-06-09 16:57:05 +00:00
|
|
|
if (_window) {
|
2020-06-15 16:25:02 +00:00
|
|
|
// Global::DesktopNotify is used in updateTrayMenu.
|
2020-06-09 16:57:05 +00:00
|
|
|
// This should be called when user settings are read.
|
|
|
|
// Right now after they are read the startMtp() is called.
|
|
|
|
_window->widget()->updateTrayMenu();
|
|
|
|
}
|
2019-07-24 08:46:23 +00:00
|
|
|
}, _lifetime);
|
2019-01-21 13:42:21 +00:00
|
|
|
}
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2019-03-28 08:48:32 +00:00
|
|
|
Application::~Application() {
|
2020-06-15 16:25:02 +00:00
|
|
|
// Depend on activeWindow() for now :(
|
|
|
|
Shortcuts::Finish();
|
|
|
|
|
2020-06-25 09:42:30 +00:00
|
|
|
_window = nullptr;
|
|
|
|
_mediaView = nullptr;
|
2020-06-30 15:33:22 +00:00
|
|
|
_notifications->clearAllFast();
|
2020-06-18 18:04:16 +00:00
|
|
|
_domain->finish();
|
2019-03-28 08:48:32 +00:00
|
|
|
|
2019-06-22 10:36:35 +00:00
|
|
|
Local::finish();
|
|
|
|
|
2019-03-28 08:48:32 +00:00
|
|
|
Shortcuts::Finish();
|
|
|
|
|
|
|
|
Ui::Emoji::Clear();
|
2019-04-02 10:29:28 +00:00
|
|
|
Media::Clip::Finish();
|
2019-03-28 08:48:32 +00:00
|
|
|
|
|
|
|
App::deinitMedia();
|
|
|
|
|
2019-09-05 06:51:46 +00:00
|
|
|
Window::Theme::Uninitialize();
|
2019-03-28 08:48:32 +00:00
|
|
|
|
|
|
|
Media::Player::finish(_audio.get());
|
|
|
|
style::stopManager();
|
|
|
|
|
|
|
|
Global::finish();
|
|
|
|
ThirdParty::finish();
|
|
|
|
|
|
|
|
Instance = nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::run() {
|
2019-09-13 10:24:06 +00:00
|
|
|
style::internal::StartFonts();
|
2017-02-23 10:59:19 +00:00
|
|
|
|
|
|
|
ThirdParty::start();
|
|
|
|
Global::start();
|
2020-06-19 17:13:43 +00:00
|
|
|
refreshGlobalProxy(); // Depends on Global::start().
|
|
|
|
|
|
|
|
// Depends on OpenSSL on macOS, so on ThirdParty::start().
|
2020-06-30 07:44:32 +00:00
|
|
|
// Depends on notifications settings.
|
2020-06-19 17:13:43 +00:00
|
|
|
_notifications = std::make_unique<Window::Notifications::System>();
|
2017-02-23 10:59:19 +00:00
|
|
|
|
|
|
|
startLocalStorage();
|
2019-09-13 10:24:06 +00:00
|
|
|
ValidateScale();
|
2017-02-23 10:59:19 +00:00
|
|
|
|
|
|
|
if (Local::oldSettingsVersion() < AppVersion) {
|
|
|
|
psNewVersion();
|
|
|
|
}
|
|
|
|
|
2020-05-29 17:49:39 +00:00
|
|
|
if (cAutoStart() && !Platform::AutostartSupported()) {
|
|
|
|
cSetAutoStart(false);
|
|
|
|
}
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
if (cLaunchMode() == LaunchModeAutoStart && !cAutoStart()) {
|
|
|
|
psAutoStart(false, true);
|
|
|
|
App::quit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-18 05:06:29 +00:00
|
|
|
Core::App().settings().setWindowControlsLayout(Platform::WindowControlsLayout());
|
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
_translator = std::make_unique<Lang::Translator>();
|
2019-01-21 13:42:21 +00:00
|
|
|
QCoreApplication::instance()->installTranslator(_translator.get());
|
2017-04-13 17:59:05 +00:00
|
|
|
|
2019-09-13 10:24:06 +00:00
|
|
|
style::startManager(cScale());
|
2017-12-28 13:06:06 +00:00
|
|
|
Ui::InitTextOptions();
|
2018-10-13 17:35:30 +00:00
|
|
|
Ui::Emoji::Init();
|
2020-06-22 19:01:19 +00:00
|
|
|
startEmojiImageLoader();
|
2020-07-22 12:10:17 +00:00
|
|
|
startSystemDarkModeViewer();
|
2019-02-01 07:09:55 +00:00
|
|
|
Media::Player::start(_audio.get());
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2019-09-13 16:45:48 +00:00
|
|
|
style::ShortAnimationPlaying(
|
|
|
|
) | rpl::start_with_next([=](bool playing) {
|
|
|
|
if (playing) {
|
2019-12-02 13:10:19 +00:00
|
|
|
MTP::details::pause();
|
2019-09-13 16:45:48 +00:00
|
|
|
} else {
|
2019-12-02 13:10:19 +00:00
|
|
|
MTP::details::unpause();
|
2019-09-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
}, _lifetime);
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
DEBUG_LOG(("Application Info: inited..."));
|
|
|
|
|
|
|
|
cChangeTimeFormat(QLocale::system().timeFormat(QLocale::ShortFormat));
|
|
|
|
|
|
|
|
DEBUG_LOG(("Application Info: starting app..."));
|
|
|
|
|
|
|
|
// Create mime database, so it won't be slow later.
|
|
|
|
QMimeDatabase().mimeTypeForName(qsl("text/plain"));
|
|
|
|
|
2020-06-15 16:25:02 +00:00
|
|
|
_window = std::make_unique<Window::Controller>();
|
2020-07-22 12:10:17 +00:00
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
_domain->activeChanges(
|
2020-06-16 06:42:47 +00:00
|
|
|
) | rpl::start_with_next([=](not_null<Main::Account*> account) {
|
|
|
|
_window->showAccount(account);
|
|
|
|
}, _window->widget()->lifetime());
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
QCoreApplication::instance()->installEventFilter(this);
|
2020-12-03 16:34:18 +00:00
|
|
|
|
2020-12-06 15:01:37 +00:00
|
|
|
appDeactivatedValue(
|
2020-12-03 16:34:18 +00:00
|
|
|
) | rpl::start_with_next([=](bool deactivated) {
|
|
|
|
if (deactivated) {
|
|
|
|
handleAppDeactivated();
|
|
|
|
} else {
|
|
|
|
handleAppActivated();
|
|
|
|
}
|
|
|
|
}, _lifetime);
|
2017-02-23 10:59:19 +00:00
|
|
|
|
|
|
|
DEBUG_LOG(("Application Info: window created..."));
|
|
|
|
|
2020-06-15 16:25:02 +00:00
|
|
|
// Depend on activeWindow() for now :(
|
2018-11-16 12:15:14 +00:00
|
|
|
startShortcuts();
|
2017-02-23 10:59:19 +00:00
|
|
|
App::initMedia();
|
2020-07-22 12:10:17 +00:00
|
|
|
startDomain();
|
2020-02-12 08:09:17 +00:00
|
|
|
|
|
|
|
_window->widget()->show();
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2020-02-11 09:28:53 +00:00
|
|
|
const auto currentGeometry = _window->widget()->geometry();
|
2020-02-11 09:01:08 +00:00
|
|
|
_mediaView = std::make_unique<Media::View::OverlayWidget>();
|
2020-02-11 09:28:53 +00:00
|
|
|
_window->widget()->setGeometry(currentGeometry);
|
2020-02-11 09:01:08 +00:00
|
|
|
|
2020-02-12 08:09:17 +00:00
|
|
|
DEBUG_LOG(("Application Info: showing."));
|
|
|
|
_window->finishFirstShow();
|
|
|
|
|
2020-06-24 07:56:16 +00:00
|
|
|
if (!_window->locked() && cStartToSettings()) {
|
2017-02-23 10:59:19 +00:00
|
|
|
_window->showSettings();
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:36:25 +00:00
|
|
|
_window->updateIsActiveFocus();
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2018-11-16 12:15:14 +00:00
|
|
|
for (const auto &error : Shortcuts::Errors()) {
|
|
|
|
LOG(("Shortcuts Error: %1").arg(error));
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 12:10:17 +00:00
|
|
|
void Application::startDomain() {
|
|
|
|
const auto state = _domain->start(QByteArray());
|
|
|
|
if (state != Storage::StartResult::IncorrectPasscodeLegacy) {
|
|
|
|
// In case of non-legacy passcoded app all global settings are ready.
|
|
|
|
startSettingsAndBackground();
|
|
|
|
}
|
|
|
|
if (state != Storage::StartResult::Success) {
|
|
|
|
Global::SetLocalPasscode(true);
|
|
|
|
Global::RefLocalPasscodeChanged().notify();
|
|
|
|
lockByPasscode();
|
|
|
|
DEBUG_LOG(("Application Info: passcode needed..."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::startSettingsAndBackground() {
|
|
|
|
Local::rewriteSettingsIfNeeded();
|
|
|
|
Window::Theme::Background()->start();
|
|
|
|
checkSystemDarkMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::checkSystemDarkMode() {
|
|
|
|
const auto maybeDarkMode = _settings.systemDarkMode();
|
|
|
|
const auto darkModeEnabled = _settings.systemDarkModeEnabled();
|
|
|
|
const auto needToSwitch = darkModeEnabled
|
|
|
|
&& maybeDarkMode
|
|
|
|
&& (*maybeDarkMode != Window::Theme::IsNightMode());
|
|
|
|
if (needToSwitch) {
|
|
|
|
Window::Theme::ToggleNightMode();
|
|
|
|
Window::Theme::KeepApplied();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::startSystemDarkModeViewer() {
|
2020-07-24 06:01:37 +00:00
|
|
|
if (Window::Theme::Background()->editingTheme()) {
|
|
|
|
_settings.setSystemDarkModeEnabled(false);
|
|
|
|
}
|
2020-07-22 12:10:17 +00:00
|
|
|
rpl::merge(
|
|
|
|
_settings.systemDarkModeChanges() | rpl::to_empty,
|
|
|
|
_settings.systemDarkModeEnabledChanges() | rpl::to_empty
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
checkSystemDarkMode();
|
|
|
|
}, _lifetime);
|
|
|
|
}
|
|
|
|
|
2020-06-22 19:01:19 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
bool Application::hideMediaView() {
|
2017-08-08 09:31:48 +00:00
|
|
|
if (_mediaView && !_mediaView->isHidden()) {
|
|
|
|
_mediaView->hide();
|
2019-06-06 11:20:21 +00:00
|
|
|
if (const auto window = activeWindow()) {
|
|
|
|
window->reActivate();
|
2017-08-08 09:56:10 +00:00
|
|
|
}
|
2017-08-08 09:31:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::showPhoto(not_null<const PhotoOpenClickHandler*> link) {
|
2019-06-06 11:59:00 +00:00
|
|
|
const auto photo = link->photo();
|
2017-12-15 16:25:47 +00:00
|
|
|
const auto peer = link->peer();
|
2019-06-06 11:59:00 +00:00
|
|
|
const auto item = photo->owner().message(link->context());
|
2017-12-15 16:25:47 +00:00
|
|
|
return (!item && peer)
|
2019-06-06 11:59:00 +00:00
|
|
|
? showPhoto(photo, peer)
|
|
|
|
: showPhoto(photo, item);
|
2017-08-08 09:31:48 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::showPhoto(not_null<PhotoData*> photo, HistoryItem *item) {
|
2020-02-12 08:09:17 +00:00
|
|
|
Expects(_mediaView != nullptr);
|
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
_mediaView->showPhoto(photo, item);
|
|
|
|
_mediaView->activateWindow();
|
|
|
|
_mediaView->setFocus();
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::showPhoto(
|
2017-12-15 16:25:47 +00:00
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
not_null<PeerData*> peer) {
|
2020-02-12 08:09:17 +00:00
|
|
|
Expects(_mediaView != nullptr);
|
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
_mediaView->showPhoto(photo, peer);
|
|
|
|
_mediaView->activateWindow();
|
|
|
|
_mediaView->setFocus();
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::showDocument(not_null<DocumentData*> document, HistoryItem *item) {
|
2020-02-12 08:09:17 +00:00
|
|
|
Expects(_mediaView != nullptr);
|
|
|
|
|
2019-02-28 21:03:25 +00:00
|
|
|
if (cUseExternalVideoPlayer()
|
|
|
|
&& document->isVideoFile()
|
2020-04-09 14:02:09 +00:00
|
|
|
&& !document->filepath().isEmpty()) {
|
2020-04-28 08:26:12 +00:00
|
|
|
File::Launch(document->location(false).fname);
|
2017-08-08 09:31:48 +00:00
|
|
|
} else {
|
|
|
|
_mediaView->showDocument(document, item);
|
|
|
|
_mediaView->activateWindow();
|
|
|
|
_mediaView->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 15:31:01 +00:00
|
|
|
void Application::showTheme(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
const Data::CloudTheme &cloud) {
|
2020-02-12 08:09:17 +00:00
|
|
|
Expects(_mediaView != nullptr);
|
|
|
|
|
2019-09-06 15:31:01 +00:00
|
|
|
_mediaView->showTheme(document, cloud);
|
|
|
|
_mediaView->activateWindow();
|
|
|
|
_mediaView->setFocus();
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
PeerData *Application::ui_getPeerForMouseAction() {
|
2017-08-08 09:31:48 +00:00
|
|
|
if (_mediaView && !_mediaView->isHidden()) {
|
|
|
|
return _mediaView->ui_getPeerForMouseAction();
|
2020-06-12 14:09:04 +00:00
|
|
|
} else if (const auto m = App::main()) { // multi good
|
|
|
|
return m->ui_getPeerForMouseAction();
|
2017-08-08 09:31:48 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
bool Application::eventFilter(QObject *object, QEvent *e) {
|
2017-08-08 09:31:48 +00:00
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::KeyPress:
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
case QEvent::TouchBegin:
|
|
|
|
case QEvent::Wheel: {
|
2019-03-10 13:40:44 +00:00
|
|
|
updateNonIdle();
|
2017-08-08 09:31:48 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::ShortcutOverride: {
|
|
|
|
// handle shortcuts ourselves
|
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::Shortcut: {
|
2018-11-16 12:15:14 +00:00
|
|
|
const auto event = static_cast<QShortcutEvent*>(e);
|
|
|
|
DEBUG_LOG(("Shortcut event caught: %1"
|
|
|
|
).arg(event->key().toString()));
|
|
|
|
if (Shortcuts::HandleEvent(event)) {
|
2017-08-08 09:31:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::ApplicationActivate: {
|
2019-01-21 13:42:21 +00:00
|
|
|
if (object == QCoreApplication::instance()) {
|
2019-03-10 13:40:44 +00:00
|
|
|
updateNonIdle();
|
2017-08-08 09:31:48 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::FileOpen: {
|
2019-01-21 13:42:21 +00:00
|
|
|
if (object == QCoreApplication::instance()) {
|
|
|
|
const auto event = static_cast<QFileOpenEvent*>(e);
|
|
|
|
const auto url = QString::fromUtf8(
|
|
|
|
event->url().toEncoded().trimmed());
|
2017-08-08 09:31:48 +00:00
|
|
|
if (url.startsWith(qstr("tg://"), Qt::CaseInsensitive)) {
|
|
|
|
cSetStartUrl(url.mid(0, 8192));
|
|
|
|
checkStartUrl();
|
|
|
|
}
|
2018-04-13 05:11:53 +00:00
|
|
|
if (StartUrlRequiresActivate(url)) {
|
|
|
|
_window->activate();
|
|
|
|
}
|
2017-08-08 09:31:48 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QObject::eventFilter(object, e);
|
|
|
|
}
|
|
|
|
|
2019-08-23 13:52:59 +00:00
|
|
|
void Application::saveSettingsDelayed(crl::time delay) {
|
|
|
|
_saveSettingsTimer.callOnce(delay);
|
|
|
|
}
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
void Application::saveSettings() {
|
|
|
|
Local::writeSettings();
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:36:25 +00:00
|
|
|
MTP::Config &Application::fallbackProductionConfig() const {
|
|
|
|
if (!_fallbackProductionConfig) {
|
|
|
|
_fallbackProductionConfig = std::make_unique<MTP::Config>(
|
|
|
|
MTP::Environment::Production);
|
|
|
|
}
|
|
|
|
return *_fallbackProductionConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::refreshFallbackProductionConfig(
|
|
|
|
const MTP::Config &config) {
|
|
|
|
if (config.environment() == MTP::Environment::Production) {
|
|
|
|
_fallbackProductionConfig = std::make_unique<MTP::Config>(config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::constructFallbackProductionConfig(
|
|
|
|
const QByteArray &serialized) {
|
|
|
|
if (auto config = MTP::Config::FromSerialized(serialized)) {
|
|
|
|
if (config->environment() == MTP::Environment::Production) {
|
|
|
|
_fallbackProductionConfig = std::move(config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::setCurrentProxy(
|
2019-11-13 14:12:04 +00:00
|
|
|
const MTP::ProxyData &proxy,
|
|
|
|
MTP::ProxyData::Settings settings) {
|
2019-07-24 08:46:23 +00:00
|
|
|
const auto current = [&] {
|
2019-11-13 14:12:04 +00:00
|
|
|
return (Global::ProxySettings() == MTP::ProxyData::Settings::Enabled)
|
2018-11-05 13:58:24 +00:00
|
|
|
? Global::SelectedProxy()
|
2019-11-13 14:12:04 +00:00
|
|
|
: MTP::ProxyData();
|
2019-07-24 08:46:23 +00:00
|
|
|
};
|
|
|
|
const auto was = current();
|
2018-05-18 12:20:28 +00:00
|
|
|
Global::SetSelectedProxy(proxy);
|
2018-11-05 13:58:24 +00:00
|
|
|
Global::SetProxySettings(settings);
|
2019-07-24 08:46:23 +00:00
|
|
|
const auto now = current();
|
2019-01-21 13:42:21 +00:00
|
|
|
refreshGlobalProxy();
|
2019-07-24 08:46:23 +00:00
|
|
|
_proxyChanges.fire({ was, now });
|
2018-05-18 12:20:28 +00:00
|
|
|
Global::RefConnectionTypeChanged().notify();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:46:23 +00:00
|
|
|
auto Application::proxyChanges() const -> rpl::producer<ProxyChange> {
|
|
|
|
return _proxyChanges.events();
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::badMtprotoConfigurationError() {
|
2019-11-13 14:12:04 +00:00
|
|
|
if (Global::ProxySettings() == MTP::ProxyData::Settings::Enabled
|
2018-11-05 13:58:24 +00:00
|
|
|
&& !_badProxyDisableBox) {
|
|
|
|
const auto disableCallback = [=] {
|
|
|
|
setCurrentProxy(
|
|
|
|
Global::SelectedProxy(),
|
2019-11-13 14:12:04 +00:00
|
|
|
MTP::ProxyData::Settings::System);
|
2018-11-05 13:58:24 +00:00
|
|
|
};
|
2018-05-24 13:40:19 +00:00
|
|
|
_badProxyDisableBox = Ui::show(Box<InformBox>(
|
|
|
|
Lang::Hard::ProxyConfigError(),
|
2018-11-05 13:58:24 +00:00
|
|
|
disableCallback));
|
2018-05-24 13:40:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::startLocalStorage() {
|
2017-02-23 10:59:19 +00:00
|
|
|
Local::start();
|
2020-06-18 18:04:16 +00:00
|
|
|
_saveSettingsTimer.setCallback([=] { saveSettings(); });
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 19:01:19 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:17:37 +00:00
|
|
|
void Application::setDefaultFloatPlayerDelegate(
|
|
|
|
not_null<Media::Player::FloatDelegate*> delegate) {
|
|
|
|
Expects(!_defaultFloatPlayerDelegate == !_floatPlayers);
|
|
|
|
|
|
|
|
_defaultFloatPlayerDelegate = delegate;
|
|
|
|
_replacementFloatPlayerDelegate = nullptr;
|
|
|
|
if (_floatPlayers) {
|
|
|
|
_floatPlayers->replaceDelegate(delegate);
|
|
|
|
} else {
|
|
|
|
_floatPlayers = std::make_unique<Media::Player::FloatController>(
|
|
|
|
delegate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::replaceFloatPlayerDelegate(
|
|
|
|
not_null<Media::Player::FloatDelegate*> replacement) {
|
|
|
|
Expects(_floatPlayers != nullptr);
|
|
|
|
|
|
|
|
_replacementFloatPlayerDelegate = replacement;
|
|
|
|
_floatPlayers->replaceDelegate(replacement);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::restoreFloatPlayerDelegate(
|
|
|
|
not_null<Media::Player::FloatDelegate*> replacement) {
|
|
|
|
Expects(_floatPlayers != nullptr);
|
|
|
|
|
|
|
|
if (_replacementFloatPlayerDelegate == replacement) {
|
|
|
|
_replacementFloatPlayerDelegate = nullptr;
|
|
|
|
_floatPlayers->replaceDelegate(_defaultFloatPlayerDelegate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<FullMsgId> Application::floatPlayerClosed() const {
|
|
|
|
Expects(_floatPlayers != nullptr);
|
|
|
|
|
|
|
|
return _floatPlayers->closeEvents();
|
|
|
|
}
|
|
|
|
|
2020-06-16 09:40:43 +00:00
|
|
|
void Application::logout(Main::Account *account) {
|
|
|
|
if (account) {
|
|
|
|
account->logOut();
|
|
|
|
} else {
|
2020-06-18 18:04:16 +00:00
|
|
|
_domain->resetWithForgottenPasscode();
|
2020-06-16 09:40:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::forceLogOut(
|
|
|
|
not_null<Main::Account*> account,
|
|
|
|
const TextWithEntities &explanation) {
|
2018-06-04 18:18:52 +00:00
|
|
|
const auto box = Ui::show(Box<InformBox>(
|
|
|
|
explanation,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_passcode_logout(tr::now)));
|
2018-06-06 11:51:27 +00:00
|
|
|
box->setCloseByEscape(false);
|
|
|
|
box->setCloseByOutsideClick(false);
|
2020-06-16 09:40:43 +00:00
|
|
|
const auto weak = base::make_weak(account.get());
|
2018-06-04 18:18:52 +00:00
|
|
|
connect(box, &QObject::destroyed, [=] {
|
2020-06-16 09:40:43 +00:00
|
|
|
crl::on_main(weak, [=] {
|
|
|
|
account->forcedLogOut();
|
2018-06-04 18:18:52 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::checkLocalTime() {
|
2020-06-11 09:41:03 +00:00
|
|
|
const auto adjusted = crl::adjust_time();
|
|
|
|
if (adjusted) {
|
2019-02-19 06:57:53 +00:00
|
|
|
base::Timer::Adjust();
|
|
|
|
base::ConcurrentTimerEnvironment::Adjust();
|
2019-07-10 17:28:33 +00:00
|
|
|
base::unixtime::http_invalidate();
|
2020-06-11 09:41:03 +00:00
|
|
|
}
|
2020-06-16 10:09:16 +00:00
|
|
|
if (const auto session = maybeActiveSession()) {
|
|
|
|
session->updates().checkLastUpdate(adjusted);
|
2019-02-19 06:57:53 +00:00
|
|
|
}
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::handleAppActivated() {
|
2017-02-23 10:59:19 +00:00
|
|
|
checkLocalTime();
|
|
|
|
if (_window) {
|
2020-06-17 09:36:25 +00:00
|
|
|
_window->updateIsActiveFocus();
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::handleAppDeactivated() {
|
2017-02-23 10:59:19 +00:00
|
|
|
if (_window) {
|
2020-06-17 09:36:25 +00:00
|
|
|
_window->updateIsActiveBlur();
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
}
|
|
|
|
|
2020-12-06 15:01:37 +00:00
|
|
|
rpl::producer<bool> Application::appDeactivatedValue() const {
|
|
|
|
const auto &app =
|
|
|
|
static_cast<QGuiApplication*>(QCoreApplication::instance());
|
|
|
|
return rpl::single(
|
|
|
|
app->applicationState()
|
|
|
|
) | rpl::then(
|
|
|
|
base::qt_signal_producer(
|
|
|
|
app,
|
|
|
|
&QGuiApplication::applicationStateChanged
|
|
|
|
)) | rpl::map([=](Qt::ApplicationState state) {
|
2020-12-03 16:34:18 +00:00
|
|
|
return (state != Qt::ApplicationActive);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::call_handleObservables() {
|
2017-02-23 10:59:19 +00:00
|
|
|
base::HandleObservables();
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::switchDebugMode() {
|
2018-06-05 13:32:26 +00:00
|
|
|
if (Logs::DebugEnabled()) {
|
|
|
|
Logs::SetDebugEnabled(false);
|
2019-01-21 13:42:21 +00:00
|
|
|
_launcher->writeDebugModeSetting();
|
2017-02-23 10:59:19 +00:00
|
|
|
App::restart();
|
|
|
|
} else {
|
2018-06-05 13:32:26 +00:00
|
|
|
Logs::SetDebugEnabled(true);
|
2019-01-21 13:42:21 +00:00
|
|
|
_launcher->writeDebugModeSetting();
|
2017-02-23 10:59:19 +00:00
|
|
|
DEBUG_LOG(("Debug logs started."));
|
|
|
|
Ui::hideLayer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-08 22:37:43 +00:00
|
|
|
void Application::switchFreeType() {
|
|
|
|
if (cUseFreeType()) {
|
|
|
|
QFile(cWorkingDir() + qsl("tdata/withfreetype")).remove();
|
|
|
|
cSetUseFreeType(false);
|
|
|
|
} else {
|
|
|
|
QFile f(cWorkingDir() + qsl("tdata/withfreetype"));
|
|
|
|
if (f.open(QIODevice::WriteOnly)) {
|
|
|
|
f.write("1");
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
cSetUseFreeType(true);
|
|
|
|
}
|
|
|
|
App::restart();
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::writeInstallBetaVersionsSetting() {
|
|
|
|
_launcher->writeInstallBetaVersionsSetting();
|
|
|
|
}
|
|
|
|
|
2020-06-15 16:25:02 +00:00
|
|
|
Main::Account &Application::activeAccount() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _domain->active();
|
2020-06-15 16:25:02 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 10:09:16 +00:00
|
|
|
Main::Session *Application::maybeActiveSession() const {
|
2020-06-23 13:29:02 +00:00
|
|
|
return _domain->started() ? activeAccount().maybeSession() : nullptr;
|
2020-06-16 10:09:16 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
bool Application::exportPreventsQuit() {
|
2020-06-25 07:14:05 +00:00
|
|
|
if (_exportManager->inProgress()) {
|
|
|
|
_exportManager->stopWithConfirmation([] {
|
|
|
|
App::quit();
|
|
|
|
});
|
|
|
|
return true;
|
2019-07-24 14:00:30 +00:00
|
|
|
}
|
2020-06-16 10:09:16 +00:00
|
|
|
return false;
|
2019-07-24 14:00:30 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
int Application::unreadBadge() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _domain->unreadBadge();
|
2018-12-04 10:32:06 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
bool Application::unreadBadgeMuted() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _domain->unreadBadgeMuted();
|
2020-06-18 11:17:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> Application::unreadBadgeChanges() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _domain->unreadBadgeChanges();
|
2018-12-04 10:32:06 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 14:52:44 +00:00
|
|
|
bool Application::offerLegacyLangPackSwitch() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return (_domain->accounts().size() == 1)
|
|
|
|
&& activeAccount().sessionExists();
|
2020-06-10 13:24:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Application::canApplyLangPackWithoutRestart() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
for (const auto &[index, account] : _domain->accounts()) {
|
2020-06-15 16:25:02 +00:00
|
|
|
if (account->sessionExists()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2020-06-10 13:24:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::checkStartUrl() {
|
2020-06-24 07:56:16 +00:00
|
|
|
if (!cStartUrl().isEmpty() && _window && !_window->locked()) {
|
2019-04-02 10:29:28 +00:00
|
|
|
const auto url = cStartUrl();
|
2017-06-27 20:11:38 +00:00
|
|
|
cSetStartUrl(QString());
|
2018-07-09 18:13:48 +00:00
|
|
|
if (!openLocalUrl(url, {})) {
|
2017-06-27 20:11:38 +00:00
|
|
|
cSetStartUrl(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
bool Application::openLocalUrl(const QString &url, QVariant context) {
|
2019-12-25 15:20:02 +00:00
|
|
|
return openCustomUrl("tg://", LocalUrlHandlers(), url, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Application::openInternalUrl(const QString &url, QVariant context) {
|
|
|
|
return openCustomUrl("internal:", InternalUrlHandlers(), url, context);
|
|
|
|
}
|
2017-06-27 20:11:38 +00:00
|
|
|
|
2019-12-25 15:20:02 +00:00
|
|
|
bool Application::openCustomUrl(
|
|
|
|
const QString &protocol,
|
|
|
|
const std::vector<LocalUrlHandler> &handlers,
|
|
|
|
const QString &url,
|
|
|
|
const QVariant &context) {
|
|
|
|
const auto urlTrimmed = url.trimmed();
|
2020-06-24 07:56:16 +00:00
|
|
|
if (!urlTrimmed.startsWith(protocol, Qt::CaseInsensitive)
|
|
|
|
|| passcodeLocked()) {
|
2017-06-27 20:11:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-25 15:20:02 +00:00
|
|
|
const auto command = urlTrimmed.midRef(protocol.size(), 8192);
|
2020-06-24 07:56:16 +00:00
|
|
|
const auto controller = _window ? _window->sessionController() : nullptr;
|
2020-06-16 10:09:16 +00:00
|
|
|
|
2017-06-27 20:11:38 +00:00
|
|
|
using namespace qthelp;
|
2018-11-26 11:55:02 +00:00
|
|
|
const auto options = RegExOption::CaseInsensitive;
|
2019-12-25 15:20:02 +00:00
|
|
|
for (const auto &[expression, handler] : handlers) {
|
2018-11-26 11:55:02 +00:00
|
|
|
const auto match = regex_match(expression, command, options);
|
|
|
|
if (match) {
|
2020-06-24 07:56:16 +00:00
|
|
|
return handler(controller, match, context);
|
2018-04-18 15:42:02 +00:00
|
|
|
}
|
2017-06-27 20:11:38 +00:00
|
|
|
}
|
|
|
|
return false;
|
2019-12-25 15:20:02 +00:00
|
|
|
|
2017-06-27 20:11:38 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::lockByPasscode() {
|
2018-06-03 13:30:40 +00:00
|
|
|
_passcodeLock = true;
|
|
|
|
_window->setupPasscodeLock();
|
2017-04-15 18:48:54 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::unlockPasscode() {
|
2018-06-07 07:44:38 +00:00
|
|
|
clearPasscodeLock();
|
2019-07-24 08:46:23 +00:00
|
|
|
if (_window) {
|
|
|
|
_window->clearPasscodeLock();
|
|
|
|
}
|
2018-06-07 07:44:38 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::clearPasscodeLock() {
|
2018-06-07 07:44:38 +00:00
|
|
|
cSetPasscodeBadTries(0);
|
2018-06-03 13:30:40 +00:00
|
|
|
_passcodeLock = false;
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
bool Application::passcodeLocked() const {
|
2018-06-03 13:30:40 +00:00
|
|
|
return _passcodeLock.current();
|
|
|
|
}
|
|
|
|
|
2019-03-09 17:10:51 +00:00
|
|
|
void Application::updateNonIdle() {
|
|
|
|
_lastNonIdleTime = crl::now();
|
2020-06-16 10:09:16 +00:00
|
|
|
if (const auto session = maybeActiveSession()) {
|
|
|
|
session->updates().checkIdleFinish();
|
2020-06-11 09:41:03 +00:00
|
|
|
}
|
2019-03-09 17:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
crl::time Application::lastNonIdleTime() const {
|
2019-03-14 17:59:10 +00:00
|
|
|
return std::max(
|
2020-10-29 19:56:13 +00:00
|
|
|
base::Platform::LastUserInputTime().value_or(0),
|
2019-03-14 17:59:10 +00:00
|
|
|
_lastNonIdleTime);
|
2019-03-09 17:10:51 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
rpl::producer<bool> Application::passcodeLockChanges() const {
|
2018-06-03 13:30:40 +00:00
|
|
|
return _passcodeLock.changes();
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
rpl::producer<bool> Application::passcodeLockValue() const {
|
2018-06-03 13:30:40 +00:00
|
|
|
return _passcodeLock.value();
|
|
|
|
}
|
|
|
|
|
2020-06-15 16:25:02 +00:00
|
|
|
bool Application::someSessionExists() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
for (const auto &[index, account] : _domain->accounts()) {
|
2020-06-15 16:25:02 +00:00
|
|
|
if (account->sessionExists()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-08 15:56:52 +00:00
|
|
|
void Application::checkAutoLock() {
|
|
|
|
if (!Global::LocalPasscode()
|
|
|
|
|| passcodeLocked()
|
2020-06-15 16:25:02 +00:00
|
|
|
|| !someSessionExists()) {
|
2020-06-08 15:56:52 +00:00
|
|
|
_shouldLockAt = 0;
|
|
|
|
_autoLockTimer.cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkLocalTime();
|
|
|
|
const auto now = crl::now();
|
2020-06-18 18:04:16 +00:00
|
|
|
const auto shouldLockInMs = _settings.autoLock() * 1000LL;
|
2020-06-08 15:56:52 +00:00
|
|
|
const auto checkTimeMs = now - lastNonIdleTime();
|
|
|
|
if (checkTimeMs >= shouldLockInMs || (_shouldLockAt > 0 && now > _shouldLockAt + kAutoLockTimeoutLateMs)) {
|
|
|
|
_shouldLockAt = 0;
|
|
|
|
_autoLockTimer.cancel();
|
|
|
|
lockByPasscode();
|
|
|
|
} else {
|
|
|
|
_shouldLockAt = now + (shouldLockInMs - checkTimeMs);
|
|
|
|
_autoLockTimer.callOnce(shouldLockInMs - checkTimeMs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::checkAutoLockIn(crl::time time) {
|
|
|
|
if (_autoLockTimer.isActive()) {
|
|
|
|
auto remain = _autoLockTimer.remainingTime();
|
|
|
|
if (remain > 0 && remain <= time) return;
|
|
|
|
}
|
|
|
|
_autoLockTimer.callOnce(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::localPasscodeChanged() {
|
|
|
|
_shouldLockAt = 0;
|
|
|
|
_autoLockTimer.cancel();
|
|
|
|
checkAutoLock();
|
|
|
|
}
|
|
|
|
|
2020-06-11 09:41:03 +00:00
|
|
|
bool Application::hasActiveWindow(not_null<Main::Session*> session) const {
|
|
|
|
if (App::quitting() || !_window) {
|
|
|
|
return false;
|
2020-12-08 17:06:56 +00:00
|
|
|
} else if (_calls->hasActivePanel(session)) {
|
|
|
|
return true;
|
2020-06-11 09:41:03 +00:00
|
|
|
} else if (const auto controller = _window->sessionController()) {
|
2020-12-08 17:06:56 +00:00
|
|
|
if (&controller->session() == session
|
|
|
|
&& _window->widget()->isActive()) {
|
|
|
|
return true;
|
2020-06-11 09:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::saveCurrentDraftsToHistories() {
|
|
|
|
if (!_window) {
|
|
|
|
return;
|
|
|
|
} else if (const auto controller = _window->sessionController()) {
|
|
|
|
controller->content()->saveFieldToHistoryLocalDraft();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
Window::Controller *Application::activeWindow() const {
|
2017-02-23 10:59:19 +00:00
|
|
|
return _window.get();
|
|
|
|
}
|
2017-04-19 20:25:48 +00:00
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
bool Application::closeActiveWindow() {
|
2017-08-08 09:56:10 +00:00
|
|
|
if (hideMediaView()) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-06-06 11:20:21 +00:00
|
|
|
if (const auto window = activeWindow()) {
|
|
|
|
window->close();
|
2017-08-08 09:56:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
bool Application::minimizeActiveWindow() {
|
2017-08-08 09:56:10 +00:00
|
|
|
hideMediaView();
|
2019-06-06 11:20:21 +00:00
|
|
|
if (const auto window = activeWindow()) {
|
|
|
|
window->minimize();
|
2017-08-08 09:56:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
QWidget *Application::getFileDialogParent() {
|
2019-06-06 11:20:21 +00:00
|
|
|
return (_mediaView && _mediaView->isVisible())
|
|
|
|
? (QWidget*)_mediaView.get()
|
|
|
|
: activeWindow()
|
|
|
|
? (QWidget*)activeWindow()->widget()
|
|
|
|
: nullptr;
|
2017-08-08 09:31:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-07 11:34:40 +00:00
|
|
|
void Application::notifyFileDialogShown(bool shown) {
|
|
|
|
if (_mediaView) {
|
|
|
|
_mediaView->notifyFileDialogShown(shown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 05:50:07 +00:00
|
|
|
QWidget *Application::getModalParent() {
|
2020-06-18 18:04:16 +00:00
|
|
|
return (Platform::IsWayland() && activeWindow())
|
2020-06-24 07:56:16 +00:00
|
|
|
? activeWindow()->widget().get()
|
2020-05-27 05:50:07 +00:00
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::checkMediaViewActivation() {
|
2017-08-08 09:31:48 +00:00
|
|
|
if (_mediaView && !_mediaView->isHidden()) {
|
|
|
|
_mediaView->activateWindow();
|
2019-01-21 13:42:21 +00:00
|
|
|
QApplication::setActiveWindow(_mediaView.get());
|
2017-08-08 09:31:48 +00:00
|
|
|
_mediaView->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
QPoint Application::getPointForCallPanelCenter() const {
|
2019-06-06 11:20:21 +00:00
|
|
|
if (const auto window = activeWindow()) {
|
|
|
|
return window->getPointForCallPanelCenter();
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
2020-11-04 15:50:17 +00:00
|
|
|
return QGuiApplication::primaryScreen()->geometry().center();
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
2017-04-29 20:06:32 +00:00
|
|
|
|
2017-11-21 10:27:37 +00:00
|
|
|
// macOS Qt bug workaround, sometimes no leaveEvent() gets to the nested widgets.
|
2019-09-13 16:45:48 +00:00
|
|
|
void Application::registerLeaveSubscription(not_null<QWidget*> widget) {
|
2017-11-21 10:27:37 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2019-06-06 12:01:01 +00:00
|
|
|
if (const auto topLevel = widget->window()) {
|
|
|
|
if (topLevel == _window->widget()) {
|
2019-09-13 12:22:54 +00:00
|
|
|
auto weak = Ui::MakeWeak(widget);
|
2019-06-06 12:01:01 +00:00
|
|
|
auto subscription = _window->widget()->leaveEvents(
|
2017-12-22 07:05:20 +00:00
|
|
|
) | rpl::start_with_next([weak] {
|
|
|
|
if (const auto window = weak.data()) {
|
|
|
|
QEvent ev(QEvent::Leave);
|
|
|
|
QGuiApplication::sendEvent(window, &ev);
|
|
|
|
}
|
|
|
|
});
|
2017-11-30 18:04:13 +00:00
|
|
|
_leaveSubscriptions.emplace_back(weak, std::move(subscription));
|
2017-11-21 10:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // Q_OS_MAC
|
|
|
|
}
|
|
|
|
|
2019-09-13 16:45:48 +00:00
|
|
|
void Application::unregisterLeaveSubscription(not_null<QWidget*> widget) {
|
2017-11-21 10:27:37 +00:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
_leaveSubscriptions = std::move(
|
|
|
|
_leaveSubscriptions
|
|
|
|
) | ranges::action::remove_if([&](const LeaveSubscription &subscription) {
|
|
|
|
auto pointer = subscription.pointer.data();
|
|
|
|
return !pointer || (pointer == widget);
|
|
|
|
});
|
|
|
|
#endif // Q_OS_MAC
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::postponeCall(FnMut<void()> &&callable) {
|
|
|
|
Sandbox::Instance().postponeCall(std::move(callable));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::refreshGlobalProxy() {
|
|
|
|
Sandbox::Instance().refreshGlobalProxy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::QuitAttempt() {
|
2020-06-26 07:22:53 +00:00
|
|
|
if (!IsAppLaunched()
|
|
|
|
|| Sandbox::Instance().isSavingSession()
|
|
|
|
|| App().readyToQuit()) {
|
|
|
|
QApplication::quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Application::readyToQuit() {
|
|
|
|
auto prevented = false;
|
|
|
|
if (_calls->isQuitPrevent()) {
|
|
|
|
prevented = true;
|
|
|
|
}
|
|
|
|
if (_domain->started()) {
|
|
|
|
for (const auto &[index, account] : _domain->accounts()) {
|
|
|
|
if (const auto session = account->maybeSession()) {
|
|
|
|
if (session->updates().isQuitPrevent()) {
|
|
|
|
prevented = true;
|
|
|
|
}
|
|
|
|
if (session->api().isQuitPrevent()) {
|
|
|
|
prevented = true;
|
|
|
|
}
|
2020-06-16 10:09:16 +00:00
|
|
|
}
|
2017-04-29 20:06:32 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-26 07:22:53 +00:00
|
|
|
if (prevented) {
|
|
|
|
quitDelayed();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2017-04-29 20:06:32 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::quitPreventFinished() {
|
2017-04-29 20:06:32 +00:00
|
|
|
if (App::quitting()) {
|
|
|
|
QuitAttempt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::quitDelayed() {
|
2017-04-29 20:06:32 +00:00
|
|
|
if (!_private->quitTimer.isActive()) {
|
2019-01-18 11:26:43 +00:00
|
|
|
_private->quitTimer.setCallback([] { QApplication::quit(); });
|
2017-04-29 20:06:32 +00:00
|
|
|
_private->quitTimer.callOnce(kQuitPreventTimeoutMs);
|
|
|
|
}
|
|
|
|
}
|
2018-11-16 12:15:14 +00:00
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Application::startShortcuts() {
|
2018-11-16 12:15:14 +00:00
|
|
|
Shortcuts::Start();
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
_domain->activeSessionChanges(
|
2020-06-15 16:25:02 +00:00
|
|
|
) | rpl::start_with_next([=](Main::Session *session) {
|
|
|
|
const auto support = session && session->supportMode();
|
|
|
|
Shortcuts::ToggleSupportShortcuts(support);
|
|
|
|
Platform::SetApplicationIcon(Window::CreateIcon(session));
|
|
|
|
}, _lifetime);
|
|
|
|
|
2018-11-16 12:15:14 +00:00
|
|
|
Shortcuts::Requests(
|
|
|
|
) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
|
|
|
|
using Command = Shortcuts::Command;
|
|
|
|
request->check(Command::Quit) && request->handle([] {
|
|
|
|
App::quit();
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
request->check(Command::Lock) && request->handle([=] {
|
|
|
|
if (!passcodeLocked() && Global::LocalPasscode()) {
|
|
|
|
lockByPasscode();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
request->check(Command::Minimize) && request->handle([=] {
|
|
|
|
return minimizeActiveWindow();
|
|
|
|
});
|
|
|
|
request->check(Command::Close) && request->handle([=] {
|
|
|
|
return closeActiveWindow();
|
|
|
|
});
|
|
|
|
}, _lifetime);
|
|
|
|
}
|
2019-01-21 13:42:21 +00:00
|
|
|
|
2019-02-04 13:34:50 +00:00
|
|
|
bool IsAppLaunched() {
|
|
|
|
return (Application::Instance != nullptr);
|
2019-01-21 13:42:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Application &App() {
|
2019-02-04 13:34:50 +00:00
|
|
|
Expects(Application::Instance != nullptr);
|
|
|
|
|
|
|
|
return *Application::Instance;
|
2019-01-21 13:42:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Core
|