Skip to content

Commit 6964897

Browse files
committed
Add plugin update check and notification on startup
1 parent eafde66 commit 6964897

File tree

6 files changed

+119
-3
lines changed

6 files changed

+119
-3
lines changed

Source/MainWindow.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ MainWindow::MainWindow (const File& fileToLoad, bool isConsoleApp_) : isConsoleA
244244
LatestVersionCheckerAndUpdater::getInstance()->checkForNewVersion (true, this);
245245
#endif
246246

247+
// Check for plugin updates and notify user if any are available
248+
if (! isConsoleApp)
249+
{
250+
UIComponent* ui = (UIComponent*) documentWindow->getContentComponent();
251+
ui->checkForPluginUpdates();
252+
}
253+
247254
Process::setPriority (Process::HighPriority);
248255
}
249256

Source/Processors/FileReader/FileReader.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void FileReader::parameterValueChanged (Parameter* p)
103103
{
104104
if (p->getName() == "selected_file")
105105
{
106-
LOGC ("FileReader::parameterValueChanged - selected_file changed to: ", p->getValue().toString());
107106
setFile (p->getValue(), false);
108107
}
109108
else if (p->getName() == "active_stream")
@@ -240,8 +239,6 @@ bool FileReader::setFile (String fullpath, bool shouldUpdateSignalChain)
240239
}
241240
}
242241

243-
LOGC ("[FileReader] set file: ", fullpath);
244-
245242
//Open file
246243
File file (fullpath);
247244

Source/UI/PluginInstaller.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,84 @@ void PluginInstaller::createXmlFile()
171171
}
172172
}
173173

174+
int PluginInstaller::checkForPluginUpdates()
175+
{
176+
LOGD ("Checking for plugin updates...");
177+
178+
File xmlFile = getPluginsDirectory().getChildFile ("installedPlugins.xml");
179+
180+
XmlDocument doc (xmlFile);
181+
std::unique_ptr<XmlElement> xml (doc.getDocumentElement());
182+
183+
if (xml == 0 || ! xml->hasTagName ("PluginInstaller"))
184+
{
185+
LOGD ("[PluginInstaller] installedPlugins.xml not found.");
186+
return 0;
187+
}
188+
189+
auto child = xml->getFirstChildElement();
190+
191+
String baseUrl = "https://open-ephys-plugin-gateway.herokuapp.com/";
192+
String response = URL (baseUrl).readEntireTextStream();
193+
194+
if (response.isEmpty())
195+
{
196+
LOGE ("Unable to fetch plugin updates! Please check your internet connection.");
197+
return 0;
198+
}
199+
200+
var gatewayData;
201+
Result result = JSON::parse (response, gatewayData);
202+
gatewayData = gatewayData.getProperty ("plugins", var());
203+
204+
updatablePlugins.clear();
205+
206+
for (auto* e : child->getChildIterator())
207+
{
208+
String pName = e->getTagName();
209+
String latestVer;
210+
211+
// Get latest compatible version for this plugin
212+
for (int i = 0; i < gatewayData.size(); i++)
213+
{
214+
if (gatewayData[i].getProperty ("name", "NULL").toString().equalsIgnoreCase (pName))
215+
{
216+
auto allVersions = gatewayData[i].getProperty ("versions", "NULL").getArray();
217+
StringArray compatibleVersions;
218+
219+
for (String depVersion : *allVersions)
220+
{
221+
String apiVer = depVersion.substring (depVersion.indexOf ("I") + 1);
222+
223+
if (apiVer.equalsIgnoreCase (String (PLUGIN_API_VER)))
224+
compatibleVersions.add (depVersion);
225+
}
226+
227+
if (! compatibleVersions.isEmpty())
228+
{
229+
compatibleVersions.sort (false);
230+
latestVer = compatibleVersions[compatibleVersions.size() - 1];
231+
}
232+
else
233+
{
234+
latestVer = "0.0.0-API" + String (PLUGIN_API_VER);
235+
}
236+
237+
break;
238+
}
239+
}
240+
241+
if (latestVer.isNotEmpty() && latestVer.compareNatural (e->getAttributeValue (0)) > 0)
242+
{
243+
updatablePlugins.add (pName);
244+
LOGD ("Plugin update available: ", pName);
245+
}
246+
}
247+
248+
LOGD ("Found ", updatablePlugins.size(), " plugin(s) with updates available.");
249+
return updatablePlugins.size();
250+
}
251+
174252
void PluginInstaller::installPluginAndDependency (const String& plugin, String version)
175253
{
176254
PluginInfoComponent tempInfoComponent;

Source/UI/PluginInstaller.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class PluginInstaller : public DocumentWindow
5050
/** Access method to install a plugin directly without interacting with the Plugin Installer interface*/
5151
void installPluginAndDependency (const String& plugin, String version);
5252

53+
/** Checks for plugin updates in the background and populates updatablePlugins array.
54+
* Returns the number of plugins that have updates available. */
55+
static int checkForPluginUpdates();
56+
5357
private:
5458
WeakReference<PluginInstaller>::Master masterReference;
5559
friend class WeakReference<PluginInstaller>;

Source/UI/UIComponent.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,33 @@ void UIComponent::setUIBusy (bool busy)
476476
repaint();
477477
}
478478

479+
void UIComponent::checkForPluginUpdates()
480+
{
481+
// Run the check on a background thread to avoid blocking the UI
482+
Thread::launch ([this]()
483+
{
484+
int numUpdates = PluginInstaller::checkForPluginUpdates();
485+
486+
if (numUpdates > 0)
487+
{
488+
MessageManager::callAsync ([this, numUpdates]()
489+
{
490+
String message = String (numUpdates) + " plugin update" + (numUpdates > 1 ? "s" : "")
491+
+ " available. Open the Plugin Installer to update.";
492+
493+
AttributedString s;
494+
s.setText (message);
495+
s.setColour (findColour (ThemeColours::defaultText));
496+
s.setJustification (Justification::left);
497+
s.setWordWrap (AttributedString::WordWrap::byWord);
498+
s.setFont (FontOptions ("Inter", "Regular", 16.0f));
499+
500+
bubbleMsgComponent->showAt ({5, 5, 195, 32}, s, 4000);
501+
});
502+
}
503+
});
504+
}
505+
479506
void UIComponent::showBubbleMessage (Component* component, const String& message)
480507
{
481508
AttributedString s;

Source/UI/UIComponent.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ class UIComponent : public Component,
210210
/** Sets the busy state of the UIComponent */
211211
void setUIBusy (bool busy);
212212

213+
/** Checks for plugin updates and shows a bubble message if any are available */
214+
void checkForPluginUpdates();
215+
213216
private:
214217
ScopedPointer<DataViewport> dataViewport;
215218
ScopedPointer<SignalChainTabComponent> signalChainTabComponent;

0 commit comments

Comments
 (0)