Browse Source

Delete unused vitalium files (download, auth, login, etc)

Signed-off-by: falkTX <falktx@falktx.com>
tags/2021-03-15
falkTX 3 years ago
parent
commit
578dbcfcd6
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
6 changed files with 0 additions and 1386 deletions
  1. +0
    -355
      ports/vitalium/source/interface/editor_sections/authentication_section.cpp
  2. +0
    -199
      ports/vitalium/source/interface/editor_sections/authentication_section.h
  3. +0
    -405
      ports/vitalium/source/interface/editor_sections/download_section.cpp
  4. +0
    -147
      ports/vitalium/source/interface/editor_sections/download_section.h
  5. +0
    -165
      ports/vitalium/source/interface/editor_sections/update_check_section.cpp
  6. +0
    -115
      ports/vitalium/source/interface/editor_sections/update_check_section.h

+ 0
- 355
ports/vitalium/source/interface/editor_sections/authentication_section.cpp View File

@@ -1,355 +0,0 @@
/* Copyright 2013-2019 Matt Tytel
*
* vital is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* vital is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with vital. If not, see <http://www.gnu.org/licenses/>.
*/

#include "authentication_section.h"

#include "authentication.h"
#include "load_save.h"
#include "fonts.h"
#include "skin.h"

#if NDEBUG && !NO_AUTH

namespace {
constexpr int kMsAuthPoll = 1000;

void onTokenResult(const firebase::Future<std::string>& completed_future, void* ref_data) {
const MessageManagerLock lock(Thread::getCurrentThread());
if (!lock.lockWasGained())
return;
Component::SafePointer<AuthenticationSection>* reference = (Component::SafePointer<AuthenticationSection>*)ref_data;
if (completed_future.status() != firebase::kFutureStatusComplete) {
LoadSave::writeErrorLog("Firebase getting initial token error: not complete");
delete reference;
return;
}
if (completed_future.error()) {
std::string error = "Firebase getting initial token error: error code ";
LoadSave::writeErrorLog(error + std::to_string(completed_future.error()));
delete reference;
return;
}

if (reference->getComponent()) {
reference->getComponent()->auth()->setToken(*completed_future.result());
reference->getComponent()->notifyLoggedIn();
}

delete reference;
}

void onLoginResult(const firebase::Future<firebase::auth::User*>& completed_future, void* ref_data) {
const MessageManagerLock lock(Thread::getCurrentThread());
if (!lock.lockWasGained())
return;
Component::SafePointer<AuthenticationSection>* reference = (Component::SafePointer<AuthenticationSection>*)ref_data;
if (completed_future.status() != firebase::kFutureStatusComplete) {
LoadSave::writeErrorLog("Firebase login error: not complete");
delete reference;
return;
}
if (completed_future.error()) {
std::string error = "Firebase login error: error code ";
LoadSave::writeErrorLog(error + std::to_string(completed_future.error()));
delete reference;
return;
}

if (reference->getComponent()) {
if (completed_future.error())
reference->getComponent()->setError(completed_future.error_message());
else {
firebase::Future<std::string> future = (*completed_future.result())->GetToken(false);
Component::SafePointer<AuthenticationSection>* ref =
new Component::SafePointer<AuthenticationSection>(reference->getComponent());
future.OnCompletion(onTokenResult, ref);

LoadSave::saveAuthenticated(true);
reference->getComponent()->finishLogin();
}

reference->getComponent()->setButtonSettings(true, "Sign in");
}

delete reference;
}
}

void AuthInitThread::run() {
ref_->createAuth();
}

AuthenticationSection::AuthenticationSection(Authentication* auth) : Overlay("Auth"), auth_(auth),
body_(Shaders::kRoundedRectangleFragment) {
addOpenGlComponent(&body_);

logo_ = std::make_unique<AppLogo>("logo");
addOpenGlComponent(logo_.get());
sign_in_text_ = std::make_unique<PlainTextComponent>("Sign in", "Sign in");
addOpenGlComponent(sign_in_text_.get());
sign_in_text_->setFontType(PlainTextComponent::kLight);
sign_in_text_->setTextSize(kTextHeight * size_ratio_ * 0.6f);
sign_in_text_->setJustification(Justification::centred);

error_text_ = std::make_unique<PlainTextComponent>("Error", "");
addOpenGlComponent(error_text_.get());
error_text_->setFontType(PlainTextComponent::kLight);
error_text_->setTextSize(kTextHeight * size_ratio_ * 0.4f);
error_text_->setJustification(Justification::centredRight);

#if !defined(NO_TEXT_ENTRY)
email_ = std::make_unique<OpenGlTextEditor>("Email");
email_->addListener(this);
addAndMakeVisible(email_.get());
addOpenGlComponent(email_->getImageComponent());
password_ = std::make_unique<OpenGlTextEditor>("Password", 0x2022);
password_->addListener(this);
addAndMakeVisible(password_.get());
addOpenGlComponent(password_->getImageComponent());
#endif
sign_in_button_ = std::make_unique<OpenGlToggleButton>("Sign in");
sign_in_button_->setText("Sign in");
sign_in_button_->setUiButton(true);
sign_in_button_->addListener(this);
addAndMakeVisible(sign_in_button_.get());
addOpenGlComponent(sign_in_button_->getGlComponent());

forgot_password_ = std::make_unique<ForgotPasswordLink>();
addOpenGlComponent(forgot_password_.get());
forgot_password_->setFontType(PlainTextComponent::kLight);
forgot_password_->setTextSize(kTextHeight * size_ratio_ * 0.4f);
forgot_password_->setJustification(Justification::centredLeft);

work_offline_ = std::make_unique<WorkOffline>();
work_offline_->addListener(this);
addOpenGlComponent(work_offline_.get());
work_offline_->setFontType(PlainTextComponent::kLight);
work_offline_->setTextSize(kTextHeight * size_ratio_ * 0.4f);
work_offline_->setJustification(Justification::centredRight);

setWantsKeyboardFocus(true);
setSkinOverride(Skin::kOverlay);
}

