Skip to content

Commit a207985

Browse files
authored
fix:在线更新功能优化-实现自动无感更新(Win) (#48)
* resolve merge conflict in main.go, keep remote version * 在线更新界面整体美化设计 * 在线更新改造无感覆盖安装 * 检查到有更新显示小红点 * 编译问题 * 修改 --------- Co-authored-by: hea7en <hea7enn@qq.com>
1 parent 6bfa969 commit a207985

File tree

15 files changed

+763
-362
lines changed

15 files changed

+763
-362
lines changed

app.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,13 @@ func (a *App) GetDownloadProgress() string {
24502450
return string(data)
24512451
}
24522452

2453+
// CancelDownload cancels the current download
2454+
func (a *App) CancelDownload() {
2455+
if a.updater != nil {
2456+
a.updater.CancelDownload()
2457+
}
2458+
}
2459+
24532460
// InstallUpdate installs the downloaded update
24542461
func (a *App) InstallUpdate(filePath string) string {
24552462
if a.updater == nil {
@@ -2468,6 +2475,15 @@ func (a *App) InstallUpdate(filePath string) string {
24682475
return string(data)
24692476
}
24702477

2478+
// ApplyUpdate 应用更新并退出程序
2479+
func (a *App) ApplyUpdate(newExePath string) string {
2480+
err := updater.ApplyUpdate(newExePath)
2481+
if err != nil {
2482+
return fmt.Sprintf(`{"success":false,"error":"%s"}`, err.Error())
2483+
}
2484+
return `{"success":true,"message":"update_applying"}`
2485+
}
2486+
24712487
// SendUpdateNotification sends a system notification for updates
24722488
func (a *App) SendUpdateNotification(title, message string) error {
24732489
err := updater.SendNotification(title, message)

frontend/src/i18n/en.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,13 @@ export default {
298298
extractPath: 'File Location',
299299
install_instructions_windows: '1. Close current ccNexus application<br>2. Run the new ccNexus.exe',
300300
install_instructions_macos: '1. Close current ccNexus application<br>2. Drag the new ccNexus.app to Applications folder',
301-
install_instructions_linux: '1. Close current ccNexus application<br>2. Run the new ccNexus executable'
301+
install_instructions_linux: '1. Close current ccNexus application<br>2. Run the new ccNexus executable',
302+
readyToUpdate: 'New version is ready, click the button below to update now',
303+
applyUpdate: 'Update Now',
304+
applying: 'Applying update...',
305+
restartingApp: 'Restarting application...',
306+
applyFailed: 'Failed to apply update',
307+
install_ready_windows: 'Click Update Now button to complete the update automatically'
302308
},
303309
common: {
304310
ok: 'OK',
@@ -308,7 +314,8 @@ export default {
308314
confirm: 'Confirm',
309315
delete: 'Delete',
310316
confirmDeleteTitle: 'Confirm Deletion',
311-
close: 'Close'
317+
close: 'Close',
318+
retry: 'Retry'
312319
},
313320
tips: [
314321
'Tip: You can add multiple API endpoints for automatic failover',

frontend/src/i18n/zh-CN.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,13 @@ export default {
298298
extractPath: '文件位置',
299299
install_instructions_windows: '1. 关闭当前 ccNexus 应用<br>2. 运行新版本的 ccNexus.exe',
300300
install_instructions_macos: '1. 关闭当前 ccNexus 应用<br>2. 将新版本的 ccNexus.app 拖到应用程序文件夹',
301-
install_instructions_linux: '1. 关闭当前 ccNexus 应用<br>2. 运行新版本的 ccNexus 可执行文件'
301+
install_instructions_linux: '1. 关闭当前 ccNexus 应用<br>2. 运行新版本的 ccNexus 可执行文件',
302+
readyToUpdate: '新版本已准备就绪,点击下方按钮立即更新',
303+
applyUpdate: '立即更新',
304+
applying: '正在应用更新...',
305+
restartingApp: '正在重启应用...',
306+
applyFailed: '应用更新失败',
307+
install_ready_windows: '点击立即更新按钮自动完成更新'
302308
},
303309
common: {
304310
ok: '确定',
@@ -308,7 +314,8 @@ export default {
308314
confirm: '确认',
309315
delete: '删除',
310316
confirmDeleteTitle: '确认删除',
311-
close: '关闭'
317+
close: '关闭',
318+
retry: '重试'
312319
},
313320
tips: [
314321
'小贴士:您可以添加多个 API 端点实现自动故障转移',

frontend/src/modules/modal.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { t } from '../i18n/index.js';
22
import { escapeHtml } from '../utils/format.js';
33
import { addEndpoint, updateEndpoint, removeEndpoint, testEndpoint, updatePort } from './config.js';
44
import { setTestState, clearTestState } from './endpoints.js';
5+
import { hideAboutBadge } from './updater.js';
56

67
let currentEditIndex = -1;
78

@@ -365,6 +366,7 @@ export function closePortModal() {
365366
// Welcome Modal
366367
export async function showWelcomeModal() {
367368
document.getElementById('welcomeModal').classList.add('active');
369+
hideAboutBadge();
368370

369371
try {
370372
const version = await window.go.main.App.GetVersion();

frontend/src/modules/ui.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ export function initUI() {
2020
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/>
2121
</svg>
2222
</button>
23-
<button class="header-link" onclick="window.showWelcomeModal()" title="${t('header.about')}">
23+
<button class="header-link about-btn" id="aboutBtn" onclick="window.showWelcomeModal()" title="${t('header.about')}">
2424
📖
25+
<span class="update-badge" id="updateBadge"></span>
2526
</button>
2627
<button class="header-link" onclick="window.showSettingsModal()" title="${t('settings.title')}">
2728
⚙️
@@ -385,8 +386,9 @@ export function initUI() {
385386
<button class="btn btn-secondary" onclick="window.showChangelogModal()">
386387
${t('welcome.changelog')}
387388
</button>
388-
<button class="btn btn-secondary" onclick="window.checkForUpdates()">
389+
<button class="btn btn-secondary check-update-btn" onclick="window.checkForUpdates()">
389390
🔄 ${t('update.checkForUpdates')}
391+
<span class="update-badge" id="checkUpdateBadge"></span>
390392
</button>
391393
</div>
392394
</div>

0 commit comments

Comments
 (0)