关于界面完成更新

This commit is contained in:
yuruo 2024-07-15 09:47:36 +08:00
parent 53cde241f3
commit 23db625c18
7 changed files with 17 additions and 26 deletions

View File

@ -1,6 +1,6 @@
{
"name": "automate",
"version": "2.2.1",
"version": "2.2.3",
"description": "An Electron application with React and TypeScript",
"main": "./out/main/index.js",
"author": "example.com",

View File

@ -2,6 +2,7 @@ import {app, ipcMain, IpcMainEvent } from "electron"
import { getWindowByName, getWindowByEvent} from "./windows"
import { autoUpdater } from 'electron-updater'
import { shutdownServer } from "./serverUtilts"
import updateRegister from "./updateRegister"
ipcMain.on('openWindow', (_event: IpcMainEvent, name: WindowNameType, router_url="") => {
@ -24,13 +25,13 @@ ipcMain.handle('getVersion', async (_event) => {
ipcMain.on('restartApp', async () => {
await shutdownServer()
app.relaunch()
app.quit()
autoUpdater.quitAndInstall()
})
// 检测更新
ipcMain.on('checkUpdate', (event) => {
const win = getWindowByEvent(event);
updateRegister(win)
autoUpdater.checkForUpdates();
win.webContents.send('updateInfo', `正在检查更新...`)

View File

@ -1,4 +1,3 @@
import { is } from "@electron-toolkit/utils"
import { BrowserWindow } from "electron"
import { autoUpdater } from "electron-updater"
@ -7,9 +6,7 @@ export default (win: BrowserWindow) => {
autoUpdater.autoDownload = false
//退出时自动安装更新
autoUpdater.autoInstallOnAppQuit = true
// 检查更新
!is.dev && autoUpdater.checkForUpdates()
autoUpdater.removeAllListeners()
autoUpdater.on('update-available', (_info) => {
win.webContents.send('updateInfo', `发现新的版本!}`)
autoUpdater.downloadUpdate()
@ -22,6 +19,7 @@ export default (win: BrowserWindow) => {
autoUpdater.on('update-downloaded', async () => {
win.webContents.send('updateInfo', `下载完成,重启软件完成更新!`)
});
// 监听下载进度

View File

@ -3,7 +3,6 @@ import { OptionsType, createWindow} from "./createWindow"
const { exec } = require('child_process');
import { is } from '@electron-toolkit/utils'
import { shutdownServer } from "./serverUtilts";
import updateRegister from "./updateRegister";
export const config = {
search: {
id: 0,
@ -106,7 +105,6 @@ function createTray(){
app.whenReady().then(() => {
createTray()
const win = getWindowByName('search')
updateRegister(win)
win.on('blur', () => {
win.hide()
})

View File

@ -17,7 +17,6 @@ declare global {
checkUpdate: () => void,
updateInfo: (fn: (value: string) => void) => void,
restartApp: () => void,
registerUpdate: () => void,
}
}
}

View File

@ -39,9 +39,6 @@ const api = {
},
restartApp: () => {
ipcRenderer.send("restartApp")
},
registerUpdate: () => {
ipcRenderer.send("registerUpdate")
}
}

View File

@ -4,22 +4,22 @@ import { useEffect, useState } from "react";
function About() {
const [version, setVersion] = useState('');
const [updateInfo, setUpdateInfo] = useState('');
useEffect(() => {
window.api.updateInfo((value)=>{
if(value === '软件更新失败,重试中...'){
window.api.updateInfo((value) => {
if (value === '软件更新失败,重试中...') {
window.api.checkUpdate();
}
setUpdateInfo(value)
})
window.api.checkUpdate();
window.api.getVersion().then((res) => {
setVersion(res)
})
}, []);
return (
<main className="flex items-center justify-center h-screen">
<div className="flex flex-col items-center">
@ -27,19 +27,17 @@ function About() {
autoMate
</h1>
v{version}
<div>
<div className="text-sm mt-5 mr-5">
{updateInfo}
</div>
{updateInfo === '下载完成,重启软件完成更新!' && (
<div>
<Button type="primary" onClick={()=>{
window.api.restartApp()
}}></Button>
</div>)}
</div>
<Button type="primary" className="flex items-center" onClick={() => {
window.api.restartApp()
}}></Button>
)}
</div>
</main>
);
}