AuthenticationSection::~AuthenticationSection() = default;

void AuthenticationSection::init() {
if (firebase::App::GetInstance() == nullptr) {
startTimer(kMsAuthPoll);
return;
}
}

void AuthenticationSection::create() {
Authentication::create();
createAuth();
// TODO: Putting this on background thread hangs sometimes.
// auth_init_thread_ = std::make_unique<AuthInitThread>(this);
// auth_init_thread_->startThread();
}

void AuthenticationSection::createAuth() {
auth_->init();
checkAuth();
}

void AuthenticationSection::checkAuth() {
if (!auth_->hasAuth())
return;

firebase::auth::User* user = auth_->auth()->current_user();
if (user) {
firebase::Future<std::string> future = user->GetToken(true);
SafePointer<AuthenticationSection>* self_reference = new SafePointer<AuthenticationSection>(this);
future.OnCompletion(onTokenResult, self_reference);
}
const MessageManagerLock lock(Thread::getCurrentThread());
if (!lock.lockWasGained())
return;
setVisible(user == nullptr);
if (user) {
signed_in_email_ = user->email();
LoadSave::saveAuthenticated(true);
}
else
startTimer(kMsAuthPoll);
}

void AuthenticationSection::timerCallback() {
if (!auth_->hasAuth())
init();
else if (isVisible())
checkAuth();
else
stopTimer();
}

void AuthenticationSection::mouseUp(const MouseEvent &e) {
if (!body_.getBounds().contains(e.getPosition()))
setVisible(false);
}

void AuthenticationSection::resized() {
Overlay::resized();

Path border;

int width = kWidth * size_ratio_;
int height = kHeight * size_ratio_;
int top = kY * size_ratio_;
int padding = kPadding * size_ratio_;
int logo_width = kImageWidth * size_ratio_;
int text_height = kTextHeight * size_ratio_;

int text_width = width - 2 * padding;
int text_x = (getWidth() - text_width) / 2;
int error_height = text_height * 0.5;
int y = top + height - 2 * padding - 4 * text_height - error_height;
if (email_ && password_) {
Colour caret = findColour(Skin::kTextEditorCaret, true);
Colour body_text = findColour(Skin::kTextEditorCaret, true);
Colour selection = findColour(Skin::kTextEditorSelection, true);
Colour empty_color = body_text.withMultipliedAlpha(0.5f);
email_->setTextToShowWhenEmpty(TRANS("Email"), empty_color);
password_->setTextToShowWhenEmpty(TRANS("Password"), empty_color);
email_->setColour(CaretComponent::caretColourId, caret);
email_->setColour(TextEditor::textColourId, body_text);
email_->setColour(TextEditor::highlightedTextColourId, body_text);
email_->setColour(TextEditor::highlightColourId, selection);
password_->setColour(CaretComponent::caretColourId, caret);
password_->setColour(TextEditor::textColourId, body_text);
password_->setColour(TextEditor::highlightedTextColourId, body_text);
password_->setColour(TextEditor::highlightColourId, selection);
email_->setBounds(text_x, y, text_width, text_height);
password_->setBounds(text_x, y + 1.25f * text_height, text_width, text_height);
}

int image_x = (getWidth() - logo_width) / 2;
int image_y = top + padding;
logo_->setBounds(image_x, image_y, logo_width, logo_width);
Colour text_color = findColour(Skin::kBodyText, true);
sign_in_text_->setColor(text_color);
sign_in_text_->setBounds(text_x, image_y + logo_width, text_width, text_height);
sign_in_text_->setTextSize(kTextHeight * size_ratio_ * 0.6f);
sign_in_button_->setBounds(text_x, y + 3 * text_height + error_height + padding, text_width, text_height);

forgot_password_->setColor(findColour(Skin::kWidgetAccent1, true));
forgot_password_->setBounds(password_->getX(), password_->getBottom(), password_->getWidth() / 2, text_height);
forgot_password_->setTextSize(kTextHeight * size_ratio_ * 0.4f);

work_offline_->setColor(findColour(Skin::kWidgetAccent1, true));
work_offline_->setBounds(forgot_password_->getRight(), forgot_password_->getY(),
password_->getRight() - forgot_password_->getRight(), text_height);
work_offline_->setTextSize(kTextHeight * size_ratio_ * 0.4f);

error_text_->setColor(text_color.interpolatedWith(Colours::red, 0.5f));
error_text_->setBounds(password_->getX(), forgot_password_->getBottom(), password_->getWidth(), error_height);
error_text_->setTextSize(kTextHeight * size_ratio_ * 0.4f);

body_.setBounds((getWidth() - width) / 2, top, width, height);
body_.setRounding(findValue(Skin::kBodyRounding));
body_.setColor(findColour(Skin::kBody, true));

if (isVisible()) {
Image image(Image::ARGB, 1, 1, false);
Graphics g(image);
paintOpenGlChildrenBackgrounds(g);
}
}

void AuthenticationSection::setVisible(bool should_be_visible) {
Overlay::setVisible(should_be_visible);

if (should_be_visible) {
Image image(Image::ARGB, 1, 1, false);
Graphics g(image);
paintOpenGlChildrenBackgrounds(g);
}
}

