mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
fix(web): use window.installedPlugins for bulk update button (#250)
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>
This commit is contained in:
@@ -81,10 +81,9 @@ const PluginInstallManager = {
|
|||||||
/**
|
/**
|
||||||
* Update all plugins.
|
* Update all plugins.
|
||||||
*
|
*
|
||||||
* @param {Function} onProgress - Optional callback(index, total, pluginId) for progress updates
|
|
||||||
* @returns {Promise<Array>} Update results
|
* @returns {Promise<Array>} Update results
|
||||||
*/
|
*/
|
||||||
async updateAll(onProgress) {
|
async updateAll() {
|
||||||
if (!window.PluginStateManager || !window.PluginStateManager.installedPlugins) {
|
if (!window.PluginStateManager || !window.PluginStateManager.installedPlugins) {
|
||||||
throw new Error('Installed plugins not loaded');
|
throw new Error('Installed plugins not loaded');
|
||||||
}
|
}
|
||||||
@@ -92,22 +91,15 @@ const PluginInstallManager = {
|
|||||||
const plugins = window.PluginStateManager.installedPlugins;
|
const plugins = window.PluginStateManager.installedPlugins;
|
||||||
const results = [];
|
const results = [];
|
||||||
|
|
||||||
for (let i = 0; i < plugins.length; i++) {
|
for (const plugin of plugins) {
|
||||||
const plugin = plugins[i];
|
|
||||||
if (onProgress) onProgress(i + 1, plugins.length, plugin.id);
|
|
||||||
try {
|
try {
|
||||||
const result = await window.PluginAPI.updatePlugin(plugin.id);
|
const result = await this.update(plugin.id);
|
||||||
results.push({ pluginId: plugin.id, success: true, result });
|
results.push({ pluginId: plugin.id, success: true, result });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
results.push({ pluginId: plugin.id, success: false, 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;
|
return results;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -117,6 +109,5 @@ if (typeof module !== 'undefined' && module.exports) {
|
|||||||
module.exports = PluginInstallManager;
|
module.exports = PluginInstallManager;
|
||||||
} else {
|
} else {
|
||||||
window.PluginInstallManager = PluginInstallManager;
|
window.PluginInstallManager = PluginInstallManager;
|
||||||
window.updateAllPlugins = (onProgress) => PluginInstallManager.updateAll(onProgress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1682,16 +1682,12 @@ function startOnDemandStatusPolling() {
|
|||||||
|
|
||||||
window.loadOnDemandStatus = loadOnDemandStatus;
|
window.loadOnDemandStatus = loadOnDemandStatus;
|
||||||
|
|
||||||
function runUpdateAllPlugins() {
|
async function runUpdateAllPlugins() {
|
||||||
console.log('[runUpdateAllPlugins] Button clicked, checking for updates...');
|
console.log('[runUpdateAllPlugins] Button clicked, checking for updates...');
|
||||||
const button = document.getElementById('update-all-plugins-btn');
|
const button = document.getElementById('update-all-plugins-btn');
|
||||||
|
|
||||||
if (!button) {
|
if (!button) {
|
||||||
if (typeof showNotification === 'function') {
|
|
||||||
showNotification('Unable to locate bulk update controls. Refresh the Plugin Manager tab.', 'error');
|
showNotification('Unable to locate bulk update controls. Refresh the Plugin Manager tab.', 'error');
|
||||||
} else {
|
|
||||||
console.error('update-all-plugins-btn element not found');
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1699,12 +1695,9 @@ function runUpdateAllPlugins() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof window.updateAllPlugins !== 'function') {
|
const plugins = Array.isArray(window.installedPlugins) ? window.installedPlugins : [];
|
||||||
if (typeof showNotification === 'function') {
|
if (!plugins.length) {
|
||||||
showNotification('Bulk update handler unavailable. Refresh the Plugin Manager tab.', 'error');
|
showNotification('No installed plugins to update.', 'warning');
|
||||||
} else {
|
|
||||||
console.error('window.updateAllPlugins is not defined');
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1712,47 +1705,58 @@ function runUpdateAllPlugins() {
|
|||||||
button.dataset.running = 'true';
|
button.dataset.running = 'true';
|
||||||
button.disabled = true;
|
button.disabled = true;
|
||||||
button.classList.add('opacity-60', 'cursor-wait');
|
button.classList.add('opacity-60', 'cursor-wait');
|
||||||
button.innerHTML = '<i class="fas fa-sync fa-spin mr-2"></i>Checking...';
|
|
||||||
|
|
||||||
const onProgress = (current, total, pluginId) => {
|
|
||||||
button.innerHTML = `<i class="fas fa-sync fa-spin mr-2"></i>Updating ${current}/${total}...`;
|
|
||||||
};
|
|
||||||
|
|
||||||
Promise.resolve(window.updateAllPlugins(onProgress))
|
|
||||||
.then(results => {
|
|
||||||
if (!results || !results.length) {
|
|
||||||
showNotification('No plugins to update.', 'info');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let updated = 0, upToDate = 0, failed = 0;
|
let updated = 0, upToDate = 0, failed = 0;
|
||||||
for (const r of results) {
|
|
||||||
if (!r.success) {
|
try {
|
||||||
failed++;
|
for (let i = 0; i < plugins.length; i++) {
|
||||||
} else if (r.result && r.result.message && r.result.message.includes('already up to date')) {
|
const plugin = plugins[i];
|
||||||
|
const pluginId = plugin.id;
|
||||||
|
button.innerHTML = `<i class="fas fa-sync fa-spin mr-2"></i>Updating ${i + 1}/${plugins.length}...`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/v3/plugins/update', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ plugin_id: pluginId })
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.status === 'success') {
|
||||||
|
if (data.message && data.message.includes('already up to date')) {
|
||||||
upToDate++;
|
upToDate++;
|
||||||
} else {
|
} else {
|
||||||
updated++;
|
updated++;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
failed++;
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
failed++;
|
||||||
|
console.error(`Error updating ${pluginId}:`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh plugin list once at the end
|
||||||
|
if (updated > 0) {
|
||||||
|
loadInstalledPlugins(true);
|
||||||
|
}
|
||||||
|
|
||||||
const parts = [];
|
const parts = [];
|
||||||
if (updated > 0) parts.push(`${updated} updated`);
|
if (updated > 0) parts.push(`${updated} updated`);
|
||||||
if (upToDate > 0) parts.push(`${upToDate} already up to date`);
|
if (upToDate > 0) parts.push(`${upToDate} already up to date`);
|
||||||
if (failed > 0) parts.push(`${failed} failed`);
|
if (failed > 0) parts.push(`${failed} failed`);
|
||||||
const type = failed > 0 ? (updated > 0 ? 'warning' : 'error') : 'success';
|
const type = failed > 0 ? (updated > 0 ? 'warning' : 'error') : 'success';
|
||||||
showNotification(parts.join(', '), type);
|
showNotification(parts.join(', '), type);
|
||||||
})
|
} catch (error) {
|
||||||
.catch(error => {
|
console.error('Bulk plugin update failed:', error);
|
||||||
console.error('Error updating all plugins:', error);
|
showNotification('Failed to update all plugins: ' + error.message, 'error');
|
||||||
if (typeof showNotification === 'function') {
|
} finally {
|
||||||
showNotification('Error updating all plugins: ' + error.message, 'error');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
button.innerHTML = originalContent;
|
button.innerHTML = originalContent;
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
button.classList.remove('opacity-60', 'cursor-wait');
|
button.classList.remove('opacity-60', 'cursor-wait');
|
||||||
button.dataset.running = 'false';
|
button.dataset.running = 'false';
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize on-demand modal setup (runs unconditionally since modal is in base.html)
|
// Initialize on-demand modal setup (runs unconditionally since modal is in base.html)
|
||||||
|
|||||||
Reference in New Issue
Block a user