1 | // Aseprite |
2 | // Copyright (C) 2020 Igara Studio S.A. |
3 | // Copyright (C) 2001-2018 David Capello |
4 | // |
5 | // This program is distributed under the terms of |
6 | // the End-User License Agreement for Aseprite. |
7 | |
8 | #ifndef APP_CHECK_UPDATE_H_INCLUDED |
9 | #define APP_CHECK_UPDATE_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #ifdef ENABLE_UPDATER |
13 | |
14 | #include "base/thread.h" |
15 | #include "ui/timer.h" |
16 | #include "updater/check_update.h" |
17 | |
18 | #include <atomic> |
19 | #include <memory> |
20 | |
21 | namespace app { |
22 | |
23 | class CheckUpdateDelegate; |
24 | class CheckUpdateBackgroundJob; |
25 | class Preferences; |
26 | |
27 | class CheckUpdateThreadLauncher { |
28 | public: |
29 | CheckUpdateThreadLauncher(CheckUpdateDelegate* delegate); |
30 | ~CheckUpdateThreadLauncher(); |
31 | |
32 | void launch(); |
33 | |
34 | bool isReceived() const; |
35 | |
36 | const updater::CheckUpdateResponse& getResponse() const |
37 | { |
38 | return m_response; |
39 | } |
40 | |
41 | private: |
42 | void onMonitoringTick(); |
43 | void checkForUpdates(); |
44 | void showUI(); |
45 | |
46 | CheckUpdateDelegate* m_delegate; |
47 | Preferences& m_preferences; |
48 | updater::Uuid m_uuid; |
49 | std::unique_ptr<base::thread> m_thread; |
50 | std::unique_ptr<CheckUpdateBackgroundJob> m_bgJob; |
51 | bool m_doCheck; |
52 | std::atomic<bool> m_received; |
53 | |
54 | // Mini-stats |
55 | int m_inits; |
56 | int m_exits; |
57 | |
58 | // True if this is a developer |
59 | bool m_isDeveloper; |
60 | |
61 | updater::CheckUpdateResponse m_response; |
62 | ui::Timer m_timer; |
63 | }; |
64 | |
65 | } // namespace app |
66 | |
67 | #endif // ENABLE_UPDATER |
68 | |
69 | #endif // APP_CHECK_UPDATE_H_INCLUDED |
70 | |