Vital
Loading...
Searching...
No Matches
update_check_section.cpp
Go to the documentation of this file.
2
3#include "fonts.h"
4#include "load_save.h"
5
7 checkers_ = 0;
9 checkers_ = 1;
10}
11
13 clearSingletonInstance();
14}
15
16JUCE_IMPLEMENT_SINGLETON(UpdateMemory)
17
18UpdateCheckSection::UpdateCheckSection(String name) : Overlay(name), version_request_(this),
19 body_(Shaders::kRoundedRectangleFragment) {
20 addOpenGlComponent(&body_);
21
22 notify_text_ = std::make_unique<PlainTextComponent>("notify", "There is a new version of Vital!");
23 notify_text_->setTextSize(20.0f);
24 notify_text_->setFontType(PlainTextComponent::kLight);
25 addOpenGlComponent(notify_text_.get());
26
27 version_text_ = std::make_unique<PlainTextComponent>("version", "");
28 version_text_->setTextSize(14.0f);
29 version_text_->setFontType(PlainTextComponent::kLight);
30 addOpenGlComponent(version_text_.get());
31
32 download_button_ = std::make_unique<OpenGlToggleButton>(TRANS("Download"));
33 download_button_->addListener(this);
34 download_button_->setUiButton(true);
35 addAndMakeVisible(download_button_.get());
36 addOpenGlComponent(download_button_->getGlComponent());
37
38 nope_button_ = std::make_unique<OpenGlToggleButton>(TRANS("Ignore"));
39 nope_button_->addListener(this);
40 nope_button_->setUiButton(false);
41 addAndMakeVisible(nope_button_.get());
42 addOpenGlComponent(nope_button_->getGlComponent());
43
44 content_update_ = false;
45}
46
49 body_.setColor(findColour(Skin::kBody, true));
50
51 Colour text_color = findColour(Skin::kBodyText, true);
52 notify_text_->setColor(text_color);
53 version_text_->setColor(text_color);
54
55 Rectangle<int> update_rect = getUpdateCheckRect();
56 body_.setBounds(update_rect);
57
58 int text_width = update_rect.getWidth() - 2 * kPaddingX;
59 int height = 32;
60 notify_text_->setBounds(update_rect.getX() + kPaddingX, update_rect.getY() + kPaddingY, text_width, height);
61 version_text_->setBounds(update_rect.getX() + kPaddingX, update_rect.getY() + kPaddingY + height, text_width, height);
62
63 float button_width = (update_rect.getWidth() - 3 * kPaddingX) / 2.0f;
64 download_button_->setBounds(update_rect.getX() + kPaddingX,
65 update_rect.getBottom() - kPaddingY - kButtonHeight,
66 button_width, kButtonHeight);
67 nope_button_->setBounds(update_rect.getX() + button_width + 2 * kPaddingX,
68 update_rect.getBottom() - kPaddingY - kButtonHeight,
69 button_width, kButtonHeight);
70
72}
73
74void UpdateCheckSection::setVisible(bool should_be_visible) {
75 Overlay::setVisible(should_be_visible);
76
77 if (should_be_visible) {
78 Image image(Image::ARGB, 1, 1, false);
79 Graphics g(image);
81 }
82}
83
84void UpdateCheckSection::updateContent(String version) {
85}
86
88 for (Listener* listener : listeners_)
89 listener->needsUpdate();
90}
91
92void UpdateCheckSection::buttonClicked(Button* clicked_button) {
93 if (clicked_button == download_button_.get()) {
94 if (content_update_)
95 updateContent(content_version_);
96 else
97 URL("").launchInDefaultBrowser();
98 }
99 setVisible(false);
100}
101
102void UpdateCheckSection::mouseUp(const MouseEvent &e) {
103 if (!getUpdateCheckRect().contains(e.getPosition()))
104 setVisible(false);
105}
106
107void UpdateCheckSection::finished(URL::DownloadTask* task, bool success) {
108 if (!success)
109 return;
110
111 StringArray versions;
112 version_file_.readLines(versions);
113 if (versions.size() < 2)
114 return;
115
116 MessageManagerLock lock(&version_request_);
117 if (!lock.lockWasGained())
118 return;
119
120 app_version_ = versions[0];
121 content_version_ = versions[1];
122
123 if (!app_version_.isEmpty() && LoadSave::compareVersionStrings(ProjectInfo::versionString, app_version_) < 0) {
124 version_text_->setText(String("Version: ") + app_version_);
125 needsUpdate();
126 }
127}
128
130 URL version_url("");
131 version_file_ = File::getSpecialLocation(File::tempDirectory).getChildFile("vital_versions.txt");
132 download_task_ = version_url.downloadToFile(version_file_, "", this);
133}
134
136 String content_version = LoadSave::loadContentVersion();
137 if (!content_version_.isEmpty() && LoadSave::compareVersionStrings(content_version, content_version_) < 0) {
138 notify_text_->setText("There is new preset content available");
139 version_text_->setText(String("Version: ") + content_version_);
140 content_update_ = true;
141 needsUpdate();
142 }
143}
144
146 int x = (getWidth() - kUpdateCheckWidth) / 2;
147 int y = (getHeight() - kUpdateCheckHeight) / 2;
148 return Rectangle<int>(x, y, kUpdateCheckWidth, kUpdateCheckHeight);
149}
static String loadContentVersion()
Loads the saved content version string.
Definition load_save.cpp:1638
static bool shouldCheckForUpdates()
Checks if Vital should perform update checks.
Definition load_save.cpp:1554
static int compareVersionStrings(String a, String b)
Compares two version strings.
Definition load_save.cpp:1895
force_inline void setColor(Colour color)
Sets the base color for the quads.
Definition open_gl_multi_quad.h:102
void setRounding(float rounding)
Sets the rounding radius of the quads.
Definition open_gl_multi_quad.h:347
A SynthSection that displays an overlay with a background and optional listeners.
Definition overlay.h:180
virtual void resized() override
Called when the overlay is resized. Updates background color and size.
Definition overlay.h:237
void setVisible(bool should_be_visible) override
Sets the visibility of the overlay and notifies listeners.
Definition overlay.h:224
@ kLight
Definition open_gl_image_component.h:309
Manages and provides access to vertex and fragment shaders used by the OpenGL rendering pipeline.
Definition shaders.h:19
@ kBodyRounding
Definition skin.h:71
@ kBodyText
Definition skin.h:133
@ kBody
Definition skin.h:129
void paintOpenGlChildrenBackgrounds(Graphics &g)
Paints the backgrounds for all OpenGL child components.
Definition synth_section.cpp:267
float findValue(Skin::ValueId value_id) const
Finds a value in the skin overrides or from the parent if not found locally.
Definition synth_section.cpp:18
Interface for components interested in update notifications.
Definition update_check_section.h:96
A UI overlay for checking software or content updates.
Definition update_check_section.h:59
void resized() override
Called when the component is resized. Updates layout of all elements.
Definition update_check_section.cpp:47
static constexpr int kUpdateCheckHeight
Height of the update check dialog.
Definition update_check_section.h:62
void checkUpdate()
Actual method that checks for an update. Usually called from the thread.
Definition update_check_section.cpp:129
static constexpr int kPaddingY
Vertical padding inside the dialog.
Definition update_check_section.h:64
Rectangle< int > getUpdateCheckRect()
Computes the rectangle of the update check dialog within the overlay.
Definition update_check_section.cpp:145
void mouseUp(const MouseEvent &e) override
Closes the overlay if clicked outside the dialog area.
Definition update_check_section.cpp:102
void buttonClicked(Button *clicked_button) override
Handles button clicks.
Definition update_check_section.cpp:92
void checkContentUpdate()
Checks for content updates (e.g., new preset content).
Definition update_check_section.cpp:135
static constexpr int kPaddingX
Horizontal padding inside the dialog.
Definition update_check_section.h:63
static constexpr int kUpdateCheckWidth
Width of the update check dialog.
Definition update_check_section.h:61
void finished(URL::DownloadTask *task, bool success) override
Called when a download task finishes.
Definition update_check_section.cpp:107
static constexpr int kButtonHeight
Height of buttons in the dialog.
Definition update_check_section.h:65
void needsUpdate()
Informs listeners that an update is available.
Definition update_check_section.cpp:87
void setVisible(bool should_be_visible) override
Sets the visibility of the update overlay. When made visible, lays out elements accordingly.
Definition update_check_section.cpp:74
A singleton class that keeps track of whether an update check should be performed.
Definition update_check_section.h:14
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