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
url: https://example.com/auto-updates
url: http://192.168.1.7:5500/update
updaterCacheDirName: cvpilot-desktop-updater

View File

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

View File

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

View File

@ -3,7 +3,7 @@ import { join } from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import icon from '../../resources/icon.png?asset'
import { setupIpcHandle } from './ipc'
import './sqlite3'
// import './sqlite3'
import { setupAutoUpdater } from './updater'
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
@ -8,6 +9,7 @@ export const setupIpcHandle = (): void => {
ipcMain.handle('check-for-updates', (event) => {
console.log('检查更新')
autoUpdater.checkForUpdates()
console.log('执行')
})
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'
/**
* 文档地址: 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) => {
// 配置更新服务器地址
const updateServerUrl = `http://192.168.1.7:5500/update/${process.platform}/${app.getVersion()}`
console.log(app.getVersion())
const updateServerUrl = `https://assets.maxshader.com`
const isDevelopment = process.env.NODE_ENV === 'development'
if (isDevelopment) {
// 强制在开发环境进行更新检查
autoUpdater.forceDevUpdateConfig = true
}
// 关闭自动更新
autoUpdater.autoDownload = false
// 设置自动更新的 feed URL
autoUpdater.setFeedURL({ provider: 'generic', url: updateServerUrl })
console.log(autoUpdater.getFeedURL())
autoUpdater.on('update-downloaded', (e) => {
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('update-downloaded', (res) => {
console.log('下载完成')
autoUpdater.quitAndInstall()
})
autoUpdater.on('checking-for-update', () => {
console.log('checking-for-update,开始检查更新')
})
autoUpdater.on('update-available', () => {
autoUpdater.on('update-available', (info) => {
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) => {

View File

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