Skip to content

Commit 1e3fb42

Browse files
committed
Merge branch development-juce8 into testing-juce8
2 parents 9944d35 + 10a19bc commit 1e3fb42

2 files changed

Lines changed: 81 additions & 35 deletions

File tree

Source/UI/PluginInstaller.cpp

Lines changed: 77 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void PluginInstaller::installPluginAndDependency (const String& plugin, String v
166166
String response = URL (baseUrl).readEntireTextStream();
167167

168168
if (response.isEmpty())
169-
LOGD ("Unable to fetch plugins! Please check your internet connection and try again.")
169+
LOGE ("Unable to fetch plugins! Please check your internet connection and try again.")
170170

171171
var gatewayData;
172172
Result result = JSON::parse (response, gatewayData);
@@ -191,7 +191,7 @@ void PluginInstaller::installPluginAndDependency (const String& plugin, String v
191191

192192
if (! pluginFound)
193193
{
194-
LOGC ("Automated Plugin Installation Failed! Plugin not found!")
194+
LOGE ("Automated Plugin Installation Failed! Plugin not found!")
195195
return;
196196
}
197197

@@ -210,7 +210,6 @@ void PluginInstaller::installPluginAndDependency (const String& plugin, String v
210210
requiredPluginInfo.pluginName = pluginData[pIndex].getProperty ("name", "NULL").toString();
211211
requiredPluginInfo.displayName = plugin;
212212
requiredPluginInfo.type = pluginData[pIndex].getProperty ("type", "NULL").toString();
213-
requiredPluginInfo.latestVersion = pluginData[pIndex].getProperty ("latest_version", "NULL");
214213

215214
auto allVersions = pluginData[pIndex].getProperty ("versions", "NULL").getArray();
216215

@@ -235,7 +234,28 @@ void PluginInstaller::installPluginAndDependency (const String& plugin, String v
235234
{
236235
if (pluginData[i].getProperty ("name", "NULL").toString().equalsIgnoreCase (dependency))
237236
{
238-
requiredPluginInfo.dependencyVersions.add (pluginData[i].getProperty ("latest_version", "NULL").toString());
237+
// Get the latest compatible version of the dependency
238+
auto allDepVersions = pluginData[i].getProperty ("versions", "NULL").getArray();
239+
StringArray compatibleVersions;
240+
for (String depVersion : *allDepVersions)
241+
{
242+
String apiVer = depVersion.substring (depVersion.indexOf ("I") + 1);
243+
244+
if (apiVer.equalsIgnoreCase (String (PLUGIN_API_VER)))
245+
compatibleVersions.add (depVersion);
246+
}
247+
248+
if (! compatibleVersions.isEmpty())
249+
{
250+
compatibleVersions.sort (false);
251+
requiredPluginInfo.dependencyVersions.add (compatibleVersions[compatibleVersions.size() - 1]);
252+
}
253+
else
254+
{
255+
LOGE ("Automated Plugin Installation Failed! Compatible plugin version not found!")
256+
return;
257+
}
258+
239259
break;
240260
}
241261
}
@@ -262,7 +282,7 @@ void PluginInstaller::installPluginAndDependency (const String& plugin, String v
262282
}
263283
else
264284
{
265-
LOGC ("Automated Plugin Installation Failed! Compatible plugin version not found!")
285+
LOGE ("Automated Plugin Installation Failed! Compatible plugin version not found!")
266286
return;
267287
}
268288
}
@@ -444,7 +464,27 @@ void PluginInstallerComponent::run()
444464
{
445465
if (gatewayData[i].getProperty ("name", "NULL").toString().equalsIgnoreCase (pName))
446466
{
447-
latestVer = gatewayData[i].getProperty ("latest_version", "NULL");
467+
// Get the latest compatible version
468+
auto allVersions = gatewayData[i].getProperty ("versions", "NULL").getArray();
469+
StringArray compatibleVersions;
470+
for (String depVersion : *allVersions)
471+
{
472+
String apiVer = depVersion.substring (depVersion.indexOf ("I") + 1);
473+
474+
if (apiVer.equalsIgnoreCase (String (PLUGIN_API_VER)))
475+
compatibleVersions.add (depVersion);
476+
}
477+
478+
if (! compatibleVersions.isEmpty())
479+
{
480+
compatibleVersions.sort (false);
481+
latestVer = compatibleVersions[compatibleVersions.size() - 1];
482+
}
483+
else
484+
{
485+
latestVer = "0.0.0-API" + String (PLUGIN_API_VER);
486+
}
487+
448488
break;
449489
}
450490
}
@@ -670,7 +710,7 @@ void PluginListBoxComponent::run()
670710
pluginName = pluginData[i].getProperty ("name", var()).toString();
671711
label = pluginData[i].getProperty ("type", "NULL").toString();
672712
dispName = pluginData[i].getProperty ("display_name", "NULL").toString();
673-
713+
674714
pluginTextWidth = GlyphArrangement::getStringWidthInt (Font (listFont), dispName);
675715
if (pluginTextWidth > maxTextWidth)
676716
maxTextWidth = pluginTextWidth;
@@ -683,16 +723,16 @@ void PluginListBoxComponent::run()
683723
}
684724
else
685725
{
686-
String ver = pluginData[i].getProperty ("latest_version", "NULL").toString();
687-
dependencyVersion.set (pluginName, ver);
726+
compatibleVersions.sort (false);
727+
dependencyVersion.set (pluginName, compatibleVersions[compatibleVersions.size() - 1]);
688728
}
689729
}
690730

691731
//setProgress ((i + 1) / (double) numRows);
692732
}
693733

