MCPcopy Create free account
hub / github.com/su-kaka/gcli2api / checkForUpdates

Function checkForUpdates

front/common.js:3117–3176  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3115
3116// 检查更新
3117async function checkForUpdates() {
3118 const checkBtn = document.getElementById('checkUpdateBtn');
3119 if (!checkBtn) return;
3120
3121 const originalText = checkBtn.textContent;
3122
3123 try {
3124 // 显示检查中状态
3125 checkBtn.textContent = '检查中...';
3126 checkBtn.disabled = true;
3127
3128 // 调用API检查更新
3129 const response = await fetch('./version/info?check_update=true');
3130 const data = await response.json();
3131
3132 if (data.success) {
3133 if (data.check_update === false) {
3134 // 检查更新失败
3135 showStatus(`检查更新失败: ${data.update_error || '未知错误'}`, 'error');
3136 } else if (data.has_update === true) {
3137 // 有更新
3138 const updateMsg = `发现新版本!\n当前: v${data.version}\n最新: v${data.latest_version}\n\n更新内容: ${data.latest_message || '无'}`;
3139 showStatus(updateMsg.replace(/\n/g, ' '), 'warning');
3140
3141 // 更新按钮样式
3142 checkBtn.style.backgroundColor = '#ffc107';
3143 checkBtn.textContent = '有新版本';
3144
3145 setTimeout(() => {
3146 checkBtn.style.backgroundColor = '#17a2b8';
3147 checkBtn.textContent = originalText;
3148 }, 5000);
3149 } else if (data.has_update === false) {
3150 // 已是最新
3151 showStatus('已是最新版本!', 'success');
3152
3153 checkBtn.style.backgroundColor = '#28a745';
3154 checkBtn.textContent = '已是最新';
3155
3156 setTimeout(() => {
3157 checkBtn.style.backgroundColor = '#17a2b8';
3158 checkBtn.textContent = originalText;
3159 }, 3000);
3160 } else {
3161 // 无法确定
3162 showStatus('无法确定是否有更新', 'info');
3163 }
3164 } else {
3165 showStatus(`检查更新失败: ${data.error}`, 'error');
3166 }
3167 } catch (error) {
3168 console.error('检查更新失败:', error);
3169 showStatus(`检查更新失败: ${error.message}`, 'error');
3170 } finally {
3171 checkBtn.disabled = false;
3172 if (checkBtn.textContent === '检查中...') {
3173 checkBtn.textContent = originalText;
3174 }

Callers

nothing calls this directly

Calls 2

showStatusFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected