Skip to content

Commit b267321

Browse files
committed
feat: Connect updater events to UI
1 parent bcafce8 commit b267321

4 files changed

Lines changed: 26 additions & 25 deletions

File tree

packages/neuron-ui/src/components/GeneralSetting/index.tsx

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import React, { useCallback, useState } from 'react'
1+
import React, { useContext, useCallback, useState } from 'react'
22
import { useTranslation } from 'react-i18next'
33
import { Stack, PrimaryButton, Spinner, Text, ProgressIndicator } from 'office-ui-fabric-react'
4+
import { NeuronWalletContext } from 'states/stateProvider'
45
import { StateWithDispatch } from 'states/stateProvider/reducer'
56
import { addPopup } from 'states/stateProvider/actionCreators'
67
import { checkForUpdates, downloadUpdate, installUpdate, clearCellCache } from 'services/remote'
@@ -26,7 +27,7 @@ const UpdateDownloadStatus = ({
2627
<Stack horizontal horizontalAlign="start">
2728
<PrimaryButton
2829
onClick={download}
29-
disabled={available}
30+
disabled={!available}
3031
styles={{
3132
root: {
3233
minWidth: 180,
@@ -78,23 +79,19 @@ const UpdateDownloadStatus = ({
7879

7980
const GeneralSetting = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch>) => {
8081
const [t] = useTranslation()
81-
const [clearing, setClearing] = useState(false)
82-
const [checkingUpdates, setCheckingUpdates] = useState(false) // TODO: checkingUpdates should be fetched from backend
83-
const [downloadingUpdate] = useState(false)
82+
const { updater } = useContext(NeuronWalletContext)
83+
const [clearingCache, setClearingCache] = useState(false)
8484

8585
const checkUpdates = useCallback(() => {
86-
setCheckingUpdates(true)
87-
setTimeout(() => {
88-
checkForUpdates()
89-
}, 100)
90-
}, [dispatch])
86+
checkForUpdates()
87+
}, [])
9188

9289
const clearCache = useCallback(() => {
93-
setClearing(true)
90+
setClearingCache(true)
9491
setTimeout(() => {
9592
clearCellCache().finally(() => {
9693
addPopup('clear-cache-successfully')(dispatch)
97-
setClearing(false)
94+
setClearingCache(false)
9895
})
9996
}, 100)
10097
}, [dispatch])
@@ -103,20 +100,20 @@ const GeneralSetting = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch>)
103100
<Stack tokens={{ childrenGap: 15 }}>
104101
<Stack>
105102
<Stack horizontal horizontalAlign="start">
106-
{downloadingUpdate ? (
107-
<UpdateDownloadStatus progress={1} newVersion="v0.25.2" />
103+
{updater.version !== '' || updater.downloadProgress >= 0 ? (
104+
<UpdateDownloadStatus progress={updater.downloadProgress} newVersion={updater.version} />
108105
) : (
109106
<PrimaryButton
110107
onClick={checkUpdates}
111-
disabled={checkingUpdates}
108+
disabled={updater.checking}
112109
ariaDescription="Check updates"
113110
styles={{
114111
root: {
115112
minWidth: 180,
116113
},
117114
}}
118115
>
119-
{checkingUpdates ? <Spinner /> : t('updates.check-updates')}
116+
{updater.checking ? <Spinner /> : t('updates.check-updates')}
120117
</PrimaryButton>
121118
)}
122119
</Stack>
@@ -129,15 +126,15 @@ const GeneralSetting = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch>)
129126
<Stack horizontal horizontalAlign="start">
130127
<PrimaryButton
131128
onClick={clearCache}
132-
disabled={clearing}
129+
disabled={clearingCache}
133130
ariaDescription="Clear cache"
134131
styles={{
135132
root: {
136133
minWidth: 180,
137134
},
138135
}}
139136
>
140-
{clearing ? <Spinner /> : t('settings.general.clear-cache')}
137+
{clearingCache ? <Spinner /> : t('settings.general.clear-cache')}
141138
</PrimaryButton>
142139
</Stack>
143140
</Stack>

packages/neuron-ui/src/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
"update-not-available": "There are currently no updates available.",
351351
"updates-found-do-you-want-to-update": "An update ({{version}}) is available, do you want to download and update now?",
352352
"download-update": "Download Update",
353-
"updates-downloaded-about-to-quit-and-install": "Update downloaded. Neuron will quit and install the update...",
353+
"updates-downloaded-about-to-quit-and-install": "Update downloaded. Please quit to install the update.",
354354
"quit-and-install": "Quit and Install"
355355
}
356356
}

packages/neuron-ui/src/locales/zh.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
"update-not-available": "没有可供升级的新版本。",
351351
"updates-found-do-you-want-to-update": "有可供升级的新版本({{version}})。现在进行下载和升级吗?",
352352
"download-update": "下载更新以升级",
353-
"updates-downloaded-about-to-quit-and-install": "下载完成。Neuron 将退出并安装新版本...",
353+
"updates-downloaded-about-to-quit-and-install": "下载完成。请退出并安装新版本。",
354354
"quit-and-install": "退出并安装"
355355
}
356356
}

packages/neuron-wallet/src/controllers/update.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ export default class UpdateController {
3838
autoUpdater.removeAllListeners()
3939

4040
autoUpdater.on('error', error => {
41-
dialog.showErrorBox('Error', error == null ? 'unknown' : (error.stack || error).toString())
42-
4341
UpdateController.isChecking = false
4442
this.notify()
43+
44+
dialog.showErrorBox('Error', error == null ? 'unknown' : (error.stack || error).toString())
4545
})
4646

4747
autoUpdater.on('update-available', (info: UpdateInfo) => {
@@ -50,19 +50,23 @@ export default class UpdateController {
5050
})
5151

5252
autoUpdater.on('update-not-available', () => {
53+
UpdateController.isChecking = false
54+
this.notify()
55+
5356
dialog.showMessageBox({
5457
type: 'info',
5558
message: i18n.t('updater.update-not-available'),
5659
buttons: [i18n.t('common.ok')],
5760
})
61+
})
5862

59-
UpdateController.isChecking = false
60-
this.notify()
63+
autoUpdater.on('download-progress', progress => {
64+
this.notify(progress.percent / 100)
6165
})
6266

6367
autoUpdater.on('update-downloaded', () => {
6468
UpdateController.isChecking = false
65-
this.notify(1, 'toto', '')
69+
this.notify(1)
6670
})
6771
}
6872

0 commit comments

Comments
 (0)