void AuthenticationSection::visibilityChanged() {
Component::visibilityChanged();
if (isShowing() && email_ && email_->isEmpty())
email_->grabKeyboardFocus();
Image image(Image::ARGB, 1, 1, false);
Graphics g(image);
paintOpenGlChildrenBackgrounds(g);
}

void AuthenticationSection::workOffline() {
setVisible(false);
LoadSave::saveWorkOffline(true);
}

void AuthenticationSection::signOut() {
auth_->auth()->SignOut();
setVisible(true);
startTimer(kMsAuthPoll);
}

void AuthenticationSection::notifyLoggedIn() {
for (Listener* listener : listeners_)
listener->loggedIn();
}

void AuthenticationSection::setFocus() {
if (isShowing() && email_ && email_->isEmpty())
email_->grabKeyboardFocus();
}

void AuthenticationSection::finishLogin() {
setVisible(false);
for (Listener* listener : listeners_)
listener->loggedIn();
}

void AuthenticationSection::tryLogin() {
LoadSave::saveWorkOffline(false);

if (!auth_->hasAuth()) {
setVisible(false);
return;
}

setError("");
setButtonSettings(false, "Signing in...");
signed_in_email_ = email_->getText().toStdString();
std::string password = password_->getText().toStdString();
firebase::Future<firebase::auth::User*> future =
auth_->auth()->SignInWithEmailAndPassword(signed_in_email_.c_str(), password.c_str());

SafePointer<AuthenticationSection>* self_reference = new SafePointer<AuthenticationSection>(this);
future.OnCompletion(onLoginResult, self_reference);
}

#endif

+ 0
- 199
ports/vitalium/source/interface/editor_sections/authentication_section.h View File

@@ -1,199 +0,0 @@
/* Copyright 2013-2019 Matt Tytel
*
* vital is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* vital is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with vital. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#if NDEBUG && !NO_AUTH

#include "JuceHeader.h"

#include "authentication.h"
#include "synth_button.h"
#include "overlay.h"
#include "open_gl_image_component.h"
#include "open_gl_multi_quad.h"

class AuthenticationSection;

class ForgotPasswordLink : public PlainTextComponent {
public:
ForgotPasswordLink() : PlainTextComponent("Forgot password?", "Forgot password?") {
setInterceptsMouseClicks(true, false);
}

void mouseEnter(const MouseEvent& e) override {
setColor(findColour(Skin::kWidgetAccent1, true).brighter(1.0f));
}

void mouseExit(const MouseEvent& e) override {
setColor(findColour(Skin::kWidgetAccent1, true));
}

void mouseDown(const MouseEvent& e) override {
URL url("");
url.launchInDefaultBrowser();
}
};

class AuthInitThread : public Thread {
public:
AuthInitThread(AuthenticationSection* ref) : Thread("Vial Auth Init Thread"), ref_(ref) { }
virtual ~AuthInitThread() { }

void run() override;

private:
AuthenticationSection* ref_;
};

class WorkOffline : public PlainTextComponent {
public:
class Listener {
public:
virtual ~Listener() = default;
virtual void workOffline() = 0;
};

WorkOffline() : PlainTextComponent("Work offline", "Work offline") {
setInterceptsMouseClicks(true, false);
}

void mouseEnter(const MouseEvent& e) override {
setColor(findColour(Skin::kWidgetAccent1, true).brighter(1.0f));
}

void mouseExit(const MouseEvent& e) override {
setColor(findColour(Skin::kWidgetAccent1, true));
}

void mouseDown(const MouseEvent& e) override {
for (Listener* listener: listeners_)
listener->workOffline();
}

void addListener(Listener* listener) {
listeners_.push_back(listener);
}

private:
std::vector<Listener*> listeners_;
};

class AuthenticationSection : public Overlay, public TextEditor::Listener, public WorkOffline::Listener, public Timer {
public:
static constexpr int kWidth = 450;
static constexpr int kHeight = 398;
static constexpr int kY = 180;
static constexpr int kPadding = 20;
static constexpr int kTextHeight = 36;
static constexpr int kImageWidth = 128;

class Listener {
public:
virtual ~Listener() = default;
virtual void loggedIn() = 0;
};

AuthenticationSection(Authentication* auth);
virtual ~AuthenticationSection();

void init();
void createAuth();
void create();
void checkAuth();
Authentication* auth() { return auth_; }
void timerCallback() override;
void mouseUp(const MouseEvent& e) override;

void paintBackground(Graphics& g) override { }
void resized() override;
void setVisible(bool should_be_visible) override;
void visibilityChanged() override;
void notifyLoggedIn();
void textEditorReturnKeyPressed(TextEditor& editor) override {
tryLogin();
}
void buttonClicked(Button* clicked_button) override {
tryLogin();
}

std::string getSignedInName() {
return signed_in_email_;
}

std::string getEmail() {
return signed_in_email_;
}

void workOffline() override;
void signOut();
void setFocus();
void setError(const std::string& error) { error_text_->setText(error); }
void setButtonSettings(bool enabled, const std::string& text) {
sign_in_button_->setEnabled(enabled);
sign_in_button_->setText(text);
}
void addListener(Listener* listener) { listeners_.push_back(listener); }
void finishLogin();

private:
void tryLogin();
Authentication* auth_;
std::vector<Listener*> listeners_;

std::string signed_in_email_;
OpenGlQuad body_;

std::unique_ptr<AppLogo> logo_;
std::unique_ptr<PlainTextComponent> sign_in_text_;
std::unique_ptr<PlainTextComponent> error_text_;
std::unique_ptr<OpenGlTextEditor> email_;
std::unique_ptr<OpenGlTextEditor> password_;
std::unique_ptr<OpenGlToggleButton> sign_in_button_;
std::unique_ptr<ForgotPasswordLink> forgot_password_;
std::unique_ptr<WorkOffline> work_offline_;
std::unique_ptr<AuthInitThread> auth_init_thread_;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AuthenticationSection)
};

#else

class AuthenticationSection : public Component {
public:
class Listener {
public:
virtual ~Listener() = default;
virtual void loggedIn() = 0;
};

AuthenticationSection(Authentication* auth) { }

std::string getSignedInName() { return ""; }
void signOut() { }
void create() { }
void setFocus() { }
void addListener(Listener* listener) { }

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AuthenticationSection)
};

#endif

+ 0
- 405
ports/vitalium/source/interface/editor_sections/download_section.cpp View File

@@ -1,405 +0,0 @@
/* Copyright 2013-2019 Matt Tytel
*
* vital is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* vital is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with vital. If not, see <http://www.gnu.org/licenses/>.
*/

#include "download_section.h"
#include "load_save.h"
#include "update_check_section.h"

#include "skin.h"
#include "fonts.h"

namespace {
const std::string kDownloadUrlPrefix = "";
const std::string kPacksUrlPrefix = "";
const std::string kTokenUrlQuery = "?idToken=";
}

DownloadSection::DownloadSection(String name, Authentication* auth) :
Overlay(std::move(name)), auth_(auth),
body_(Shaders::kRoundedRectangleFragment),
download_progress_(Shaders::kColorFragment),
download_background_(Shaders::kColorFragment),
install_text_background_(Shaders::kRoundedRectangleFragment),
install_thread_(this) {

cancel_ = false;
initial_download_ = !LoadSave::hasDataDirectory();
progress_value_ = 0.0f;

addOpenGlComponent(&body_);
addOpenGlComponent(&download_background_);
addOpenGlComponent(&install_text_background_);
download_progress_.addRoundedCorners();
addOpenGlComponent(&download_progress_);

logo_ = std::make_unique<AppLogo>("logo");
addOpenGlComponent(logo_.get());

loading_wheel_ = std::make_unique<LoadingWheel>();
addOpenGlComponent(loading_wheel_.get());

install_button_ = std::make_unique<OpenGlToggleButton>("Install");
install_button_->setText("Install");
install_button_->setUiButton(true);
install_button_->addListener(this);
install_button_->setEnabled(false);
addAndMakeVisible(install_button_.get());
addOpenGlComponent(install_button_->getGlComponent());

cancel_button_ = std::make_unique<OpenGlToggleButton>("Cancel");
cancel_button_->setText("Cancel");
cancel_button_->setUiButton(false);
cancel_button_->addListener(this);
addAndMakeVisible(cancel_button_.get());
addOpenGlComponent(cancel_button_->getGlComponent());

download_text_ = std::make_unique<PlainTextComponent>("Download", "Downloading factory content...");
addOpenGlComponent(download_text_.get());
download_text_->setFontType(PlainTextComponent::kLight);
download_text_->setTextSize(kTextHeight);
download_text_->setJustification(Justification::centred);

install_location_ = LoadSave::getDataDirectory();
install_location_text_ = std::make_unique<PlainTextComponent>("Location", install_location_.getFullPathName());
addOpenGlComponent(install_location_text_.get());
install_location_text_->setFontType(PlainTextComponent::kLight);
install_location_text_->setTextSize(kTextHeight);
install_location_text_->setJustification(Justification::centredLeft);

folder_button_ = std::make_unique<OpenGlShapeButton>("Folder");
addAndMakeVisible(folder_button_.get());
addOpenGlComponent(folder_button_->getGlComponent());
#if !defined(NO_TEXT_ENTRY)
folder_button_->addListener(this);
#endif
folder_button_->setTriggeredOnMouseDown(true);
folder_button_->setShape(Paths::folder());

available_packs_location_ = File::getSpecialLocation(File::tempDirectory).getChildFile("available_packs.json");
}

