Compare commits
No commits in common. "feat/1.0" and "main" have entirely different histories.
1
.npmrc
1
.npmrc
|
@ -1,4 +1,3 @@
|
|||
electron_mirror=https://npmmirror.com/mirrors/electron/
|
||||
electron_builder_binaries_mirror=https://npmmirror.com/mirrors/electron-builder-binaries/
|
||||
shamefully-hoist=true
|
||||
better_sqlite3_binary_host=https://registry.npmmirror.com/-/binary/better-sqlite3
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
provider: generic
|
||||
url: http://192.168.1.7:5500/update
|
||||
url: https://example.com/auto-updates
|
||||
updaterCacheDirName: cvpilot-desktop-updater
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
appId: com.tavi.app
|
||||
appId: com.electron.app
|
||||
productName: cvpilot-desktop
|
||||
directories:
|
||||
buildResources: build
|
||||
|
@ -40,6 +40,6 @@ appImage:
|
|||
npmRebuild: false
|
||||
publish:
|
||||
provider: generic
|
||||
url: https://assets.maxshader.com
|
||||
url: https://example.com/auto-updates
|
||||
electronDownload:
|
||||
mirror: https://npmmirror.com/mirrors/electron/
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { resolve } from 'path'
|
||||
import { defineConfig, externalizeDepsPlugin, bytecodePlugin } from 'electron-vite'
|
||||
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
export default defineConfig({
|
||||
main: {
|
||||
plugins: [externalizeDepsPlugin(), bytecodePlugin()]
|
||||
plugins: [externalizeDepsPlugin()]
|
||||
},
|
||||
preload: {
|
||||
plugins: [externalizeDepsPlugin(), bytecodePlugin()]
|
||||
plugins: [externalizeDepsPlugin()]
|
||||
},
|
||||
renderer: {
|
||||
resolve: {
|
||||
|
|
12
package.json
12
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cvpilot-desktop",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.0",
|
||||
"description": "An Electron application with React and TypeScript",
|
||||
"main": "./out/main/index.js",
|
||||
"author": "example.com",
|
||||
|
@ -12,8 +12,8 @@
|
|||
"typecheck:web": "tsc --noEmit -p tsconfig.web.json --composite false",
|
||||
"typecheck": "npm run typecheck:node && npm run typecheck:web",
|
||||
"start": "electron-vite preview",
|
||||
"dev": "electron-vite dev --watch",
|
||||
"build": "electron-vite build",
|
||||
"dev": "electron-vite dev",
|
||||
"build": "npm run typecheck && electron-vite build",
|
||||
"postinstall": "electron-builder install-app-deps",
|
||||
"build:unpack": "npm run build && electron-builder --dir",
|
||||
"build:win": "npm run build && electron-builder --win",
|
||||
|
@ -23,9 +23,9 @@
|
|||
"dependencies": {
|
||||
"@electron-toolkit/preload": "^3.0.1",
|
||||
"@electron-toolkit/utils": "^3.0.0",
|
||||
"better-sqlite3": "^11.1.2",
|
||||
"electron-updater": "^6.1.7",
|
||||
"knex": "^3.1.0"
|
||||
"knex": "^3.1.0",
|
||||
"sqlite3": "^5.1.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@electron-toolkit/eslint-config-prettier": "^2.0.0",
|
||||
|
@ -36,7 +36,7 @@
|
|||
"@types/react-dom": "^18.3.0",
|
||||
"@vitejs/plugin-react": "^4.3.1",
|
||||
"electron": "^31.0.2",
|
||||
"electron-builder": "24.6.3",
|
||||
"electron-builder": "^24.13.3",
|
||||
"electron-vite": "^2.3.0",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-plugin-react": "^7.34.3",
|
||||
|
|
780
pnpm-lock.yaml
780
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -2,8 +2,7 @@ import { app, shell, BrowserWindow } from 'electron'
|
|||
import { join } from 'path'
|
||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||
import icon from '../../resources/icon.png?asset'
|
||||
import { setupIpcHandle } from './ipc'
|
||||
import { setupAutoUpdater } from './updater'
|
||||
import { setupSignals } from './ipc'
|
||||
import './sqlite3'
|
||||
|
||||
function createWindow(): void {
|
||||
|
@ -36,9 +35,6 @@ function createWindow(): void {
|
|||
} else {
|
||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
||||
}
|
||||
|
||||
setupIpcHandle()
|
||||
setupAutoUpdater(mainWindow)
|
||||
}
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
|
@ -55,6 +51,8 @@ app.whenReady().then(() => {
|
|||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
|
||||
setupSignals()
|
||||
|
||||
createWindow()
|
||||
|
||||
app.on('activate', function () {
|
||||
|
|
|
@ -1,18 +1,8 @@
|
|||
import { ipcMain } from 'electron'
|
||||
import { autoUpdater } from 'electron-updater'
|
||||
|
||||
/**
|
||||
* ipc signals
|
||||
*/
|
||||
export const setupIpcHandle = (): void => {
|
||||
export const setupSignals = (): void => {
|
||||
ipcMain.on('ping', () => console.log('pong'))
|
||||
ipcMain.handle('check-for-updates', (event) => {
|
||||
console.log('检查更新')
|
||||
autoUpdater.checkForUpdates()
|
||||
console.log('执行')
|
||||
})
|
||||
|
||||
ipcMain.handle('quit-and-install', () => {
|
||||
autoUpdater.quitAndInstall()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -5,26 +5,21 @@ import path = require('path')
|
|||
// 初始化 Knex 配置
|
||||
const initKnex = (): Knex =>
|
||||
knex({
|
||||
client: 'better-sqlite3',
|
||||
client: 'sqlite3',
|
||||
connection: {
|
||||
filename: path.join(app.getPath('userData'), 'cvpilot.db')
|
||||
},
|
||||
useNullAsDefault: true
|
||||
})
|
||||
|
||||
// 创建一个表,如果它不存在
|
||||
// 创建一个表
|
||||
const createTable = async (db: Knex) => {
|
||||
const exists = await db.schema.hasTable('users')
|
||||
if (!exists) {
|
||||
await db.schema.createTable('users', (table) => {
|
||||
table.increments('id')
|
||||
table.string('name')
|
||||
table.integer('age')
|
||||
})
|
||||
console.log('Table created')
|
||||
} else {
|
||||
console.log('Table already exists')
|
||||
}
|
||||
await db.schema.createTable('users', (table) => {
|
||||
table.increments('id')
|
||||
table.string('name')
|
||||
table.integer('age')
|
||||
})
|
||||
console.log('Table created')
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
import { app, BrowserWindow, dialog } from 'electron'
|
||||
import { autoUpdater } from 'electron-updater'
|
||||
|
||||
/**
|
||||
* 文档地址: https://www.electron.build/auto-update
|
||||
*/
|
||||
export const setupAutoUpdater = (win: BrowserWindow) => {
|
||||
// 配置更新服务器地址
|
||||
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 })
|
||||
|
||||
autoUpdater.on('update-downloaded', (res) => {
|
||||
console.log('下载完成')
|
||||
autoUpdater.quitAndInstall()
|
||||
})
|
||||
|
||||
autoUpdater.on('checking-for-update', () => {
|
||||
console.log('checking-for-update,开始检查更新')
|
||||
})
|
||||
|
||||
autoUpdater.on('update-available', (info) => {
|
||||
console.log('update-available,有可用更新')
|
||||
autoUpdater.downloadUpdate()
|
||||
})
|
||||
|
||||
autoUpdater.on('download-progress', (progress) => {
|
||||
console.log('下载进度download-progress')
|
||||
console.log(progress)
|
||||
win.webContents.send('update-progress', progress)
|
||||
})
|
||||
|
||||
autoUpdater.on('error', (error) => {
|
||||
console.log('更新错误', error)
|
||||
win.webContents.send('update-error', { error, updateServerUrl })
|
||||
})
|
||||
}
|
6
src/preload/index.d.ts
vendored
6
src/preload/index.d.ts
vendored
|
@ -3,10 +3,6 @@ import { ElectronAPI } from '@electron-toolkit/preload'
|
|||
declare global {
|
||||
interface Window {
|
||||
electron: ElectronAPI
|
||||
api: {
|
||||
checkUpdate
|
||||
confirmUpdate
|
||||
quitInstall
|
||||
}
|
||||
api: unknown
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
import { contextBridge, ipcRenderer } from 'electron'
|
||||
import { contextBridge } from 'electron'
|
||||
import { electronAPI } from '@electron-toolkit/preload'
|
||||
|
||||
// Custom APIs for renderer
|
||||
const api = {
|
||||
checkUpdate: () => ipcRenderer.invoke('check-for-updates'),
|
||||
confirmUpdate: (version) => ipcRenderer.invoke('confirmUpdate', version),
|
||||
quitInstall: () => ipcRenderer.invoke('quit-and-install')
|
||||
}
|
||||
const api = {}
|
||||
|
||||
// Use `contextBridge` APIs to expose Electron APIs to
|
||||
// renderer only if context isolation is enabled, otherwise
|
||||
|
|
|
@ -1,29 +1,13 @@
|
|||
import Versions from './components/Versions'
|
||||
import electronLogo from './assets/electron.svg'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
function App(): JSX.Element {
|
||||
const updateHandle = () => window.api.checkUpdate()
|
||||
const [percent, setPercent] = useState()
|
||||
|
||||
useEffect(() => {
|
||||
window.electron.ipcRenderer.on('update-error', (e, data) => {
|
||||
// console.log(e)
|
||||
console.log(data)
|
||||
})
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
window.electron.ipcRenderer.on('update-progress', (e, data) => {
|
||||
setPercent(data.percent)
|
||||
})
|
||||
}, [])
|
||||
const ipcHandle = (): void => window.electron.ipcRenderer.send('ping')
|
||||
|
||||
return (
|
||||
<>
|
||||
<img alt="logo" className="logo" src={electronLogo} />
|
||||
<button onClick={updateHandle}>更新1.0.5</button>
|
||||
<div className="creator">进度{percent}</div>
|
||||
<div className="creator">Powered by electron-vite</div>
|
||||
<div className="text">
|
||||
Build an Electron app with <span className="react">React</span>
|
||||
and <span className="ts">TypeScript</span>
|
||||
|
@ -37,6 +21,11 @@ function App(): JSX.Element {
|
|||
Documentation
|
||||
</a>
|
||||
</div>
|
||||
<div className="action">
|
||||
<a target="_blank" rel="noreferrer" onClick={ipcHandle}>
|
||||
Send IPC
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<Versions></Versions>
|
||||
</>
|
||||
|
|
|
@ -8,7 +8,6 @@ function Versions(): JSX.Element {
|
|||
<li className="electron-version">Electron v{versions.electron}</li>
|
||||
<li className="chrome-version">Chromium v{versions.chrome}</li>
|
||||
<li className="node-version">Node v{versions.node}</li>
|
||||
<li>{window.electron.process.platform}</li>
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
import './assets/main.css'
|
||||
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(<App />)
|
||||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user