feat: 更新检查更新按钮的加载状态和通知功能,增加工具提示

This commit is contained in:
catlog22
2026-01-21 13:00:25 +08:00
parent 572c103fbf
commit cac0566627
2 changed files with 107 additions and 9 deletions

View File

@@ -55,26 +55,74 @@ function toggleAutoUpdate() {
async function checkForUpdatesNow() {
const btn = document.getElementById('checkUpdateNow');
if (btn) {
// Add loading animation
btn.classList.add('animate-spin');
// Add loading state - change button color and animate icon
btn.classList.add('checking');
btn.disabled = true;
}
// Show checking notification
console.log('[Version Check] Starting update check...');
if (typeof addGlobalNotification === 'function') {
addGlobalNotification('info', 'Checking for updates...', 'Please wait', 'version-check');
} else {
console.warn('[Version Check] addGlobalNotification is not available');
}
// Force check regardless of toggle state
const originalState = autoUpdateEnabled;
autoUpdateEnabled = true;
try {
await checkForUpdates();
addGlobalNotification('success', 'Update check complete', 'Checked for latest version', 'version-check');
const res = await fetch('/api/version-check');
if (!res.ok) {
throw new Error('Failed to fetch version information');
}
const data = await res.json();
versionCheckData = data;
console.log('[Version Check] Result:', data);
if (data.hasUpdate) {
// New version available
console.log('[Version Check] Update available:', data.latestVersion);
showUpdateBanner(data);
if (typeof addGlobalNotification === 'function') {
addGlobalNotification(
'success',
'Update Available!',
`New version ${data.latestVersion} is available (current: ${data.currentVersion})`,
'version-check'
);
}
} else {
// Already up to date
console.log('[Version Check] Already up to date:', data.currentVersion);
if (typeof addGlobalNotification === 'function') {
addGlobalNotification(
'success',
'You\'re up to date!',
`Current version ${data.currentVersion} is the latest`,
'version-check'
);
}
}
} catch (err) {
addGlobalNotification('error', 'Update check failed', err.message, 'version-check');
console.error('[Version Check] Error:', err);
if (typeof addGlobalNotification === 'function') {
addGlobalNotification(
'error',
'Update check failed',
err.message || 'Unable to check for updates',
'version-check'
);
}
} finally {
// Restore original state
autoUpdateEnabled = originalState;
if (btn) {
btn.classList.remove('animate-spin');
btn.classList.remove('checking');
btn.disabled = false;
}
}