void DownloadSection::resized() {
static constexpr int kLogoWidth = 128;
static constexpr int kDownloadHeight = 8;
static constexpr float kRingThicknessRatio = 0.03f;
static constexpr float kRingMarginRatio = 0.03f;
Overlay::resized();

body_.setRounding(findValue(Skin::kBodyRounding));
Colour background = findColour(Skin::kBackground, true);
download_background_.setColor(background);
install_text_background_.setColor(background);
install_text_background_.setRounding(findValue(Skin::kWidgetRoundedCorner));
download_progress_.setColor(findColour(Skin::kWidgetPrimary1, true));

body_.setColor(findColour(Skin::kBody, true));

Rectangle<int> download_rect = getDownloadRect();
body_.setBounds(download_rect);

int logo_width = size_ratio_ * kLogoWidth;
int padding_x = size_ratio_ * kPaddingX;
int padding_y = size_ratio_ * kPaddingY;
int button_height = size_ratio_ * kButtonHeight;

int logo_x = (getWidth() - logo_width) / 2;
int logo_y = download_rect.getY() + padding_y;
logo_->setBounds(logo_x, logo_y, logo_width, logo_width);

int wheel_margin = logo_width * kRingMarginRatio;
loading_wheel_->setBounds(logo_->getX() - wheel_margin, logo_->getY() - wheel_margin,
logo_->getWidth() + 2 * wheel_margin, logo_->getHeight() + 2 * wheel_margin);
loading_wheel_->setThickness(logo_width * kRingThicknessRatio);

float button_width = (download_rect.getWidth() - 3 * padding_x) / 2;
install_button_->setBounds(download_rect.getX() + padding_x,
download_rect.getBottom() - padding_y - button_height,
button_width, button_height);
cancel_button_->setBounds(install_button_->getRight() + padding_x, install_button_->getY(),
download_rect.getRight() - 2 * padding_x - install_button_->getRight(), button_height);

float text_size = kTextHeight * size_ratio_;
download_text_->setTextSize(text_size);
float text_height = 22.0f * size_ratio_;
download_text_->setBounds(download_rect.getX() + padding_x, logo_y + logo_width + padding_y,
download_rect.getWidth() - 2 * padding_x, text_height);
int download_height = size_ratio_ * kDownloadHeight;
int download_y = (download_text_->getBottom() + install_button_->getY() -
download_height + text_size - text_height) / 2;
if (initial_download_) {
folder_button_->setBounds(install_button_->getX(), install_button_->getY() - padding_y - button_height,
button_height, button_height);
download_y = (download_text_->getBottom() + folder_button_->getY() - download_height + text_size - text_height) / 2;

install_location_text_->setTextSize(text_size);
int install_background_x = folder_button_->getRight() + text_height / 2;
int install_text_x = folder_button_->getRight() + text_height;
install_location_text_->setBounds(install_text_x, folder_button_->getY(),
download_rect.getRight() - padding_x - install_text_x, button_height);
install_text_background_.setBounds(install_background_x, folder_button_->getY(),
download_rect.getRight() - padding_x - install_background_x, button_height);
}

download_progress_.setBounds(install_button_->getX(), download_y,
download_rect.getWidth() - 2 * padding_x, download_height);
download_background_.setBounds(download_progress_.getBounds());
}

void DownloadSection::setVisible(bool should_be_visible) {
Overlay::setVisible(should_be_visible);

if (should_be_visible) {
Image image(Image::ARGB, 1, 1, false);
Graphics g(image);
paintOpenGlChildrenBackgrounds(g);
}
}

void DownloadSection::mouseUp(const MouseEvent &e) {
if (install_text_background_.getBounds().contains(e.getPosition()))
chooseInstallFolder();
}

void DownloadSection::buttonClicked(Button* clicked_button) {
if (clicked_button == cancel_button_.get())
cancelDownload();
else if (clicked_button == install_button_.get())
triggerInstall();
else if (clicked_button == folder_button_.get())
chooseInstallFolder();
}

void DownloadSection::renderOpenGlComponents(OpenGlWrapper& open_gl, bool animate) {
download_progress_.setQuad(0, -1.0f, -1.0f, 2.0f * progress_value_, 2.0f);

SynthSection::renderOpenGlComponents(open_gl, animate);
download_progress_.renderCorners(open_gl, animate, download_progress_.getBodyColor(),
download_progress_.getHeight() / 2);
}

void DownloadSection::finished(URL::DownloadTask* task, bool success) {
if (cancel_)
return;

if (awaiting_install_.empty()) {
try {
json packs_data;
if (success)
packs_data = json::parse(available_packs_location_.loadFileAsString().toStdString(), nullptr, false);

if (available_packs_location_.exists() && LoadSave::getAvailablePacksFile() != File())
available_packs_location_.moveFileTo(LoadSave::getAvailablePacksFile());

json available_packs = packs_data["packs"];
json installed_packs = LoadSave::getInstalledPacks();

MessageManagerLock lock(Thread::getCurrentThread());
if (!lock.lockWasGained())
return;

for (auto& pack : available_packs) {
bool purchased = false;
if (pack.count("Purchased"))
purchased = pack["Purchased"];
int id = pack["Id"];
std::string pack_name = pack["Name"];
pack_name = String(pack_name).removeCharacters(" ._").toLowerCase().toStdString();

if (purchased && installed_packs.count(std::to_string(id)) == 0 && installed_packs.count(pack_name) == 0) {
std::string name = pack["Name"];
std::string author = pack["Author"];
std::string url = pack["DownloadLink"];
LoadSave::writeErrorLog(url);

File download_location = File::getSpecialLocation(File::tempDirectory).getChildFile(name + ".zip");
if (!url.empty() && url[0] == '/')
url = kDownloadUrlPrefix + url;
awaiting_download_.emplace_back(name, author, id, URL(url), download_location);
}
}

if (awaiting_download_.empty()) {
for (Listener* listener : listeners_)
listener->noDownloadNeeded();
}
else
setVisible(true);
}
catch (const json::exception& e) {
LoadSave::writeErrorLog(e.what());
}
}
else {
progress_value_ = 1.0f;
awaiting_install_[awaiting_install_.size() - 1].finished = success;
}

if (!awaiting_download_.empty()) {
DownloadPack pack = awaiting_download_[awaiting_download_.size() - 1];
awaiting_download_.pop_back();
awaiting_install_.push_back(pack);
int number = static_cast<int>(awaiting_install_.size());
int total = awaiting_download_.size() + awaiting_install_.size();

MessageManagerLock lock(Thread::getCurrentThread());
if (!lock.lockWasGained())
return;

std::string order_string = "(" + std::to_string(number) + " / " + std::to_string(total) + ")";
download_text_->setText(pack.author + ": " + pack.name + " " + order_string);
download_threads_.emplace_back(std::make_unique<DownloadThread>(this, pack.url, pack.download_location));
download_threads_[download_threads_.size() - 1]->startThread();
return;
}

MessageManagerLock lock(Thread::getCurrentThread());
if (!lock.lockWasGained())
return;

if (success)
install_button_->setEnabled(true);

loading_wheel_->setActive(false);
download_text_->setText("Downloads completed");
}

