diff --git a/css/settings.css b/css/settings.css index 73959e4..f98942b 100644 --- a/css/settings.css +++ b/css/settings.css @@ -45,12 +45,10 @@ body { /* Server Status Display */ .server-status-container { border-top: 1px solid #e0e0e0; - padding: 8px 20px; background: #f9f9f9; margin-top: auto; display: flex; - align-items: center; - height: 55px; + flex-direction: column; } .server-status-content { @@ -58,7 +56,7 @@ body { align-items: center; justify-content: flex-start; width: 100%; - height: 100%; + padding: 8px 20px; } .server-status-text { @@ -1664,4 +1662,105 @@ textarea.form-input { border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto; +} + +/* CLI Version and Update Styles */ +.cli-version-container { + border-top: 1px solid #e0e0e0; + padding: 12px 20px; + background: #ffffff; + display: none; + flex-direction: column; + gap: 10px; +} + +.cli-version-container.show { + display: flex; +} + +.cli-version-info { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; +} + +.cli-version-label { + font-size: 11px; + font-weight: 500; + color: #6b7280; +} + +.cli-version-text { + font-size: 11px; + font-weight: 600; + color: #000000; + font-family: 'SF Mono', 'Monaco', 'Consolas', monospace; +} + +.update-cli-btn { + width: 100%; + padding: 8px 12px; + background: #8b5cf6; + color: #ffffff; + border: none; + border-radius: 6px; + font-size: 12px; + font-weight: 500; + cursor: pointer; + transition: all 0.2s ease; + font-family: inherit; +} + +.update-cli-btn:hover { + background: #7c3aed; +} + +.update-cli-btn:active { + transform: translateY(1px); +} + +.update-cli-btn:disabled { + background: #d1d5db; + cursor: not-allowed; +} + +/* Update Dialog Styles */ +.cli-update-details { + margin-top: 8px; + font-size: 13px; + color: #4b5563; + line-height: 1.6; +} + +/* Progress Bar Styles for Update Dialog */ +#cli-progress-dialog .progress-label { + font-size: 13px; + font-weight: 500; + margin-bottom: 12px; + color: #000000; + text-align: center; +} + +#cli-progress-dialog .progress-bar { + width: 100%; + height: 8px; + background: #e0e0e0; + border-radius: 4px; + overflow: hidden; + margin-bottom: 8px; +} + +#cli-progress-dialog .progress-fill { + height: 100%; + background: #8b5cf6; + border-radius: 4px; + transition: width 0.3s ease; + width: 0%; +} + +#cli-progress-dialog .progress-text { + font-size: 11px; + color: #6b7280; + text-align: center; } \ No newline at end of file diff --git a/js/settings-update.js b/js/settings-update.js new file mode 100644 index 0000000..f541140 --- /dev/null +++ b/js/settings-update.js @@ -0,0 +1,275 @@ +// CLI Update functionality for settings page +// Handles version checking, update dialog, and download progress + +// UI Elements +const cliVersionText = document.getElementById('cli-version-text'); +const updateCliBtn = document.getElementById('update-cli-btn'); +const cliUpdateDialog = document.getElementById('cli-update-dialog'); +const cliUpdateClose = document.getElementById('cli-update-close'); +const cliUpdateMessage = document.getElementById('cli-update-message'); +const cliUpdateDetails = document.getElementById('cli-update-details'); +const cliUpdateCancel = document.getElementById('cli-update-cancel'); +const cliUpdateConfirm = document.getElementById('cli-update-confirm'); +const cliProgressDialog = document.getElementById('cli-progress-dialog'); +const cliProgressLabel = document.getElementById('cli-progress-label'); +const cliProgressFill = document.getElementById('cli-progress-fill'); +const cliProgressText = document.getElementById('cli-progress-text'); + +// State +let currentVersion = null; +let latestVersion = null; +let updateAvailable = false; + +// Format bytes to human readable string +function formatBytes(bytes) { + if (bytes === 0) return '0 B'; + const k = 1024; + const sizes = ['B', 'KB', 'MB', 'GB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i]; +} + +// Load and display current CLI version +async function loadCliVersion() { + const connectionType = localStorage.getItem('type') || 'local'; + + // Only show version in Local mode + if (connectionType !== 'local') { + return; + } + + try { + const storedVersion = localStorage.getItem('cliproxyapi-version'); + if (storedVersion) { + currentVersion = storedVersion; + cliVersionText.textContent = `v${currentVersion}`; + } else { + cliVersionText.textContent = 'Not installed'; + } + } catch (error) { + console.error('Error loading CLI version:', error); + cliVersionText.textContent = 'Unknown'; + } +} + +// Show update dialog +function showUpdateDialog(current, latest) { + cliUpdateMessage.textContent = `A new version of CLIProxyAPI is available!`; + cliUpdateDetails.innerHTML = ` +