Vital
Loading...
Searching...
No Matches
update_check_section.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4#include "overlay.h"
5
14class UpdateMemory : public DeletedAtShutdown {
15public:
21
23 virtual ~UpdateMemory();
24
30 ScopedLock lock(lock_);
31 bool should_check = (checkers_ == 0);
32 checkers_++;
33 return should_check;
34 }
35
40 ScopedLock lock(lock_);
41 checkers_--;
42 }
43
44 JUCE_DECLARE_SINGLETON(UpdateMemory, false)
45
46private:
47 CriticalSection lock_;
48 int checkers_;
49};
50
59class UpdateCheckSection : public Overlay, public URL::DownloadTask::Listener {
60public:
61 static constexpr int kUpdateCheckWidth = 340;
62 static constexpr int kUpdateCheckHeight = 160;
63 static constexpr int kPaddingX = 20;
64 static constexpr int kPaddingY = 20;
65 static constexpr int kButtonHeight = 30;
66
73 class VersionRequestThread : public Thread {
74 public:
79 VersionRequestThread(UpdateCheckSection* ref) : Thread("Vital Download Thread"), ref_(ref) { }
80
84 void run() override {
85 ref_->checkUpdate();
86 }
87
88 private:
89 UpdateCheckSection* ref_;
90 };
91
96 class Listener {
97 public:
98 virtual ~Listener() { }
99
103 virtual void needsUpdate() = 0;
104 };
105
110 UpdateCheckSection(String name);
111
116 version_request_.stopThread(350);
117 }
118
122 void resized() override;
123
128 void setVisible(bool should_be_visible) override;
129
133 void needsUpdate();
134
139 void buttonClicked(Button* clicked_button) override;
140
145 void mouseUp(const MouseEvent& e) override;
146
152 void finished(URL::DownloadTask* task, bool success) override;
153
160 void progress(URL::DownloadTask* task, int64 bytesDownloaded, int64 totalLength) override { }
161
165 void startCheck() {
166 version_request_.startThread();
167 }
168
172 void checkUpdate();
173
177 void checkContentUpdate();
178
183 Rectangle<int> getUpdateCheckRect();
184
189 void addListener(Listener* listener) { listeners_.push_back(listener); }
190
191private:
196 void updateContent(String version);
197
198 std::vector<Listener*> listeners_;
199
200 VersionRequestThread version_request_;
201 std::unique_ptr<URL::DownloadTask> download_task_;
202 File version_file_;
203
204 OpenGlQuad body_;
205 std::unique_ptr<PlainTextComponent> notify_text_;
206 std::unique_ptr<PlainTextComponent> version_text_;
207 std::unique_ptr<OpenGlToggleButton> download_button_;
208 std::unique_ptr<OpenGlToggleButton> nope_button_;
209
210 String app_version_;
211 String content_version_;
212 bool content_update_;
213
214 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UpdateCheckSection)
215};
A convenience class for a single quad rendered via OpenGL.
Definition open_gl_multi_quad.h:447
A SynthSection that displays an overlay with a background and optional listeners.
Definition overlay.h:180
Interface for components interested in update notifications.
Definition update_check_section.h:96
virtual void needsUpdate()=0
Called when an update is needed.
virtual ~Listener()
Definition update_check_section.h:98
A thread that requests version information from the server.
Definition update_check_section.h:73
void run() override
Thread entry point. Calls checkUpdate() on the referenced UpdateCheckSection.
Definition update_check_section.h:84
VersionRequestThread(UpdateCheckSection *ref)
Constructs a VersionRequestThread.
Definition update_check_section.h:79
A UI overlay for checking software or content updates.
Definition update_check_section.h:59
void addListener(Listener *listener)
Adds a listener to be notified when updates are available.
Definition update_check_section.h:189
~UpdateCheckSection()
Destructor. Stops the version request thread.
Definition update_check_section.h:115
void progress(URL::DownloadTask *task, int64 bytesDownloaded, int64 totalLength) override
Called periodically to report download progress.
Definition update_check_section.h:160
void startCheck()
Starts the version check by launching the VersionRequestThread.
Definition update_check_section.h:165
A singleton class that keeps track of whether an update check should be performed.
Definition update_check_section.h:14
bool incrementChecker()
Increments the number of components interested in checking for updates.
Definition update_check_section.h:29
void decrementChecker()
Decrements the count of interested update checkers.
Definition update_check_section.h:39
UpdateMemory()
Constructs the UpdateMemory object. Initializes the checker count based on user settings for update c...
Definition update_check_section.cpp:6
virtual ~UpdateMemory()
Destructor.
Definition update_check_section.cpp:12