yangjie #49
|
|
@ -9,62 +9,64 @@ const { confirm } = Modal;
|
|||
const UpdateModal = forwardRef((_props: any, ref: any) => {
|
||||
useImperativeHandle(ref, () => ({
|
||||
changeModal: (data: any) => {
|
||||
try {
|
||||
let dataJson = JSON.parse(data)
|
||||
if (dataJson.type === '0') { // 打开弹窗
|
||||
setProgress(res => {
|
||||
if (res) {
|
||||
if (JSON.stringify(data).includes('Error') || JSON.stringify(data).includes('{}')) {
|
||||
setIsError(res => {
|
||||
if (res) {
|
||||
setIsError(false)
|
||||
confirm({
|
||||
keyboard: false,
|
||||
title: '提示',
|
||||
icon: <ExclamationCircleFilled />,
|
||||
content: `更新失败,请尝试手动更新!`,
|
||||
centered: true,
|
||||
okText: '立即更新',
|
||||
wrapClassName: 'hideCancelText',
|
||||
cancelText: '',
|
||||
async onOk() {
|
||||
isVersion((bool: boolean, req: any) => {
|
||||
if (bool && req) {
|
||||
window.electron.getEnv().then(res => {
|
||||
location.href = `${getUpdateUrl(res)}/${req.path}`
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
return res
|
||||
})
|
||||
} else {
|
||||
try {
|
||||
let dataJson = JSON.parse(data)
|
||||
if (dataJson.type === '0') { // 打开弹窗
|
||||
setProgress(res => {
|
||||
if (res) {
|
||||
|
||||
} else {
|
||||
window.electron.onDownload('1')
|
||||
} else {
|
||||
window.electron.onDownload('1')
|
||||
}
|
||||
return res
|
||||
})
|
||||
} else if (dataJson.type === '1') { // 下载中 返回进度值
|
||||
if (dataJson.value === 100 && location.hash.indexOf('/meeting') === -1) {
|
||||
setIsUpdateModal(true)
|
||||
getContent()
|
||||
}
|
||||
return res
|
||||
})
|
||||
} else if (dataJson.type === '1') { // 下载中 返回进度值
|
||||
if (dataJson.value === 100 && location.hash.indexOf('/meeting') === -1) {
|
||||
setIsUpdateModal(true)
|
||||
getContent()
|
||||
}
|
||||
setProgress(dataJson.value.toFixed(2))
|
||||
} else if (dataJson.type === '2') { // 下载完成
|
||||
setProgress(100)
|
||||
if (location.hash.indexOf('/meeting') === -1) {
|
||||
setIsUpdateModal(true)
|
||||
getContent()
|
||||
}
|
||||
} else if (dataJson.type === '3') {
|
||||
if (location.hash.indexOf('/meeting') === -1) {
|
||||
setIsUpdateModal(true)
|
||||
getContent()
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (typeof data === 'string' && data.includes('Error')) {
|
||||
setIsError(res => {
|
||||
if (res) {
|
||||
setIsError(false)
|
||||
confirm({
|
||||
keyboard: false,
|
||||
title: '提示',
|
||||
icon: <ExclamationCircleFilled />,
|
||||
content: `更新失败,请尝试手动更新!`,
|
||||
centered: true,
|
||||
okText: '立即更新',
|
||||
wrapClassName: 'hideCancelText',
|
||||
cancelText: '',
|
||||
async onOk() {
|
||||
isVersion((bool: boolean, req: any) => {
|
||||
if (bool && req) {
|
||||
window.electron.getEnv().then(res => {
|
||||
location.href = `${getUpdateUrl(res)}/${req.path}`
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
})
|
||||
setProgress(dataJson.value.toFixed(2))
|
||||
} else if (dataJson.type === '2') { // 下载完成
|
||||
setProgress(100)
|
||||
if (location.hash.indexOf('/meeting') === -1) {
|
||||
setIsUpdateModal(true)
|
||||
getContent()
|
||||
}
|
||||
return res
|
||||
})
|
||||
} else if (dataJson.type === '3') {
|
||||
if (location.hash.indexOf('/meeting') === -1) {
|
||||
setIsUpdateModal(true)
|
||||
getContent()
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue