mirror of
https://github.com/yuruotong1/autoMate.git
synced 2025-12-26 05:16:21 +08:00
在搜索界面增加版本号和更新检测
This commit is contained in:
parent
752a77524b
commit
699243fa98
@ -4,7 +4,7 @@ import "./db"
|
||||
import "./windows"
|
||||
import "./ipc"
|
||||
import "./shortcut"
|
||||
|
||||
import "./updateRegister"
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
|
||||
@ -2,7 +2,6 @@ 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="") => {
|
||||
@ -31,17 +30,9 @@ ipcMain.on('restartApp', async () => {
|
||||
|
||||
// 检测更新
|
||||
ipcMain.on('checkUpdate', (event) => {
|
||||
|
||||
const win = getWindowByEvent(event);
|
||||
autoUpdater.checkForUpdates();
|
||||
win.webContents.send('updateInfo', `正在检查更新...`)
|
||||
|
||||
|
||||
})
|
||||
|
||||
// 注册更新事件
|
||||
ipcMain.on('registerUpdate', (event) => {
|
||||
const win = getWindowByEvent(event);
|
||||
updateRegister(win)
|
||||
})
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { is } from "@electron-toolkit/utils"
|
||||
import { BrowserWindow } from "electron"
|
||||
import { autoUpdater } from "electron-updater"
|
||||
|
||||
@ -6,6 +7,8 @@ export default (win: BrowserWindow) => {
|
||||
autoUpdater.autoDownload = false
|
||||
//退出时自动安装更新
|
||||
autoUpdater.autoInstallOnAppQuit = true
|
||||
// 检查更新
|
||||
!is.dev && autoUpdater.checkForUpdates()
|
||||
|
||||
autoUpdater.on('update-available', (_info) => {
|
||||
win.webContents.send('updateInfo', `发现新的版本!}`)
|
||||
|
||||
@ -3,6 +3,7 @@ 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,
|
||||
@ -105,6 +106,7 @@ function createTray(){
|
||||
app.whenReady().then(() => {
|
||||
createTray()
|
||||
const win = getWindowByName('search')
|
||||
updateRegister(win)
|
||||
win.on('blur', () => {
|
||||
win.hide()
|
||||
})
|
||||
|
||||
@ -1,10 +1,25 @@
|
||||
import useSearch from "@renderer/hooks/useSearch"
|
||||
import { SettingOne } from "@icon-park/react"
|
||||
import { Input } from "antd"
|
||||
import { Button, Input } from "antd"
|
||||
import { useStore } from "@renderer/store/useStore"
|
||||
import { useEffect, useState } from "react"
|
||||
export default function Search(): JSX.Element {
|
||||
const {handleSearch} = useSearch()
|
||||
const search = useStore((state)=>state.search)
|
||||
const [version, setVersion] = useState('')
|
||||
const [updateInfo, setUpdateInfo] = useState('')
|
||||
useEffect(() => {
|
||||
window.api.getVersion().then((res) => {
|
||||
setVersion(res)
|
||||
})
|
||||
window.api.updateInfo((value)=>{
|
||||
if(value === '软件更新失败,重试中...'){
|
||||
window.api.checkUpdate();
|
||||
}
|
||||
})
|
||||
|
||||
window.api.checkUpdate();
|
||||
}, []);
|
||||
return (
|
||||
<main className="bg-slate-50 p-3 rounded-lg drag" >
|
||||
<div className="bg-slate-200 p-3 rounded-l flex items-center gap-1 no-drag">
|
||||
@ -25,9 +40,13 @@ export default function Search(): JSX.Element {
|
||||
/>
|
||||
</div>
|
||||
<section className="text-center text-slate-600 text-xs mt-2 no-drag select-none">
|
||||
autoMate
|
||||
<div>
|
||||
autoMate V{version}
|
||||
<span className="text-blue-600 cursor-pointer" onClick={()=>window.api.openWindow('config')}>点击配置</span>
|
||||
</div>
|
||||
{updateInfo==='成功' && <Button type="primary" onClick={()=>window.api.restart()}>重启</Button>}
|
||||
</section>
|
||||
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ function About() {
|
||||
const [updateInfo, setUpdateInfo] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
window.api.registerUpdate()
|
||||
window.api.updateInfo((value)=>{
|
||||
if(value === '软件更新失败,重试中...'){
|
||||
window.api.checkUpdate();
|
||||
@ -33,9 +32,12 @@ function About() {
|
||||
{updateInfo}
|
||||
</div>
|
||||
|
||||
{updateInfo === '下载完成,重启软件完成更新!' && <Button type="primary" onClick={()=>{
|
||||
{updateInfo === '下载完成,重启软件完成更新!' && (
|
||||
<div>检测到新版本,点击重启完成更新!
|
||||
<Button type="primary" onClick={()=>{
|
||||
window.api.restartApp()
|
||||
}}>重启软件</Button>}
|
||||
}}>重启</Button>
|
||||
</div>)}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user