Skip to content

Commit 10a19bc

Browse files
committed
Update Plugin Installer to get latest version from compatible versions
1 parent cf817b7 commit 10a19bc

1 file changed

Lines changed: 55 additions & 11 deletions

File tree

Source/UI/PluginInstaller.cpp

Lines changed: 55 additions & 11 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
}
@@ -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)

0 commit comments

Comments
 (0)