mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
window.updateAllPlugins was never assigned, so the button always showed "Bulk update handler unavailable." Wire it to PluginInstallManager.updateAll(), add per-plugin progress feedback in the button text, show a summary notification on completion, and skip redundant plugin list reloads. Co-authored-by: Chuck <chuck@example.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
123 lines
3.8 KiB
JavaScript
123 lines
3.8 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.
|
|
*
|
|
* @param {Function} onProgress - Optional callback(index, total, pluginId) for progress updates
|
|
* @returns {Promise<Array>} Update results
|
|
*/
|
|
async updateAll(onProgress) {
|
|
if (!window.PluginStateManager || !window.PluginStateManager.installedPlugins) {
|
|
throw new Error('Installed plugins not loaded');
|
|
}
|
|
|
|
const plugins = window.PluginStateManager.installedPlugins;
|
|
const results = [];
|
|
|
|
for (let i = 0; i < plugins.length; i++) {
|
|
const plugin = plugins[i];
|
|
if (onProgress) onProgress(i + 1, plugins.length, plugin.id);
|
|
try {
|
|
const result = await window.PluginAPI.updatePlugin(plugin.id);
|
|
results.push({ pluginId: plugin.id, success: true, result });
|
|
} catch (error) {
|
|
results.push({ pluginId: plugin.id, success: false, error });
|
|
}
|
|
}
|
|
|
|
// Reload plugin list once at the end
|
|
if (window.PluginStateManager) {
|
|
await window.PluginStateManager.loadInstalledPlugins();
|
|
}
|
|
|
|
return results;
|
|
}
|
|
};
|
|
|
|
// Export
|
|
if (typeof module !== 'undefined' && module.exports) {
|
|
module.exports = PluginInstallManager;
|
|
} else {
|
|
window.PluginInstallManager = PluginInstallManager;
|
|
window.updateAllPlugins = (onProgress) => PluginInstallManager.updateAll(onProgress);
|
|
}
|
|
|