Skip to content

Commit f7f0e58

Browse files
authored
refactor: improve code structure (#45)
* refactor electron module * feat(updater): implement app updater with auto-update functionality - Added AppUpdater class to handle application updates using electron-updater. - Implemented methods for checking updates, downloading, and installing updates. - Introduced WebUpdater class as a placeholder for future web resource hot-reload logic. - Created types for AppUpdateState and UpdaterStatus in shared-types package. - Updated IPC communication to include app update state messages. - Enhanced the web application to display update status and control updates. - Improved UI with new styles and layout for the update control panel. - Added error handling and logging for update processes. * fix: correct usage of import.meta.dirname in catchException and appConfig * refactor: update publish workflow to trigger on main branch and change release type to release
1 parent 4449992 commit f7f0e58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+5678
-4038
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build
1+
name: Publish Electron App
22

33
on:
44
push:
@@ -45,7 +45,7 @@ jobs:
4545
- name: Release for Windows
4646
if: matrix.os == 'windows-latest'
4747
run: |
48-
pnpm pack:dev
48+
pnpm pack:prod
4949
5050
- name: Release for MacOS
5151
if: matrix.os == 'macos-latest'
@@ -80,9 +80,9 @@ jobs:
8080
# apply provisioning profile
8181
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
8282
cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles
83-
pnpm pack:dev
83+
pnpm pack:prod
8484
8585
- name: Release for Linux
8686
if: matrix.os == 'ubuntu-latest'
8787
run: |
88-
pnpm pack:dev
88+
pnpm pack:prod

.npmrc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11

22
package-manager-strict=false
33

4-
# https://github.com/electron-userland/electron-builder/issues/8346
5-
virtual-store-dir-max-length=70
6-
74
# 使用淘宝镜像源
85
registry = https://registry.npmmirror.com
96
# registry = https://registry.npmjs.org

.vscode/extensions.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"recommendations": [
3+
// Vue 3 的语言支持
4+
"Vue.volar",
5+
// 将 ESLint JavaScript 集成到 VS Code 中。
6+
"dbaeumer.vscode-eslint",
7+
// 支持 dotenv 文件语法
8+
"mikestead.dotenv",
9+
// 源代码的拼写检查器
10+
"streetsidesoftware.code-spell-checker",
11+
// Tailwind CSS 的官方 VS Code 插件
12+
"bradlc.vscode-tailwindcss",
13+
// 在 package.json 文件中显示可用更新
14+
"codeandstuff.package-json-upgrade"
15+
],
16+
"unwantedRecommendations": [
17+
// 和 volar 冲突
18+
"octref.vetur"
19+
]
20+
}

