AnalogTapeModel

Physical modelling signal processing for analog tape recording
Log | Files | Refs | Submodules | README | LICENSE

commit 838348f9cd78b3e6a0d3649a910ad04b3f4547cf
parent 30153f5521949977161468238352550898bd2cac
Author: jatinchowdhury18 <[email protected]>
Date:   Sat, 14 Nov 2020 23:30:28 -0800

Re-factor auto-updater to run update check asynchronously

Diffstat:
MPlugin/Source/GUI/AutoUpdating.cpp | 17++++++++++++++++-
MPlugin/Source/GUI/AutoUpdating.h | 6+++++-
MPlugin/Source/PluginProcessor.cpp | 12+-----------
MPlugin/Source/PluginProcessor.h | 3---
4 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/Plugin/Source/GUI/AutoUpdating.cpp b/Plugin/Source/GUI/AutoUpdating.cpp @@ -7,6 +7,7 @@ namespace const String versionURL = "https://api.github.com/repos/jatinchowdhury18/AnalogTapeModel/releases/latest"; const String updateURL = "https://github.com/jatinchowdhury18/AnalogTapeModel/releases/latest"; const Colour backgroundColour = Colour (0xFF31323A).withAlpha (0.9f); + const Colour textColour = Colour (0xFFEAA92C); } AutoUpdater::AutoUpdater() @@ -15,7 +16,7 @@ AutoUpdater::AutoUpdater() { addAndMakeVisible (button); button.setColour (TextButton::buttonColourId, backgroundColour); - button.setColour (TextButton::textColourOffId, Colour (0xFFEAA92C)); + button.setColour (TextButton::textColourOffId, textColour); button.setColour (ComboBox::outlineColourId, Colours::transparentBlack); button.setOpaque (false); button.setMouseCursor (MouseCursor::PointingHandCursor); @@ -27,6 +28,8 @@ AutoUpdater::AutoUpdater() yesButton.onClick = std::bind (&AutoUpdater::yesButtonPressed, this); noButton.onClick = std::bind (&AutoUpdater::noButtonPressed, this); + + needsUpdate = std::async (std::launch::async, &AutoUpdater::runAutoUpdateCheck, this); } AutoUpdater::~AutoUpdater() @@ -81,6 +84,18 @@ void AutoUpdater::resized() noButton.setBounds (getWidth() / 2 + pad, y, width, height); } +void AutoUpdater::showUpdaterScreen (Component* parent) +{ + if (! needsUpdate.valid()) + return; + + if (needsUpdate.get()) + { + parent->addAndMakeVisible (this); + setBounds (0, 0, parent->getWidth(), parent->getHeight()); + } +} + bool AutoUpdater::runAutoUpdateCheck() { auto updateFile = getUpdateCheckFile(); diff --git a/Plugin/Source/GUI/AutoUpdating.h b/Plugin/Source/GUI/AutoUpdating.h @@ -2,6 +2,7 @@ #define AUTOUPDATING_H_INCLUDED #include <JuceHeader.h> +#include <future> #include "MyLNF.h" struct UpdateButtonLNF : public MyLNF @@ -31,6 +32,8 @@ public: void paint (Graphics& g) override; void resized() override; + void showUpdaterScreen (Component* parent); + bool runAutoUpdateCheck(); void noButtonPressed(); void yesButtonPressed(); @@ -48,8 +51,9 @@ private: TextButton noButton { "No" }; UpdateButtonLNF ubLNF; + std::future<bool> needsUpdate; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AutoUpdater) }; - #endif // AUTOUPDATING_H_INCLUDED diff --git a/Plugin/Source/PluginProcessor.cpp b/Plugin/Source/PluginProcessor.cpp @@ -47,8 +47,6 @@ ChowtapeModelAudioProcessor::ChowtapeModelAudioProcessor() flutter.initialisePlots (magicState); LookAndFeel::setDefaultLookAndFeel (&myLNF); - - needsUpdate = updater.runAutoUpdateCheck(); } ChowtapeModelAudioProcessor::~ChowtapeModelAudioProcessor() @@ -302,15 +300,7 @@ AudioProcessorEditor* ChowtapeModelAudioProcessor::createEditor() } auto* editor = new foleys::MagicPluginEditor (magicState, BinaryData::gui_xml, BinaryData::gui_xmlSize, std::move (builder)); - - if (needsUpdate) - { - needsUpdate = false; - - editor->addAndMakeVisible (updater); - updater.setBounds (0, 0, editor->getWidth(), editor->getHeight()); - } - + updater.showUpdaterScreen (editor); return editor; } diff --git a/Plugin/Source/PluginProcessor.h b/Plugin/Source/PluginProcessor.h @@ -98,10 +98,7 @@ private: PresetManager presetManager; MyLNF myLNF; - AutoUpdater updater; - bool needsUpdate = false; - MixGroupsController mixGroupsController; //==============================================================================