void DownloadSection::progress(URL::DownloadTask* task, int64 bytesDownloaded, int64 totalLength) {
MessageManagerLock lock(Thread::getCurrentThread());

if (lock.lockWasGained() && !awaiting_install_.empty()) {
double completed = bytesDownloaded;
progress_value_ = completed / totalLength;
}
}

Rectangle<int> DownloadSection::getDownloadRect() {
int width = kDownloadWidth * size_ratio_;
int height = kDownloadInitialHeight * size_ratio_;
if (!initial_download_)
height = kDownloadAdditionalHeight * size_ratio_;

int x = (getWidth() - width) / 2;
int y = kY * size_ratio_;
return Rectangle<int>(x, y, width, height);
}

void DownloadSection::triggerDownload() {
cancel_ = false;
progress_value_ = 0.0f;
awaiting_install_.clear();
awaiting_download_.clear();
packs_url_ = URL(kPacksUrlPrefix + kTokenUrlQuery + auth_->token());
download_text_->setText("Getting available packs...");
loading_wheel_->setActive(true);
download_threads_.emplace_back(std::make_unique<DownloadThread>(this, packs_url_, available_packs_location_));
download_threads_[download_threads_.size() - 1]->startThread();
}

void DownloadSection::triggerInstall() {
install_location_.createDirectory();
File errors_file = install_location_.getChildFile("errors.txt");
errors_file.create();

if (!install_location_.exists() || !errors_file.exists() || !errors_file.hasWriteAccess()) {
MessageManagerLock lock(Thread::getCurrentThread());
String warning = "Can't create install directory. Select another destination";
AlertWindow::showNativeDialogBox("Can't Create Directory", warning, false);
install_button_->setEnabled(true);
cancel_button_->setEnabled(true);
return;
}

loading_wheel_->setActive(true);
download_text_->setText("Installing...");
install_button_->setEnabled(false);
cancel_button_->setEnabled(false);
install_thread_.startThread();
}

void DownloadSection::startDownload(Thread* thread, URL& url, const File& dest) {
download_tasks_.emplace_back(url.downloadToFile(dest, "", this));
}

void DownloadSection::startInstall(Thread* thread) {
std::vector<int> installed;
LoadSave::saveDataDirectory(install_location_);

for (const DownloadPack& pack : awaiting_install_) {
if (!pack.download_location.exists())
LoadSave::writeErrorLog("Install Error: Pack file moved or is missing.");

if (!pack.finished)
LoadSave::writeErrorLog("Install Error: Pack didn't download correctly");

if (!pack.finished || !pack.download_location.exists())
continue;

ZipFile zip(pack.download_location);
if (zip.getNumEntries() <= 0)
LoadSave::writeErrorLog("Unzipping Error: no entries");
else {
Result unzip_result = zip.uncompressTo(install_location_);
if (!unzip_result.wasOk())
LoadSave::writeErrorLog("Unzipping Error: " + unzip_result.getErrorMessage());
else
installed.push_back(pack.id);
}

pack.download_location.deleteFile();
}

MessageManagerLock lock(Thread::getCurrentThread());
if (!lock.lockWasGained())
return;
for (int installed_pack_id : installed)
LoadSave::markPackInstalled(installed_pack_id);

for (Listener* listener : listeners_)
listener->dataDirectoryChanged();

loading_wheel_->completeRing();
download_text_->setText("All done!");

startTimer(kCompletionWaitMs);
}

void DownloadSection::cancelDownload() {
cancel_ = true;
download_tasks_.clear();
setVisible(false);
}

void DownloadSection::chooseInstallFolder() {
FileChooser open_box("Choose Install Directory", install_location_);
if (open_box.browseForDirectory()) {
File result = open_box.getResult();
if (result.getFileName() != "Vial")
result = result.getChildFile("Vial");

result.createDirectory();
File errors_file = result.getChildFile("errors.txt");
errors_file.create();

if (result.exists() && errors_file.exists() && errors_file.hasWriteAccess()) {
install_location_ = result;
install_location_text_->setText(install_location_.getFullPathName());
}
else {
String warning = "Can't create install directory. Select another destination";
AlertWindow::showNativeDialogBox("Invalid Directory", warning, false);
}
}
}

+ 0
- 147
ports/vitalium/source/interface/editor_sections/download_section.h View File

