feat: test

This commit is contained in:
mozzie 2024-08-14 12:02:08 +08:00
parent 6c9ba88a4e
commit 900c1c75d4
7 changed files with 42 additions and 29 deletions

View File

@ -1,3 +1,3 @@
provider: generic provider: generic
url: https://example.com/auto-updates url: http://192.168.1.7:5500/update
updaterCacheDirName: cvpilot-desktop-updater updaterCacheDirName: cvpilot-desktop-updater

View File

@ -40,6 +40,6 @@ appImage:
npmRebuild: false npmRebuild: false
publish: publish:
provider: generic provider: generic
url: https://example.com/auto-updates url: https://assets.maxshader.com
electronDownload: electronDownload:
mirror: https://npmmirror.com/mirrors/electron/ mirror: https://npmmirror.com/mirrors/electron/

View File

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

View File

@ -3,7 +3,7 @@ import { join } from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils' import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import icon from '../../resources/icon.png?asset' import icon from '../../resources/icon.png?asset'
import { setupIpcHandle } from './ipc' import { setupIpcHandle } from './ipc'
import './sqlite3' // import './sqlite3'
import { setupAutoUpdater } from './updater' import { setupAutoUpdater } from './updater'
function createWindow(): void { function createWindow(): void {

View File

@ -1,4 +1,5 @@
import { autoUpdater, ipcMain } from 'electron' import { ipcMain } from 'electron'
import { autoUpdater } from 'electron-updater'
/** /**
* ipc signals * ipc signals
@ -8,6 +9,7 @@ export const setupIpcHandle = (): void => {
ipcMain.handle('check-for-updates', (event) => { ipcMain.handle('check-for-updates', (event) => {
console.log('检查更新') console.log('检查更新')
autoUpdater.checkForUpdates() autoUpdater.checkForUpdates()
console.log('执行')
}) })
ipcMain.handle('quit-and-install', () => { ipcMain.handle('quit-and-install', () => {

View File

@ -1,34 +1,44 @@
import { app, BrowserWindow, ipcMain } from 'electron' import { app, BrowserWindow, dialog } from 'electron'
import { autoUpdater } from 'electron-updater' import { autoUpdater } from 'electron-updater'
/** /**
* 文档地址: https://www.electronjs.org/zh/docs/latest/api/auto-updater#event--before-quit-for-update * 文档地址: https://www.electron.build/auto-update
*/ */
export const setupAutoUpdater = (win: BrowserWindow) => { export const setupAutoUpdater = (win: BrowserWindow) => {
// 配置更新服务器地址 // 配置更新服务器地址
const updateServerUrl = `http://192.168.1.7:5500/update/${process.platform}/${app.getVersion()}` const updateServerUrl = `https://assets.maxshader.com`
console.log(app.getVersion())
const isDevelopment = process.env.NODE_ENV === 'development'
if (isDevelopment) {
// 强制在开发环境进行更新检查
autoUpdater.forceDevUpdateConfig = true
}
// 关闭自动更新
autoUpdater.autoDownload = false
// 设置自动更新的 feed URL // 设置自动更新的 feed URL
autoUpdater.setFeedURL({ provider: 'generic', url: updateServerUrl }) autoUpdater.setFeedURL({ provider: 'generic', url: updateServerUrl })
console.log(autoUpdater.getFeedURL()) autoUpdater.on('update-downloaded', (res) => {
console.log('下载完成')
autoUpdater.on('update-downloaded', (e) => { autoUpdater.quitAndInstall()
console.log(e)
ipcMain.emit('update-ready', e)
})
autoUpdater.on('update-not-available', () => {
console.log('update-not-available')
ipcMain.emit('update-not-available', '没有可用更新')
}) })
autoUpdater.on('checking-for-update', () => { autoUpdater.on('checking-for-update', () => {
console.log('checking-for-update,开始检查更新') console.log('checking-for-update,开始检查更新')
}) })
autoUpdater.on('update-available', () => { autoUpdater.on('update-available', (info) => {
console.log('update-available,有可用更新') console.log('update-available,有可用更新')
autoUpdater.downloadUpdate()
})
autoUpdater.on('download-progress', (progress) => {
console.log('下载进度download-progress')
const { bytesPerSecond, percent, transferred, total } = progress
console.log(bytesPerSecond, transferred, total)
win.webContents.send('update-progress', percent)
}) })
autoUpdater.on('error', (error) => { autoUpdater.on('error', (error) => {

View File

@ -1,10 +1,10 @@
import Versions from './components/Versions' import Versions from './components/Versions'
import electronLogo from './assets/electron.svg' import electronLogo from './assets/electron.svg'
import { useEffect } from 'react' import { useEffect, useState } from 'react'
function App(): JSX.Element { function App(): JSX.Element {
const ipcHandle = (): void => window.electron.ipcRenderer.send('ping')
const updateHandle = () => window.api.checkUpdate() const updateHandle = () => window.api.checkUpdate()
const [percent, setPercent] = useState()
useEffect(() => { useEffect(() => {
window.electron.ipcRenderer.on('update-ready', (e, data) => { window.electron.ipcRenderer.on('update-ready', (e, data) => {
@ -27,11 +27,17 @@ function App(): JSX.Element {
}) })
}, []) }, [])
useEffect(() => {
window.electron.ipcRenderer.on('update-progress', (e, data) => {
setPercent(percent)
})
}, [])
return ( return (
<> <>
<img alt="logo" className="logo" src={electronLogo} /> <img alt="logo" className="logo" src={electronLogo} />
<button onClick={updateHandle}>22</button> <button onClick={updateHandle}>1.0.6</button>
<div className="creator">Powered by electron-vite</div> <div className="creator">{percent}</div>
<div className="text"> <div className="text">
Build an Electron app with <span className="react">React</span> Build an Electron app with <span className="react">React</span>
&nbsp;and <span className="ts">TypeScript</span> &nbsp;and <span className="ts">TypeScript</span>
@ -45,11 +51,6 @@ function App(): JSX.Element {
Documentation Documentation
</a> </a>
</div> </div>
<div className="action">
<a target="_blank" rel="noreferrer" onClick={ipcHandle}>
Send IPC
</a>
</div>
</div> </div>
<Versions></Versions> <Versions></Versions>
</> </>