.vscode/settings.json

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,66 @@
11
{
2+
"typescript.preferences.importModuleSpecifier": "non-relative",
23
// Disable the default formatter, use eslint instead
34
"prettier.enable": false,
4-
"editor.formatOnSave": true,
5-
5+
"editor.formatOnSave": false,
66
// Auto fix
77
"editor.codeActionsOnSave": {
88
"source.fixAll.eslint": "explicit",
99
"source.organizeImports": "never"
1010
},
11-
12-
// Silent the stylistic rules in you IDE, but still auto fix them
11+
// Silent the stylistic rules in your IDE, but still auto fix them
1312
"eslint.rules.customizations": [
14-
{ "rule": "style/*", "severity": "off", "fixable": true },
15-
{ "rule": "format/*", "severity": "off", "fixable": true },
16-
{ "rule": "*-indent", "severity": "off", "fixable": true },
17-
{ "rule": "*-spacing", "severity": "off", "fixable": true },
18-
{ "rule": "*-spaces", "severity": "off", "fixable": true },
19-
{ "rule": "*-order", "severity": "off", "fixable": true },
20-
{ "rule": "*-dangle", "severity": "off", "fixable": true },
21-
{ "rule": "*-newline", "severity": "off", "fixable": true },
22-
{ "rule": "*quotes", "severity": "off", "fixable": true },
23-
{ "rule": "*semi", "severity": "off", "fixable": true }
13+
{
14+
"rule": "style/*",
15+
"severity": "off",
16+
"fixable": true
17+
},
18+
{
19+
"rule": "format/*",
20+
"severity": "off",
21+
"fixable": true
22+
},
23+
{
24+
"rule": "*-indent",
25+
"severity": "off",
26+
"fixable": true
27+
},
28+
{
29+
"rule": "*-spacing",
30+
"severity": "off",
31+
"fixable": true
32+
},
33+
{
34+
"rule": "*-spaces",
35+
"severity": "off",
36+
"fixable": true
37+
},
38+
{
39+
"rule": "*-order",
40+
"severity": "off",
41+
"fixable": true
42+
},
43+
{
44+
"rule": "*-dangle",
45+
"severity": "off",
46+
"fixable": true
47+
},
48+
{
49+
"rule": "*-newline",
50+
"severity": "off",
51+
"fixable": true
52+
},
53+
{
54+
"rule": "*quotes",
55+
"severity": "off",
56+
"fixable": true
57+
},
58+
{
59+
"rule": "*semi",
60+
"severity": "off",
61+
"fixable": true
62+
}
2463
],
25-
2664
// Enable eslint for all supported languages
2765
"eslint.validate": [
2866
"javascript",
@@ -40,6 +78,7 @@
4078
"gql",
4179
"graphql",
4280
"astro",
81+
"svelte",
4382
"css",
4483
"less",
4584
"scss",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "chrome": "134", "node": "22" }
1+
{"chrome":"142","node":"22"}

apps/electron/.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# 测试环境配置
22
NODE_ENV=development
3-
VITE_APP_VERSION=0.2.0
3+
VITE_APP_VERSION=0.0.1

apps/electron/dev-app-update.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
provider: generic
2-
url: 'http://localhost:8080'
1+
# provider: generic
2+
# url: 'http://localhost:8080'
3+
4+
provider: github
5+
owner: buqiyuan
6+
repo: electron-vite-monorepo
7+
releaseType: release # 如果构建脚本发布成 Draft,可保留;否则设为 release/latest
8+
private: false # 若仓库私有则改为 true 并提供 token

apps/electron/package.json

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "electron-main",
3+
"type": "module",
34
"version": "0.2.0",
45
"private": false,
56
"description": "Electron main process",
@@ -13,33 +14,37 @@
1314
"type": "git",
1415
"url": "https://github.com/buqiyuan/electron-vite-monorepo.git"
1516
},
16-
"main": "dist-vite/index.cjs",
17+
"main": "dist-vite/index.mjs",
1718
"engines": {
1819
"node": ">=22.0.0"
1920
},
2021
"scripts": {
21-
"bundle": "npx rimraf ./dist && webpack --config webpack.config.js",
22+
"bundle": "npx rimraf ./dist && webpack --config webpack.config.cjs",
2223
"build:dev": "vite build --mode development && pnpm bundle",
2324
"build:prod": "vite build && pnpm bundle",
24-
"pack:app": "npx tsx scripts/build.ts",
25+
"pack:app": "npx tsx scripts/build.mts",
2526
"pack:dev": "pnpm build:dev && dotenvx run -f .env.development -- pnpm pack:app",
2627
"pack:prod": "pnpm build:prod && dotenvx run -f .env.production -- pnpm pack:app",
2728
"typecheck": "tsc --noEmit -p tsconfig.json",
2829
"install:electron": "cross-env ELECTRON_GET_USE_PROXY=true node node_modules/electron/install.js",
29-
"gen:vendors": "cross-env ELECTRON_RUN_AS_NODE=1 electron ./scripts/update-electron-vendors.js",
30+
"gen:vendors": "cross-env ELECTRON_RUN_AS_NODE=1 electron ./scripts/update-electron-vendors.mjs",
3031
"postinstall": "pnpm install:electron && pnpm gen:vendors"
3132
},
3233
"devDependencies": {
33-
"@electron/notarize": "^3.0.1",
34+
"@electron/notarize": "^3.1.1",
3435
"@repo/electron-preload": "workspace:*",
36+
"@repo/shared-types": "workspace:*",
3537
"@types/node": "^22.14.1",
36-
"electron": "35.1.4",
37-
"electron-builder": "26.0.12",
38+
"date-fns": "^4.1.0",
39+
"electron": "39.2.6",
40+
"electron-builder": "26.3.4",
41+
"electron-log": "^5.4.3",
42+
"electron-store": "^11.0.2",
3843
"electron-updater": "6.6.2",
39-
"terser-webpack-plugin": "^5.3.14",
40-
"typescript": "5.8.3",
41-
"vite": "6.2.6",
42-
"webpack": "^5.99.5",
44+
"terser-webpack-plugin": "^5.3.15",
45+
"typescript": "catalog:",
46+
"vite": "catalog:",
47+
"webpack": "^5.103.0",
4348
"webpack-cli": "^6.0.1"
4449
}
4550
}

