-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Expand file tree
/
Copy pathapplication.h
More file actions
510 lines (418 loc) · 13.9 KB
/
Copy pathapplication.h
File metadata and controls
510 lines (418 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/timer.h"
#include "mtproto/mtproto_auth_key.h"
#include "mtproto/mtproto_proxy_data.h"
#include "window/window_separate_id.h"
class History;
namespace base {
class BatterySaving;
} // namespace base
namespace Platform {
class Integration;
} // namespace Platform
namespace Storage {
class Databases;
} // namespace Storage
namespace Window {
class Controller;
class SavedWindows;
} // namespace Window
namespace Window::Notifications {
class System;
} // namespace Window::Notifications
namespace ChatHelpers {
class EmojiKeywords;
} // namespace ChatHelpers
namespace Main {
class Domain;
class Account;
class Session;
} // namespace Main
namespace Iv {
class Instance;
class DelegateImpl;
} // namespace Iv
namespace Ui {
namespace Animations {
class Manager;
} // namespace Animations
namespace Emoji {
class UniversalImages;
} // namespace Emoji
class BoxContent;
} // namespace Ui
namespace MTP {
class Config;
class Instance;
class AuthKey;
using AuthKeyPtr = std::shared_ptr<AuthKey>;
using AuthKeysList = std::vector<AuthKeyPtr>;
} // namespace MTP
namespace Media {
namespace Audio {
class Instance;
} // namespace Audio
namespace View {
class OverlayWidget;
struct OpenRequest;
} // namespace View
namespace Player {
class FloatController;
class FloatDelegate;
} // namespace Player
class SystemMediaControlsManager;
} // namespace Media
namespace Lang {
class Instance;
class Translator;
class CloudManager;
} // namespace Lang
namespace Data {
struct CloudTheme;
class DownloadManager;
} // namespace Data
namespace Stickers {
class EmojiImageLoader;
} // namespace Stickers
namespace Export {
class Manager;
} // namespace Export
namespace Calls {
class Instance;
} // namespace Calls
namespace Webrtc {
class Environment;
} // namespace Webrtc
namespace Core {
struct LocalUrlHandler;
class ScreenshotProtection;
class Settings;
class Tray;
enum class LaunchState {
Running,
QuitRequested,
QuitProcessed,
};
enum class QuitReason {
Default,
QtQuitEvent,
};
extern const char kOptionSkipUrlSchemeRegister[];
class Application final : public QObject {
public:
struct ProxyChange {
MTP::ProxyData was;
MTP::ProxyData now;
};
Application();
Application(const Application &other) = delete;
Application &operator=(const Application &other) = delete;
~Application();
void run();
[[nodiscard]] Platform::Integration &platformIntegration() const {
return *_platformIntegration;
}
[[nodiscard]] Ui::Animations::Manager &animationManager() const {
return *_animationsManager;
}
[[nodiscard]] Window::Notifications::System ¬ifications() const {
Expects(_notifications != nullptr);
return *_notifications;
}
[[nodiscard]] Data::DownloadManager &downloadManager() const {
return *_downloadManager;
}
[[nodiscard]] Tray &tray() const {
return *_tray;
}
[[nodiscard]] base::BatterySaving &batterySaving() const {
return *_batterySaving;
}
[[nodiscard]] ScreenshotProtection &screenshotProtection() const {
return *_screenshotProtection;
}
// Windows interface.
bool hasActiveWindow(not_null<Main::Session*> session) const;
[[nodiscard]] bool savingPositionFor(
not_null<Window::Controller*> window) const;
[[nodiscard]] Window::Controller *findWindow(
not_null<QWidget*> widget) const;
[[nodiscard]] Window::Controller *activeWindow() const;
[[nodiscard]] Window::Controller *activePrimaryWindow() const;
void setActivePrimaryWindow(not_null<Window::Controller*> window);
[[nodiscard]] Window::Controller *separateWindowFor(
Window::SeparateId id) const;
Window::Controller *ensureSeparateWindowFor(
Window::SeparateId id,
MsgId showAtMsgId = 0);
[[nodiscard]] Window::Controller *windowFor( // Doesn't auto-switch.
Window::SeparateId id) const;
[[nodiscard]] Window::Controller *windowForShowingHistory(
not_null<PeerData*> peer) const;
[[nodiscard]] Window::Controller *windowForShowingForum(
not_null<Data::Forum*> forum) const;
[[nodiscard]] bool closeNonLastAsync(
not_null<Window::Controller*> window);
void closeWindow(not_null<Window::Controller*> window);
void windowActivated(not_null<Window::Controller*> window);
bool closeActiveWindow();
bool closeOtherWindows();
bool minimizeActiveWindow();
bool toggleActiveWindowFullScreen();
[[nodiscard]] QWidget *getFileDialogParent();
void notifyFileDialogShown(bool shown);
void checkSystemDarkMode();
[[nodiscard]] bool isActiveForTrayMenu() const;
void closeChatFromWindows(not_null<PeerData*> peer);
void checkWindowId(not_null<Window::Controller*> window);
void activate();
[[nodiscard]] Window::SavedWindows *savedWindows() const {
return _savedWindows.get();
}
[[nodiscard]] auto windowStack() const
-> const std::vector<not_null<Window::Controller*>> & {
return _windowStack;
}
void enumerateWindows(
Fn<void(not_null<Window::Controller*>)> callback) const;
// Media view interface.
bool hideMediaView();
[[nodiscard]] QPoint getPointForCallPanelCenter() const;
[[nodiscard]] bool isSharingScreen() const;
void startSettingsAndBackground();
[[nodiscard]] Settings &settings();
[[nodiscard]] const Settings &settings() const;
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
void saveSettings();
[[nodiscard]] bool canReadDefaultDownloadPath() const;
[[nodiscard]] bool canSaveFileWithoutAskingForPath() const;
// Fallback config and proxy.
[[nodiscard]] MTP::Config &fallbackProductionConfig() const;
void refreshFallbackProductionConfig(const MTP::Config &config);
void constructFallbackProductionConfig(const QByteArray &serialized);
void setCurrentProxy(
const MTP::ProxyData &proxy,
MTP::ProxyData::Settings settings);
void proxyRotationSettingsChanged();
void checkProxyRotation(not_null<Main::Account*> account, int32 state);
[[nodiscard]] rpl::producer<ProxyChange> proxyChanges() const;
void badMtprotoConfigurationError();
// Databases.
[[nodiscard]] Storage::Databases &databases() {
return *_databases;
}
// Domain component.
[[nodiscard]] Main::Domain &domain() const {
return *_domain;
}
[[nodiscard]] Main::Account &activeAccount() const;
[[nodiscard]] bool someSessionExists() const;
[[nodiscard]] Export::Manager &exportManager() const {
return *_exportManager;
}
[[nodiscard]] bool exportPreventsQuit();
// Main::Session component.
Main::Session *maybePrimarySession() const;
[[nodiscard]] int unreadBadge() const;
[[nodiscard]] bool unreadBadgeMuted() const;
[[nodiscard]] rpl::producer<> unreadBadgeChanges() const;
// Media component.
[[nodiscard]] Media::Audio::Instance &audio() {
return *_audio;
}
[[nodiscard]] Webrtc::Environment &mediaDevices() {
return *_mediaDevices;
}
// Langpack and emoji keywords.
[[nodiscard]] Lang::Instance &langpack() {
return *_langpack;
}
[[nodiscard]] Lang::CloudManager *langCloudManager() {
return _langCloudManager.get();
}
[[nodiscard]] bool offerLegacyLangPackSwitch() const;
[[nodiscard]] bool canApplyLangPackWithoutRestart() const;
[[nodiscard]] ChatHelpers::EmojiKeywords &emojiKeywords() {
return *_emojiKeywords;
}
[[nodiscard]] auto emojiImageLoader() const
-> const crl::object_on_queue<Stickers::EmojiImageLoader> & {
return _emojiImageLoader;
}
// Internal links.
void checkStartUrls();
bool openLocalUrl(const QString &url, QVariant context);
bool openInternalUrl(const QString &url, QVariant context);
[[nodiscard]] QString changelogLink() const;
// Float player.
void floatPlayerToggleGifsPaused(bool paused);
[[nodiscard]] rpl::producer<FullMsgId> floatPlayerClosed() const;
// Calls.
Calls::Instance &calls() const {
return *_calls;
}
// Iv.
Iv::Instance &iv() const {
return *_iv;
}
void logout(Main::Account *account = nullptr);
void logoutWithChecks(Main::Account *account);
void forceLogOut(
not_null<Main::Account*> account,
const TextWithEntities &explanation);
[[nodiscard]] bool uploadPreventsQuit();
[[nodiscard]] bool downloadPreventsQuit();
void checkLocalTime();
void lockByPasscode();
void maybeLockByPasscode();
void unlockPasscode();
[[nodiscard]] bool passcodeLocked() const;
rpl::producer<bool> passcodeLockChanges() const;
rpl::producer<bool> passcodeLockValue() const;
void lockBySetupEmail();
void unlockSetupEmail();
void checkAutoLock(crl::time lastNonIdleTime = 0);
void checkAutoLockIn(crl::time time);
void localPasscodeChanged();
[[nodiscard]] bool preventsQuit(QuitReason reason);
[[nodiscard]] crl::time lastNonIdleTime() const;
void updateNonIdle();
void registerLeaveSubscription(not_null<QWidget*> widget);
void unregisterLeaveSubscription(not_null<QWidget*> widget);
// Sandbox interface.
void postponeCall(FnMut<void()> &&callable);
void refreshGlobalProxy();
void refreshApplicationIcon();
void quitPreventFinished();
void handleAppActivated();
void handleAppDeactivated();
[[nodiscard]] rpl::producer<bool> appDeactivatedValue() const;
[[nodiscard]] rpl::producer<> inAppKeyPressed() const;
void materializeLocalDrafts();
[[nodiscard]] rpl::producer<> materializeLocalDraftsRequests() const;
void switchDebugMode();
void preventOrInvoke(Fn<void()> &&callback);
// Global runtime variables.
void setScreenIsLocked(bool locked);
bool screenIsLocked() const;
static void RegisterUrlScheme();
protected:
bool eventFilter(QObject *object, QEvent *event) override;
private:
static constexpr auto kDefaultSaveDelay = crl::time(1000);
friend bool IsAppLaunched();
friend Application &App();
void autoRegisterUrlScheme();
void clearEmojiSourceImages();
[[nodiscard]] auto prepareEmojiSourceImages()
-> std::shared_ptr<Ui::Emoji::UniversalImages>;
void startLocalStorage();
void startShortcuts();
void startDomain();
void startEmojiImageLoader();
void startSystemDarkModeViewer();
void startMediaView();
void startTray();
void createTray();
void updateWindowTitles();
void setLastActiveWindow(Window::Controller *window);
void showAccount(not_null<Main::Account*> account);
void processCreatedWindow(not_null<Window::Controller*> window);
void refreshApplicationIcon(Main::Session *session);
friend void QuitAttempt();
void quitDelayed();
[[nodiscard]] bool readyToQuit();
void showOpenGLCrashNotification();
void clearPasscodeLock();
void closeAdditionalWindows();
bool openCustomUrl(
const QString &protocol,
const std::vector<LocalUrlHandler> &handlers,
const QString &url,
const QVariant &context);
static Application *Instance;
struct InstanceSetter {
InstanceSetter(not_null<Application*> instance) {
Expects(Instance == nullptr);
Instance = instance;
}
};
InstanceSetter _setter = { this };
rpl::event_stream<ProxyChange> _proxyChanges;
// Some fields are just moved from the declaration.
struct Private;
const std::unique_ptr<Private> _private;
const std::unique_ptr<Platform::Integration> _platformIntegration;
const std::unique_ptr<base::BatterySaving> _batterySaving;
const std::unique_ptr<Webrtc::Environment> _mediaDevices;
const std::unique_ptr<ScreenshotProtection> _screenshotProtection;
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;
const std::unique_ptr<Media::Audio::Instance> _audio;
mutable std::unique_ptr<MTP::Config> _fallbackProductionConfig;
// Notifications should be destroyed before _audio, after _domain.
// Mutable because is created in run() after OpenSSL is inited.
std::unique_ptr<Window::Notifications::System> _notifications;
using MediaControlsManager = Media::SystemMediaControlsManager;
std::unique_ptr<MediaControlsManager> _mediaControlsManager;
const std::unique_ptr<Data::DownloadManager> _downloadManager;
const std::unique_ptr<Main::Domain> _domain;
const std::unique_ptr<Export::Manager> _exportManager;
const std::unique_ptr<Calls::Instance> _calls;
const std::unique_ptr<Iv::Instance> _iv;
base::flat_map<
Window::SeparateId,
std::unique_ptr<Window::Controller>> _windows;
base::flat_set<not_null<Window::Controller*>> _closingAsyncWindows;
std::vector<not_null<Window::Controller*>> _windowStack;
Window::Controller *_lastActiveWindow = nullptr;
Window::Controller *_lastActivePrimaryWindow = nullptr;
Window::Controller *_windowInSettings = nullptr;
std::unique_ptr<Window::SavedWindows> _savedWindows;
bool _lastMouseIgnored = false;
bool _lastTouchProcessed = false;
std::unique_ptr<Media::View::OverlayWidget> _mediaView;
const std::unique_ptr<Lang::Instance> _langpack;
const std::unique_ptr<Lang::CloudManager> _langCloudManager;
const std::unique_ptr<ChatHelpers::EmojiKeywords> _emojiKeywords;
std::unique_ptr<Lang::Translator> _translator;
base::weak_qptr<Ui::BoxContent> _badProxyDisableBox;
base::weak_qptr<Ui::BoxContent> _webProxyFallbackBox;
const std::unique_ptr<Tray> _tray;
std::unique_ptr<Media::Player::FloatController> _floatPlayers;
rpl::lifetime _floatPlayerDelegateLifetime;
bool _floatPlayerGifsPaused = false;
rpl::variable<bool> _passcodeLock;
rpl::variable<bool> _setupEmailLock;
bool _screenIsLocked = false;
crl::time _shouldLockAt = 0;
base::Timer _autoLockTimer;
QList<QUrl> _urlsToOpen;
std::optional<base::Timer> _saveSettingsTimer;
struct LeaveFilter {
std::vector<QPointer<QWidget>> registered;
QPointer<QObject> filter;
};
base::flat_map<not_null<QWidget*>, LeaveFilter> _leaveFilters;
rpl::event_stream<Media::View::OpenRequest> _openInMediaViewRequests;
rpl::event_stream<> _inAppKeyPressed;
rpl::event_stream<> _materializeLocalDraftsRequests;
rpl::lifetime _lifetime;
crl::time _lastNonIdleTime = 0;
};
[[nodiscard]] bool IsAppLaunched();
[[nodiscard]] Application &App();
[[nodiscard]] LaunchState CurrentLaunchState();
void SetLaunchState(LaunchState state);
void Quit(QuitReason reason = QuitReason::Default);
[[nodiscard]] bool Quitting();
void Restart();
} // namespace Core