Skip to content

Commit

Permalink
chore: Modify manual detection update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
1943time committed Jan 12, 2024
1 parent 9be4bc3 commit ae542cf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/main/appMenus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const getSystemMenus = () => {
{
label: zh ? '检查更新' : 'Check for Updates',
click: () => {
ipcMain.emit('check-updated')
BrowserWindow.getFocusedWindow()?.webContents.send('check-updated')
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ autoUpdater.autoInstallOnAppQuit = true

export class AppUpdate {
cancelToken?: CancellationToken
manual = false
get win() {
return BrowserWindow.getFocusedWindow()
}
constructor() {
// setTimeout(() => {
// autoUpdater.checkForUpdatesAndNotify()
// }, 3000)

ipcMain.handle('check-updated', () => {
this.manual = true
autoUpdater.checkForUpdatesAndNotify()
return new Promise((resolve, reject) => {
autoUpdater.once('update-available', resolve)
Expand All @@ -51,7 +45,7 @@ export class AppUpdate {
})

autoUpdater.on('update-not-available', (info) => {
this.win?.webContents.send('update-not-available', this.manual)
this.win?.webContents.send('update-not-available')
})

autoUpdater.on('error', (e, message) => {
Expand Down
31 changes: 22 additions & 9 deletions src/renderer/src/components/Update.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {observer} from 'mobx-react-lite'
import {Button, Checkbox, Modal, notification, Progress, Space} from 'antd'
import {useLocalState} from '../hooks/useLocalState'
import {useCallback, useEffect} from 'react'
import {useCallback, useEffect, useRef} from 'react'
import {message$} from '../utils'
import {configStore} from '../store/config'
import {openConfirmDialog$} from './ConfirmDialog'
Expand All @@ -23,6 +23,7 @@ export const Update = observer(() => {
zhInfo: [] as string[]
}
})
const checkTimer = useRef(0)
const downLoad = useCallback(() => {
window.open(`https://github.com/1943time/bluestone/releases/latest`)
}, [])
Expand All @@ -49,28 +50,40 @@ export const Update = observer(() => {
})
runInAction(() => configStore.enableUpgrade = true)
} else {
setTimeout(check, 60 * 1000 * 60)
checkTimer.current = window.setTimeout(check, 60 * 1000 * 60)
}
return !!res.github
}, [])

const [api, contextHolder] = notification.useNotification()
useEffect(() => {
check()
ipcRenderer.on('check-updated', e => {
setState({manual: true})
clearTimeout(checkTimer.current)
check().then((updated) => {
if (updated) {
runInAction(() => configStore.openUpdateDialog = true)
} else {
message$.next({
type: 'info',
content: configStore.zh ? '没有可用的更新' : 'No updates are available'
})
}
})
})
ipcRenderer.on('update-progress', (e, data) => {
const percent = (data.percent as number || 0).toFixed(1)
setState({percent: +percent})
})

ipcRenderer.on('update-not-available', (e, manual) => {
if (!manual) return
message$.next({
type: 'info',
content: configStore.zh ? '没有可用的更新' : 'No updates are available'
})
})
// ipcRenderer.on('update-not-available', (e, manual) => {
// if (!manual) return
// message$.next({
// type: 'info',
// content: configStore.zh ? '没有可用的更新' : 'No updates are available'
// })
// })

ipcRenderer.on('update-error', (e, err) => {
console.error('update-error', err)
Expand Down

0 comments on commit ae542cf

Please sign in to comment.