Skip to content

Commit

Permalink
feat:Detect new upgrade on launch
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsupa597 committed Jul 11, 2023
1 parent c6fa609 commit 6bd0f9a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 9 deletions.
27 changes: 20 additions & 7 deletions packages/neuron-ui/src/components/GeneralSetting/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import React, { useCallback, useState, useMemo, useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { useSearchParams } from 'react-router-dom'
Expand All @@ -20,7 +21,7 @@ import styles from './generalSetting.module.scss'

interface UpdateDownloadStatusProps {
show: boolean
onCancel: () => void
onCancel: (status?: string) => void
progress: number
newVersion: string
releaseDate: string
Expand Down Expand Up @@ -69,7 +70,7 @@ const UpdateDownloadStatus = ({
onConfirm={handleConfirm}
disabled={!available}
confirmText={t('updates.install-update')}
onCancel={onCancel}
onCancel={() => onCancel('checked')}
title={t('updates.update-available')}
confirmProps={{
'data-method': 'download',
Expand Down Expand Up @@ -135,13 +136,14 @@ const GeneralSetting = ({ updater }: GeneralSettingProps) => {
const [showLangDialog, setShowLangDialog] = useState(false)
const [searchParams] = useSearchParams()
const [errorMsg, setErrorMsg] = useState('')
const [dialogType, setDialogType] = useState<'' | 'checking' | 'updating' | 'updated'>('')
const [dialogType, setDialogType] = useState<'' | 'checking' | 'checked' | 'updating' | 'updated'>('')

const version = useMemo(() => {
return getVersion()
}, [])

useEffect(() => {
console.log(searchParams, 'searchParams-----innner')
const checkUpdate = searchParams.get('checkUpdate')
if (checkUpdate === '1') {
checkForUpdates()
Expand All @@ -162,10 +164,15 @@ const GeneralSetting = ({ updater }: GeneralSettingProps) => {
setDialogType('checking')
return
}
if (updater.version || updater.downloadProgress > 0) {
if (updater.version) {
setDialogType('checked')
return
}
if (updater.downloadProgress > 0) {
setDialogType('updating')
return
}

setDialogType('')
}, [updater, setDialogType, setErrorMsg])

Expand All @@ -189,6 +196,7 @@ const GeneralSetting = ({ updater }: GeneralSettingProps) => {

return (
<div className={styles.container}>
{/* 设置默认页面 */}
<div className={styles.content}>
<p>
{t('settings.general.version')} v{version}
Expand All @@ -211,6 +219,7 @@ const GeneralSetting = ({ updater }: GeneralSettingProps) => {
</button>
</div>

{/* 接口错误 */}
<AlertDialog
show={!!errorMsg}
title={t(`updates.check-updates`)}
Expand All @@ -219,6 +228,7 @@ const GeneralSetting = ({ updater }: GeneralSettingProps) => {
onCancel={() => setErrorMsg('')}
/>

{/* 检查更新弹窗 */}
<Dialog
show={['checking', 'updated'].includes(dialogType)}
showCancel={false}
Expand All @@ -236,10 +246,13 @@ const GeneralSetting = ({ updater }: GeneralSettingProps) => {
</div>
</Dialog>

{/* 下载弹窗 */}
<UpdateDownloadStatus
show={dialogType === 'updating'}
onCancel={() => {
cancelDownloadUpdate()
show={dialogType === 'updating' || dialogType === 'checked'}
onCancel={status => {
if (status !== 'checked') {
cancelDownloadUpdate()
}
setDialogType('')
}}
progress={updater.downloadProgress}
Expand Down
28 changes: 27 additions & 1 deletion packages/neuron-ui/src/containers/Navbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* eslint-disable no-console */
import React, { useCallback, useEffect, useState } from 'react'
import { createPortal } from 'react-dom'
import { useLocation, NavLink, useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { useState as useGlobalState } from 'states'
import { checkForUpdates } from 'services/remote'
import Dot from 'widgets/Dot'
import Logo from 'widgets/Icons/Logo.png'
import {
Overview,
Expand Down Expand Up @@ -71,6 +74,7 @@ const Navbar = () => {
const {
wallet: { name },
settings: { wallets = [] },
updater: { version },
} = neuronWallet
const [t, i18n] = useTranslation()
useOnLocaleChange(i18n)
Expand All @@ -83,6 +87,12 @@ const Navbar = () => {
}
}, [computedKey])

useEffect(() => {
console.log('checkForUpdates-----fetch automatically')

checkForUpdates()
}, [checkForUpdates])

const [menuExpanded, setMenuExpanded] = useState(true)
const onClickExpand = useCallback(() => {
setMenuExpanded(v => !v)
Expand All @@ -93,6 +103,13 @@ const Navbar = () => {
return null
}

useEffect(() => {
console.log('start check for updates automatically')
checkForUpdates()
}, [])

console.log(version, 'version')

return (
<aside className={styles.sidebar} data-expanded={menuExpanded}>
<button
Expand Down Expand Up @@ -121,9 +138,18 @@ const Navbar = () => {
<React.Fragment key={item.key}>
<MenuButton menu={item} selectedKey={selectedKey}>
{item.icon}
<span>{t(item.name)}</span>

{version && item.key === RoutePath.Settings ? (
<Dot>
<span>{t(item.name)}</span>
</Dot>
) : (
<span>{t(item.name)}</span>
)}

{item.children?.length && <ArrowOpenRight className={styles.arrow} />}
</MenuButton>

{item.children?.length && item.key === selectedKey && (
<div className={styles.child}>
<div className={styles.leftLine} />
Expand Down
15 changes: 15 additions & 0 deletions packages/neuron-ui/src/widgets/Dot/dot.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@import '../../styles/theme.scss';

.dot {
position: relative;

&::after {
content: '';
width: 8px;
height: 8px;
border-radius: 50%;
background-color: #ff1e1e;
position: absolute;
top: 20%;
}
}
8 changes: 8 additions & 0 deletions packages/neuron-ui/src/widgets/Dot/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import styles from './dot.module.scss'

const Dot = ({ children }: { children: React.ReactChild }) => {
return <div className={styles.dot}>{children}</div>
}

export default Dot
2 changes: 1 addition & 1 deletion packages/neuron-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productName": "Neuron",
"description": "CKB Neuron Wallet",
"homepage": "https://www.nervos.org/",
"version": "0.110.2",
"version": "0.106.0",
"private": true,
"author": {
"name": "Nervos Core Dev",
Expand Down

0 comments on commit 6bd0f9a

Please sign in to comment.