@@ -1,147 +0,0 @@
/* Copyright 2013-2019 Matt Tytel
*
* vital is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* vital is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with vital. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "JuceHeader.h"
#include "overlay.h"

class Authentication;

class DownloadSection : public Overlay, public URL::DownloadTask::Listener, public Timer {
public:
static const std::string kFactoryDownloadPath;
static constexpr int kY = 180;
static constexpr int kDownloadWidth = 450;
static constexpr int kDownloadInitialHeight = 380;
static constexpr int kDownloadAdditionalHeight = 324;
static constexpr int kTextHeight = 15;
static constexpr int kPaddingX = 20;
static constexpr int kPaddingY = 20;
static constexpr int kButtonHeight = 36;
static constexpr int kCompletionWaitMs = 1000;

struct DownloadPack {
DownloadPack(std::string n, std::string a, int i, URL u, File d) :
name(std::move(n)), author(std::move(a)), id(i), url(u), download_location(d), finished(false) { }
std::string name;
std::string author;
int id;
URL url;
File download_location;
bool finished;
};

class Listener {
public:
virtual ~Listener() = default;

virtual void dataDirectoryChanged() = 0;
virtual void noDownloadNeeded() = 0;
};

class DownloadThread : public Thread {
public:
DownloadThread(DownloadSection* ref, URL url, File dest) :
Thread("Vial Download Thread"), ref_(ref), url_(std::move(url)), dest_(std::move(dest)) { }
virtual ~DownloadThread() { }

void run() override {
ref_->startDownload(this, url_, dest_);
}

private:
DownloadSection* ref_;
URL url_;
File dest_;
};

class InstallThread : public Thread {
public:
InstallThread(DownloadSection* ref) : Thread("Vial Install Thread"), ref_(ref) { }
virtual ~InstallThread() { }

void run() override {
ref_->startInstall(this);
}

private:
DownloadSection* ref_;
};

DownloadSection(String name, Authentication* auth);
virtual ~DownloadSection() {
for (auto& thread : download_threads_)
thread->stopThread(300);
}

void resized() override;
void setVisible(bool should_be_visible) override;
void timerCallback() override {
stopTimer();
setVisible(false);
}

void mouseUp(const MouseEvent& e) override;
void buttonClicked(Button* clicked_button) override;

void renderOpenGlComponents(OpenGlWrapper& open_gl, bool animate) override;

void finished(URL::DownloadTask* task, bool success) override;
void progress(URL::DownloadTask* task, int64 bytesDownloaded, int64 totalLength) override;

Rectangle<int> getDownloadRect();
void triggerDownload();
void triggerInstall();
void startDownload(Thread* thread, URL& url, const File& dest);
void startInstall(Thread* thread);
void cancelDownload();
void chooseInstallFolder();
void addListener(Listener* listener) { listeners_.push_back(listener); }

private:
Authentication* auth_;
OpenGlQuad body_;
bool cancel_;
bool initial_download_;
float progress_value_;
OpenGlQuad download_progress_;
OpenGlQuad download_background_;
OpenGlQuad install_text_background_;
std::unique_ptr<AppLogo> logo_;
std::unique_ptr<LoadingWheel> loading_wheel_;

std::vector<std::unique_ptr<DownloadThread>> download_threads_;
InstallThread install_thread_;

URL packs_url_;
URL factory_download_url_;
File available_packs_location_;
std::vector<DownloadPack> awaiting_install_;
std::vector<DownloadPack> awaiting_download_;
std::vector<std::unique_ptr<URL::DownloadTask>> download_tasks_;
File install_location_;
std::vector<Listener*> listeners_;

std::unique_ptr<OpenGlShapeButton> folder_button_;
std::unique_ptr<PlainTextComponent> download_text_;
std::unique_ptr<PlainTextComponent> install_location_text_;
std::unique_ptr<OpenGlToggleButton> install_button_;
std::unique_ptr<OpenGlToggleButton> cancel_button_;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DownloadSection)
};


+ 0
- 165
ports/vitalium/source/interface/editor_sections/update_check_section.cpp View File

@@ -1,165 +0,0 @@
/* Copyright 2013-2019 Matt Tytel
*
* vital is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* vital is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with vital. If not, see <http://www.gnu.org/licenses/>.
*/

#include "update_check_section.h"

#include "fonts.h"
#include "load_save.h"

UpdateMemory::UpdateMemory() {
checkers_ = 0;
if (!LoadSave::shouldCheckForUpdates())
checkers_ = 1;
}

UpdateMemory::~UpdateMemory() {
clearSingletonInstance();
}

JUCE_IMPLEMENT_SINGLETON(UpdateMemory)

UpdateCheckSection::UpdateCheckSection(String name) : Overlay(name), version_request_(this),
body_(Shaders::kRoundedRectangleFragment) {
addOpenGlComponent(&body_);

notify_text_ = std::make_unique<PlainTextComponent>("notify", "There is a new version of Vital!");
notify_text_->setTextSize(20.0f);
notify_text_->setFontType(PlainTextComponent::kLight);
addOpenGlComponent(notify_text_.get());

version_text_ = std::make_unique<PlainTextComponent>("version", "");
version_text_->setTextSize(14.0f);
version_text_->setFontType(PlainTextComponent::kLight);
addOpenGlComponent(version_text_.get());

download_button_ = std::make_unique<OpenGlToggleButton>(TRANS("Download"));
download_button_->addListener(this);
download_button_->setUiButton(true);
addAndMakeVisible(download_button_.get());
addOpenGlComponent(download_button_->getGlComponent());

nope_button_ = std::make_unique<OpenGlToggleButton>(TRANS("Ignore"));
nope_button_->addListener(this);
nope_button_->setUiButton(false);
addAndMakeVisible(nope_button_.get());
addOpenGlComponent(nope_button_->getGlComponent());

content_update_ = false;
}

void UpdateCheckSection::resized() {
body_.setRounding(findValue(Skin::kBodyRounding));
body_.setColor(findColour(Skin::kBody, true));

Colour text_color = findColour(Skin::kBodyText, true);
notify_text_->setColor(text_color);
version_text_->setColor(text_color);

Rectangle<int> update_rect = getUpdateCheckRect();
body_.setBounds(update_rect);

int text_width = update_rect.getWidth() - 2 * kPaddingX;
int height = 32;
notify_text_->setBounds(update_rect.getX() + kPaddingX, update_rect.getY() + kPaddingY, text_width, height);
version_text_->setBounds(update_rect.getX() + kPaddingX, update_rect.getY() + kPaddingY + height, text_width, height);

float button_width = (update_rect.getWidth() - 3 * kPaddingX) / 2.0f;
download_button_->setBounds(update_rect.getX() + kPaddingX,
update_rect.getBottom() - kPaddingY - kButtonHeight,
button_width, kButtonHeight);
nope_button_->setBounds(update_rect.getX() + button_width + 2 * kPaddingX,
update_rect.getBottom() - kPaddingY - kButtonHeight,
button_width, kButtonHeight);
Overlay::resized();
}

