Skip to content

Commit d5c746b

Browse files
committed
fix: 修复 macOS 重启自动更新以及手动点击重启更新不生效的问题
1 parent 5941cae commit d5c746b

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

apps/electron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@proma/electron",
3-
"version": "0.9.19",
3+
"version": "0.9.20",
44
"description": "Proma next gen ai software with general agents - Electron App",
55
"main": "dist/main.cjs",
66
"author": {

apps/electron/src/main/lib/updater/auto-updater.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { autoUpdater } from 'electron-updater'
9-
import type { BrowserWindow } from 'electron'
9+
import { BrowserWindow, app } from 'electron'
1010
import type { UpdateStatus } from './updater-types'
1111
import { UPDATER_IPC_CHANNELS } from './updater-types'
1212

@@ -32,7 +32,14 @@ export function getUpdateStatus(): UpdateStatus {
3232

3333
/** 手动触发检查更新 */
3434
export async function checkForUpdates(): Promise<void> {
35+
// 已在下载中或已下载完成,不重复检查
36+
if (currentStatus.status === 'downloading' || currentStatus.status === 'downloaded') {
37+
console.log('[更新] 跳过检查:已在下载中或已下载完成')
38+
return
39+
}
40+
3541
try {
42+
setStatus({ status: 'checking' })
3643
await autoUpdater.checkForUpdates()
3744
} catch (err) {
3845
console.error('[更新] 检查更新失败:', err)
@@ -45,7 +52,15 @@ export async function checkForUpdates(): Promise<void> {
4552

4653
/** 退出并安装已下载的更新 */
4754
export function quitAndInstall(): void {
48-
autoUpdater.quitAndInstall(false, true)
55+
// 移除所有窗口的 close 监听器,避免 preventDefault 阻止退出
56+
for (const w of BrowserWindow.getAllWindows()) {
57+
w.removeAllListeners('close')
58+
}
59+
60+
// 延迟调用确保 IPC 响应已发送回渲染进程
61+
setImmediate(() => {
62+
autoUpdater.quitAndInstall(true, true)
63+
})
4964
}
5065

5166
/** 清理更新器资源(定时器等) */

apps/electron/src/renderer/components/settings/UpdateDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function UpdateDialog(): React.ReactElement | null {
5757
if (updateStatus.status === 'downloaded' && !open && dialogVersion) {
5858
setOpen(true)
5959
}
60-
}, [updateStatus.status, updateStatus.version])
60+
}, [updateStatus.status, updateStatus.version, open, dialogVersion])
6161

6262
const handleQuitAndInstall = (): void => {
6363
window.electronAPI.updater?.quitAndInstall()

0 commit comments

Comments
 (0)