Moved the updatebutton, menu now checking all plugins at once, instead of one call per plugin.

This commit is contained in:
Max Klaversma 2014-04-16 14:16:37 +02:00 committed by Steffen Schröder
parent 9a6d07e73b
commit e0b5149b9c
2 changed files with 47 additions and 25 deletions

View File

@ -241,8 +241,10 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
//Display normal Plugin List
// Plugin pages
$pageFrames = array();
$y = 0.;
$pageFrames = array();
$y = 0.;
$pluginUpdates = $this->maniaControl->updateManager->getPluginsUpdates();
foreach($pluginClasses as $index => $pluginClass) {
/** @var Plugin $pluginClass */
if (!isset($pageFrame)) {
@ -319,7 +321,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$statusChangeButton->setAction(self::ACTION_PREFIX_ENABLEPLUGIN . $pluginClass);
}
if ($this->maniaControl->updateManager->checkPluginUpdate($pluginClass) != false) {
if ($pluginUpdates != false && array_key_exists($pluginClass::getId(), $pluginUpdates)) {
$quadUpdate = new Quad_Icons128x128_1();
$pluginFrame->add($quadUpdate);
$quadUpdate->setSubStyle($quadUpdate::SUBSTYLE_ProfileVehicle);
@ -335,16 +337,16 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
}
}
$numberOfOutdated = $this->maniaControl->updateManager->getNumberOfOutdatedPlugins();
if($numberOfOutdated > 0) {
if($pluginUpdates != false) {
$updatePluginsButton = new Label_Button();
$frame->add($updatePluginsButton);
$updatePluginsButton->setHAlign(Control::RIGHT);
$updatePluginsButton->setX($width * 0.1);
$updatePluginsButton->setY(-35.5);
$updatePluginsButton->setX($width * 0.5);
$updatePluginsButton->setY(-29);
$updatePluginsButton->setZ(2);
$updatePluginsButton->setStyle($updatePluginsButton::STYLE_CardButtonSmall);
$updatePluginsButton->setText('Update '.$numberOfOutdated.' plugin(s)');
$updatePluginsButton->setWidth(10);
$updatePluginsButton->setStyle($updatePluginsButton::STYLE_CardButtonSmallS);
$updatePluginsButton->setText(count($pluginUpdates).' update(s)');
$updatePluginsButton->setAction(self::ACTION_UPDATEPLUGINS);
}

View File

@ -415,22 +415,6 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
}
}
/**
* Returns the number of outdated plugins active.
* @return int
*/
public function getNumberOfOutdatedPlugins() {
$number = 0;
foreach ($this->maniaControl->pluginManager->getPluginClasses() as $pluginClass) {
$pluginData = $this->checkPluginUpdate($pluginClass);
if ($pluginData != false) {
$number++;
}
}
return $number;
}
/**
* Check given Plugin Class for Update
*
@ -457,6 +441,42 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return $pluginData;
}
/**
* Check for updates
*
* @return mixed
*/
public function getPluginsUpdates() {
$pluginUpdates = array();
$pluginsWS = array();
$url = ManiaControl::URL_WEBSERVICE . 'plugins';
$dataJson = FileUtil::loadFile($url);
$pluginVersions = json_decode($dataJson);
if (!$pluginVersions || !isset($pluginVersions[0])) {
return false;
}
foreach($pluginVersions as $plugin) {
$pluginsWS[$plugin->id] = $plugin;
}
/** @var Plugin $pluginClass */
foreach($this->maniaControl->pluginManager->getPluginClasses() as $pluginClass) {
$pluginId = $pluginClass::getId();
if(array_key_exists($pluginId, $pluginsWS)) {
if($pluginsWS[$pluginId]->currentVersion->version > $pluginClass::getVersion()) {
$pluginUpdates[$pluginId] = $pluginsWS[$pluginId];
}
}
}
if(empty($pluginUpdates)) {
return false;
}
return $pluginUpdates;
}
/**
* Update pluginfile
*