void UpdateCheckSection::setVisible(bool should_be_visible) {
Overlay::setVisible(should_be_visible);

if (should_be_visible) {
Image image(Image::ARGB, 1, 1, false);
Graphics g(image);
paintOpenGlChildrenBackgrounds(g);
}
}

void UpdateCheckSection::updateContent(String version) {
}

void UpdateCheckSection::needsUpdate() {
for (Listener* listener : listeners_)
listener->needsUpdate();
}

void UpdateCheckSection::buttonClicked(Button* clicked_button) {
if (clicked_button == download_button_.get()) {
if (content_update_)
updateContent(content_version_);
else
URL("").launchInDefaultBrowser();
}
setVisible(false);
}

void UpdateCheckSection::mouseUp(const MouseEvent &e) {
if (!getUpdateCheckRect().contains(e.getPosition()))
setVisible(false);
}

void UpdateCheckSection::finished(URL::DownloadTask* task, bool success) {
if (!success)
return;

StringArray versions;
version_file_.readLines(versions);
if (versions.size() < 2)
return;

MessageManagerLock lock(&version_request_);
if (!lock.lockWasGained())
return;

app_version_ = versions[0];
content_version_ = versions[1];

if (!app_version_.isEmpty() && LoadSave::compareVersionStrings(ProjectInfo::versionString, app_version_) < 0) {
version_text_->setText(String("Version: ") + app_version_);
needsUpdate();
}
}

void UpdateCheckSection::checkUpdate() {
URL version_url("");
version_file_ = File::getSpecialLocation(File::tempDirectory).getChildFile("vital_versions.txt");
download_task_ = version_url.downloadToFile(version_file_, "", this);
}

void UpdateCheckSection::checkContentUpdate() {
String content_version = LoadSave::loadContentVersion();
if (!content_version_.isEmpty() && LoadSave::compareVersionStrings(content_version, content_version_) < 0) {
notify_text_->setText("There is new preset content available");
version_text_->setText(String("Version: ") + content_version_);
content_update_ = true;
needsUpdate();
}
}

Rectangle<int> UpdateCheckSection::getUpdateCheckRect() {
int x = (getWidth() - kUpdateCheckWidth) / 2;
int y = (getHeight() - kUpdateCheckHeight) / 2;
return Rectangle<int>(x, y, kUpdateCheckWidth, kUpdateCheckHeight);
}

+ 0
- 115
ports/vitalium/source/interface/editor_sections/update_check_section.h View File

@@ -1,115 +0,0 @@
/* Copyright 2013-2019 Matt Tytel
*
* vital is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* vital is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with vital. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "JuceHeader.h"
#include "overlay.h"

class UpdateMemory : public DeletedAtShutdown {
public:
UpdateMemory();
virtual ~UpdateMemory();

bool incrementChecker() {
ScopedLock lock(lock_);
bool should_check = checkers_ == 0;
checkers_++;
return should_check;
}

void decrementChecker() {
ScopedLock lock(lock_);
checkers_--;
}

JUCE_DECLARE_SINGLETON(UpdateMemory, false)

private:
CriticalSection lock_;
int checkers_;
};

class UpdateCheckSection : public Overlay, public URL::DownloadTask::Listener {
public:
static constexpr int kUpdateCheckWidth = 340;
static constexpr int kUpdateCheckHeight = 160;
static constexpr int kPaddingX = 20;
static constexpr int kPaddingY = 20;
static constexpr int kButtonHeight = 30;

class VersionRequestThread : public Thread {
public:
VersionRequestThread(UpdateCheckSection* ref) : Thread("Vial Download Thread"), ref_(ref) { }

void run() override {
ref_->checkUpdate();
}

private:
UpdateCheckSection* ref_;
};

class Listener {
public:
virtual ~Listener() { }
virtual void needsUpdate() = 0;
};

UpdateCheckSection(String name);
~UpdateCheckSection() {
version_request_.stopThread(350);
}
void resized() override;
void setVisible(bool should_be_visible) override;
void needsUpdate();

void buttonClicked(Button* clicked_button) override;
void mouseUp(const MouseEvent& e) override;

void finished(URL::DownloadTask* task, bool success) override;
void progress(URL::DownloadTask* task, int64 bytesDownloaded, int64 totalLength) override { }

void startCheck() {
version_request_.startThread();
}
void checkUpdate();
void checkContentUpdate();

Rectangle<int> getUpdateCheckRect();
void addListener(Listener* listener) { listeners_.push_back(listener); }

private:
void updateContent(String version);

std::vector<Listener*> listeners_;

VersionRequestThread version_request_;
std::unique_ptr<URL::DownloadTask> download_task_;
File version_file_;

OpenGlQuad body_;
std::unique_ptr<PlainTextComponent> notify_text_;
std::unique_ptr<PlainTextComponent> version_text_;
std::unique_ptr<OpenGlToggleButton> download_button_;
std::unique_ptr<OpenGlToggleButton> nope_button_;

String app_version_;
String content_version_;
bool content_update_;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UpdateCheckSection)
};


Loading…
Cancel
Save