694-
const MessageManagerLock mmLock;
695-
setNumRows (pluginArray.size());
734+
MessageManager::callAsync ([this]
735+
{ setNumRows (pluginArray.size()); });
696736
}
697737

698738
bool PluginListBoxComponent::loadPluginInfo (const String& pluginName)
@@ -720,7 +760,6 @@ bool PluginListBoxComponent::loadPluginInfo (const String& pluginName)
720760
selectedPluginInfo.displayName = displayNames[pluginName];
721761
selectedPluginInfo.type = pluginLabels[pluginName];
722762
selectedPluginInfo.developers = pluginData[pIndex].getProperty ("developers", "NULL");
723-
selectedPluginInfo.latestVersion = pluginData[pIndex].getProperty ("latest_version", "NULL");
724763
String updated = pluginData[pIndex].getProperty ("updated", "NULL");
725764
selectedPluginInfo.lastUpdated = updated.substring (0, updated.indexOf ("T"));
726765
selectedPluginInfo.description = pluginData[pIndex].getProperty ("desc", "NULL");
@@ -739,6 +778,11 @@ bool PluginListBoxComponent::loadPluginInfo (const String& pluginName)
739778
selectedPluginInfo.versions.add (version);
740779
}
741780

781+
// Set the latest version from the list of compatible versions
782+
auto sortedVersions = selectedPluginInfo.versions;
783+
sortedVersions.sort (false);
784+
selectedPluginInfo.latestVersion = sortedVersions[sortedVersions.size() - 1];
785+
742786
selectedPluginInfo.dependencies.clear();
743787
auto dependencies = pluginData[pIndex].getProperty ("dependencies", "NULL").getArray();
744788
for (String dependency : *dependencies)
@@ -977,10 +1021,28 @@ void PluginInfoComponent::setDownloadURL (const String& url)
9771021

9781022
void PluginInfoComponent::showAlertOnMessageThread (MessageBoxIconType iconType, const String& title, const String& message)
9791023
{
980-
MessageManager::callAsync ([iconType, title, message]()
1024+
MessageManager::callAsync ([=]()
9811025
{ AlertWindow::showMessageBoxAsync (iconType, title, message); });
9821026
}
9831027

1028+
void PluginInfoComponent::updateUIOnMessageThread()
1029+
{
1030+
MessageManager::callAsync ([this]()
1031+
{
1032+
pInfo.installedVersion = pInfo.selectedVersion;
1033+
installedVerText.setText (pInfo.installedVersion, dontSendNotification);
1034+
downloadButton.setEnabled (false);
1035+
downloadButton.setButtonText ("Installed");
1036+
uninstallButton.setVisible (true);
1037+
1038+
if (pInfo.installedVersion.equalsIgnoreCase (pInfo.latestVersion))
1039+
{
1040+
updatablePlugins.removeString (pInfo.pluginName);
1041+
this->getParentComponent()->resized();
1042+
}
1043+
});
1044+
}
1045+
9841046
void PluginInfoComponent::run()
9851047
{
9861048
setProgress (-1.0);
@@ -1095,17 +1157,7 @@ void PluginInfoComponent::run()
10951157

10961158
LOGC ("Download Successful!!");
10971159

1098-
pInfo.installedVersion = pInfo.selectedVersion;
1099-
installedVerText.setText (pInfo.installedVersion, dontSendNotification);
1100-
downloadButton.setEnabled (false);
1101-
downloadButton.setButtonText ("Installed");
1102-
uninstallButton.setVisible (true);
1103-
1104-
if (pInfo.latestVersion.equalsIgnoreCase (pInfo.latestVersion))
1105-
{
1106-
updatablePlugins.removeString (pInfo.pluginName);
1107-
this->getParentComponent()->resized();
1108-
}
1160+
updateUIOnMessageThread();
11091161
}
11101162
else if (dlReturnCode == ZIP_NOTFOUND)
11111163
{
@@ -1158,17 +1210,7 @@ void PluginInfoComponent::run()
11581210

11591211
LOGE ("Loading Plugin Failed!!");
11601212

1161-
pInfo.installedVersion = pInfo.selectedVersion;
1162-
1163-
const MessageManagerLock mmLock;
1164-
downloadButton.setEnabled (false);
1165-
downloadButton.setButtonText ("Installed");
1166-
1167-
if (pInfo.latestVersion.equalsIgnoreCase (pInfo.latestVersion))
1168-
{
1169-
updatablePlugins.removeString (pInfo.pluginName);
1170-
this->getParentComponent()->repaint();
1171-
}
1213+
updateUIOnMessageThread();
11721214
}
11731215
else if (dlReturnCode == HTTP_ERR)
11741216
{

Source/UI/PluginInstaller.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,12 @@ class PluginInfoComponent : public Component,
165165

166166
void run() override;
167167

168+
/** Shows the alert message on the message thread **/
168169
void showAlertOnMessageThread (MessageBoxIconType iconType, const String& title, const String& message);
169170

171+
/** Updates the UI on the message thread **/
172+
void updateUIOnMessageThread();
173+
170174
DropShadower infoCompDropShadower { DropShadow (Colours::black.withAlpha (0.5f), 6, { 2, 2 }) };
171175

172176
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginInfoComponent);

0 commit comments

Comments
 (0)