增加自动更新(未完成)

This commit is contained in:
yuruo 2024-07-08 17:56:57 +08:00
parent 94a34bad55
commit b32b440cd3
5 changed files with 72 additions and 22 deletions

2
app/package-lock.json generated
View File

@ -25,7 +25,7 @@
"better-sqlite3": "^11.0.0",
"clsx": "^2.1.1",
"dayjs": "^1.11.11",
"electron-updater": "^6.1.7",
"electron-updater": "^6.2.1",
"localforage": "^1.10.0",
"mantine-contextmenu": "^7.10.2",
"match-sorter": "^6.3.4",

View File

@ -5,6 +5,7 @@
"main": "./out/main/index.js",
"author": "example.com",
"homepage": "https://electron-vite.org",
"repository": "https://github.com/yuruotong1/autoMate/tree/master/app",
"scripts": {
"format": "prettier --write .",
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
@ -22,7 +23,6 @@
},
"dependencies": {
"@ai-sdk/openai": "^0.0.33",
"openai": "^4.24.7",
"@ant-design/pro-chat": "^1.14.2",
"@ant-design/pro-editor": "^1.2.1",
"@codemirror/lang-python": "^6.1.6",
@ -38,11 +38,12 @@
"better-sqlite3": "^11.0.0",
"clsx": "^2.1.1",
"dayjs": "^1.11.11",
"electron-updater": "^6.1.7",
"electron-updater": "^6.2.1",
"localforage": "^1.10.0",
"mantine-contextmenu": "^7.10.2",
"match-sorter": "^6.3.4",
"mockjs": "^1.1.0",
"openai": "^4.24.7",
"react-router-dom": "^6.23.1",
"sort-by": "^0.0.2",
"zustand": "^4.5.2"

View File

@ -0,0 +1,66 @@
import { is } from '@electron-toolkit/utils'
import { BrowserWindow, dialog, shell } from 'electron'
import { autoUpdater } from 'electron-updater'
//自动下载更新
autoUpdater.autoDownload = false
//退出时自动安装更新
autoUpdater.autoInstallOnAppQuit = false
export default (win: BrowserWindow) => {
//检查是否有更新
if (!is.dev) autoUpdater.checkForUpdates()
//有新版本时
autoUpdater.on('update-available', (_info) => {
dialog
.showMessageBox({
type: 'warning',
title: '更新提示',
message: '有新版本发布了',
buttons: ['更新', '取消'],
cancelId: 1
})
.then((res) => {
if (res.response == 0) {
//开始下载更新
autoUpdater.downloadUpdate()
}
})
})
//没有新版本时
autoUpdater.on('update-not-available', (_info) => {
// dialog.showMessageBox({
// type: 'info',
// message: `你已经是最新版本`
// })
})
//更新下载完毕
autoUpdater.on('update-downloaded', (_info) => {
//退出并安装更新
autoUpdater.quitAndInstall()
})
//更新发生错误
autoUpdater.on('error', (_info) => {
dialog
.showMessageBox({
type: 'warning',
title: '更新提示',
message: '软件更新失败',
buttons: ['网站下载', '取消更新'],
cancelId: 1
})
.then((res) => {
if (res.response == 0) {
shell.openExternal('https://github.com/yuruotong1/autoMate/releases')
}
})
})
// 监听下载进度
autoUpdater.on('download-progress', (progress) => {
win.webContents.send('downloadProgress', progress)
})
}

View File

@ -2,6 +2,7 @@ import { BrowserWindow, IpcMainEvent, IpcMainInvokeEvent, Menu, Tray, app } from
import { OptionsType, createWindow} from "./createWindow"
const { exec } = require('child_process');
import { is } from '@electron-toolkit/utils'
import autoMateServer from './autoUpdater'
export const config = {
search: {
id: 0,
@ -108,6 +109,7 @@ app.whenReady().then(() => {
console.error(`stderr: ${stderr}`);
});}
autoMateServer(win)
// getWindowByName('code')
// getWindowByName('config')

View File

@ -1,19 +0,0 @@
cd app
set "target_dir=.\dist"
del /f /q "%target_dir%\*.*"
for /d %%i in ("%target_dir%\*") do rmdir /s /q "%%i"
call npm run build:win
move .\dist\win-unpacked\resources\app.asar.unpacked\resources\icon.png .\dist\win-unpacked\resources
cd ..
cd server
call .\.venv\Scripts\activate
pip install -r requirements.txt
call echo y | pyinstaller main.spec
xcopy .\.venv\Lib\site-packages\litellm\*.json .\dist\autoMateServer\_internal\litellm\ /E /H /F /I /Y
xcopy .\dist\autoMateServer\* ..\app\dist\win-unpacked\ /E /H /F /I /Y
cd ..\app\dist
REN win-unpacked autoMate
powershell Compress-Archive -Path autoMate -DestinationPath autoMate.zip