apps/electron/resources/tray.png

783 Bytes
Loading
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Configuration } from 'electron-builder'
22
import type { CopySyncOptions } from 'node:fs'
33
import { cpSync } from 'node:fs'
44
import path from 'node:path'
5-
import process, { exit, platform } from 'node:process'
5+
import process, { exit } from 'node:process'
66
import { build, Platform } from 'electron-builder'
77

88
const version = process.env.VITE_APP_VERSION
@@ -11,15 +11,15 @@ const appName = isDev ? 'ElectronAppDev' : 'ElectronApp'
1111
const appId = isDev ? 'com.electron.app' : 'com.electron-dev.app'
1212
const shortcutName = isDev ? 'Electron App Dev' : 'Electron App'
1313

14-
console.log('是否是测试环境:', isDev, appName)
15-
console.log('APP 版本号:', version)
14+
console.log('Development environment:', isDev, appName)
15+
console.log('APP version:', version)
1616

17-
const workDir = path.join(__dirname, '../')
17+
const workDir = path.join(import.meta.dirname, '../')
1818

1919
const copySyncOptions: CopySyncOptions = {
2020
recursive: true,
2121
/**
22-
* 过滤 source map 文件
22+
* Filter out source map files
2323
*/
2424
filter: src => !src.endsWith('.map') && !src.endsWith('.d.ts'),
2525
}
@@ -37,7 +37,7 @@ const options: Configuration = {
3737
extraMetadata: {
3838
version,
3939
name: appName,
40-
main: 'dist/main.cjs',
40+
main: 'dist/main.mjs',
4141
},
4242
directories: {
4343
output: '../../out',
@@ -111,24 +111,17 @@ const options: Configuration = {
111111
],
112112
}
113113

114-
// 要打包的目标平台
115-
const targetPlatform: Platform = {
116-
darwin: Platform.MAC,
117-
win32: Platform.WINDOWS,
118-
linux: Platform.LINUX,
119-
}[platform]
120-
121114
build({
122-
targets: targetPlatform.createTarget(),
115+
targets: Platform.current().createTarget(),
123116
config: options,
124117
publish: process.env.CI ? 'always' : 'never',
125118
})
126119
.then((result) => {
127120
console.log(JSON.stringify(result))
128121
const outDir = path.join(workDir, options.directories!.output!)
129-
console.log('\x1B[32m', `打包完成🎉🎉🎉你要的都在 ${outDir} 目录里🤪🤪🤪`)
122+
console.log('\x1B[32m', `Build complete! 🎉🎉🎉 Everything you need is in ${outDir}`)
130123
})
131124
.catch((error) => {
132-
console.log('\x1B[31m', '打包失败,错误信息:', error)
125+
console.log('\x1B[31m', 'Build failed with error:', error)
133126
exit(1)
134127
})

0 commit comments

Comments
 (0)