Skip to content

Commit 1c9d3cd

Browse files
committed
feat(06): desktop application via electron
1 parent f97998b commit 1c9d3cd

File tree

4 files changed

+162
-1
lines changed

4 files changed

+162
-1
lines changed

.github/workflows/electron.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: electron
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
permissions:
9+
contents: write
10+
11+
defaults:
12+
run:
13+
working-directory: frontend
14+
15+
jobs:
16+
build:
17+
runs-on: ${{ matrix.os }}
18+
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ubuntu-latest, windows-latest, macos-latest]
23+
include:
24+
- os: ubuntu-latest
25+
output-file: |
26+
./frontend/electron/*.AppImage
27+
./frontend/electron/*.deb
28+
./frontend/electron/*.rpm
29+
./frontend/electron/*.tar.gz
30+
- os: windows-latest
31+
output-file: |
32+
./frontend/electron/*.exe
33+
- os: macos-latest
34+
output-file: |
35+
./frontend/electron/*.dmg
36+
./frontend/electron/*.zip
37+
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
42+
- name: Set up Node.js
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: 20
46+
cache: yarn
47+
cache-dependency-path: ./frontend/yarn.lock
48+
49+
- name: Install dependencies
50+
run: |
51+
yarn install --frozen-lockfile
52+
yarn add electron electron-builder --dev
53+
54+
- name: Build
55+
run: |
56+
yarn build
57+
yarn electron:build
58+
59+
- name: Upload executables for publish
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: my-artifact-${{ matrix.os }}
63+
path: ${{ matrix.output-file }}
64+
65+
release:
66+
runs-on: ubuntu-latest
67+
needs: build
68+
69+
steps:
70+
- name: Download executables
71+
uses: actions/download-artifact@v4
72+
with:
73+
pattern: my-artifact-*
74+
merge-multiple: true
75+
path: dist
76+
77+
- name: Deploy to GitHub Releases
78+
uses: softprops/action-gh-release@v2
79+
with:
80+
files: ./dist/*
81+
name: Release ${{ github.ref_name }}
82+
generate_release_notes: true
83+
prerelease: true

frontend/package.json

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
"start": "craco start",
3232
"build": "craco build",
3333
"typecheck": "tsc --noEmit",
34-
"lint": "eslint src --ext .ts,.tsx"
34+
"lint": "eslint src --ext .ts,.tsx",
35+
"electron": "yarn build && electron .",
36+
"electron:build": "electron-builder"
3537
},
3638
"eslintConfig": {
3739
"extends": [
@@ -49,5 +51,47 @@
4951
"last 1 firefox version",
5052
"last 1 safari version"
5153
]
54+
},
55+
"name": "web-workshop",
56+
"version": "2024.0.0",
57+
"main": "build/electron.js",
58+
"build": {
59+
"productName": "EESAST Web Workshop",
60+
"appId": "web-workshop",
61+
"icon": "build/logo.png",
62+
"directories": {
63+
"output": "electron"
64+
},
65+
"win": {
66+
"target": [
67+
"nsis",
68+
"portable"
69+
]
70+
},
71+
"nsis": {
72+
"shortcutName": "EESAST",
73+
"oneClick": false,
74+
"perMachine": true,
75+
"allowElevation": true,
76+
"allowToChangeInstallationDirectory": true,
77+
"createDesktopShortcut": true,
78+
"createStartMenuShortcut": true
79+
},
80+
"mac": {
81+
"target": [
82+
"dmg",
83+
"zip"
84+
]
85+
},
86+
"linux": {
87+
"category": "Utility",
88+
"maintainer": "EESAST",
89+
"target": [
90+
"AppImage",
91+
"deb",
92+
"rpm",
93+
"tar.gz"
94+
]
95+
}
5296
}
5397
}

frontend/public/electron.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const { app, BrowserWindow } = require("electron");
2+
const path = require("path");
3+
4+
function createWindow() {
5+
const windowOptions = {
6+
width: 1280,
7+
height: 720,
8+
};
9+
const mainWindow = new BrowserWindow(windowOptions);
10+
mainWindow.loadFile(path.join(__dirname, "index.html"));
11+
// 打开新窗口时的配置
12+
mainWindow.webContents.setWindowOpenHandler(() => {
13+
return {
14+
action: "allow",
15+
overrideBrowserWindowOptions: windowOptions,
16+
};
17+
});
18+
}
19+
20+
app.whenReady().then(() => {
21+
createWindow();
22+
// 如果没有窗口打开则打开一个窗口 (macOS)
23+
app.on("activate", function () {
24+
if (BrowserWindow.getAllWindows().length === 0) {
25+
createWindow();
26+
}
27+
});
28+
});
29+
// 关闭所有窗口时退出应用 (Windows & Linux)
30+
app.on("window-all-closed", () => {
31+
if (process.platform !== "darwin") {
32+
app.quit();
33+
}
34+
});

frontend/public/logo.png

92.7 KB
Loading

0 commit comments

Comments
 (0)