mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
The previous fix (#249) wired window.updateAllPlugins to PluginInstallManager.updateAll(), but that method reads from PluginStateManager.installedPlugins which is never populated on page load — only after individual install/update operations. Meanwhile, base.html already defined a working updateAllPlugins using window.installedPlugins (reliably populated by plugins_manager.js). The override from install_manager.js masked this working version. Fix: revert install_manager.js changes and rewrite runUpdateAllPlugins to iterate window.installedPlugins directly, calling the API endpoint without any middleman. Adds per-plugin progress in button text and a summary notification on completion. Co-authored-by: Chuck <chuck@example.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
114 lines
3.3 KiB
JavaScript
114 lines
3.3 KiB
JavaScript
/**
|
|
* Plugin installation and update management.
|
|
*
|
|
* Handles plugin installation, updates, and uninstallation operations.
|
|
*/
|
|
|
|
const PluginInstallManager = {
|
|
/**
|
|
* Install a plugin.
|
|
*
|
|
* @param {string} pluginId - Plugin identifier
|
|
* @param {string} branch - Optional branch name to install from
|
|
* @returns {Promise<Object>} Installation result
|
|
*/
|
|
async install(pluginId, branch = null) {
|
|
try {
|
|
const result = await window.PluginAPI.installPlugin(pluginId, branch);
|
|
|
|
// Refresh installed plugins list
|
|
if (window.PluginStateManager) {
|
|
await window.PluginStateManager.loadInstalledPlugins();
|
|
}
|
|
|
|
return result;
|
|
} catch (error) {
|
|
if (window.errorHandler) {
|
|
window.errorHandler.displayError(error, `Failed to install plugin ${pluginId}`);
|
|
}
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Update a plugin.
|
|
*
|
|
* @param {string} pluginId - Plugin identifier
|
|
* @returns {Promise<Object>} Update result
|
|
*/
|
|
async update(pluginId) {
|
|
try {
|
|
const result = await window.PluginAPI.updatePlugin(pluginId);
|
|
|
|
// Refresh installed plugins list
|
|
if (window.PluginStateManager) {
|
|
await window.PluginStateManager.loadInstalledPlugins();
|
|
}
|
|
|
|
return result;
|
|
} catch (error) {
|
|
if (window.errorHandler) {
|
|
window.errorHandler.displayError(error, `Failed to update plugin ${pluginId}`);
|
|
}
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Uninstall a plugin.
|
|
*
|
|
* @param {string} pluginId - Plugin identifier
|
|
* @returns {Promise<Object>} Uninstall result
|
|
*/
|
|
async uninstall(pluginId) {
|
|
try {
|
|
const result = await window.PluginAPI.uninstallPlugin(pluginId);
|
|
|
|
// Refresh installed plugins list
|
|
if (window.PluginStateManager) {
|
|
await window.PluginStateManager.loadInstalledPlugins();
|
|
}
|
|
|
|
return result;
|
|
} catch (error) {
|
|
if (window.errorHandler) {
|
|
window.errorHandler.displayError(error, `Failed to uninstall plugin ${pluginId}`);
|
|
}
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Update all plugins.
|
|
*
|
|
* @returns {Promise<Array>} Update results
|
|
*/
|
|
async updateAll() {
|
|
if (!window.PluginStateManager || !window.PluginStateManager.installedPlugins) {
|
|
throw new Error('Installed plugins not loaded');
|
|
}
|
|
|
|
const plugins = window.PluginStateManager.installedPlugins;
|
|
const results = [];
|
|
|
|
for (const plugin of plugins) {
|
|
try {
|
|
const result = await this.update(plugin.id);
|
|
results.push({ pluginId: plugin.id, success: true, result });
|
|
} catch (error) {
|
|
results.push({ pluginId: plugin.id, success: false, error });
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
};
|
|
|
|
// Export
|
|
if (typeof module !== 'undefined' && module.exports) {
|
|
module.exports = PluginInstallManager;
|
|
} else {
|
|
window.PluginInstallManager = PluginInstallManager;
|
|
}
|
|
|