Skip to content

Commit 3f6d2ea

Browse files
committed
Improve Electron build
1 parent 8d5c745 commit 3f6d2ea

File tree

8 files changed

+149
-92
lines changed

8 files changed

+149
-92
lines changed

.github/workflows/build.yml

Lines changed: 98 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,72 +17,135 @@ permissions:
1717
contents: read
1818

1919
jobs:
20-
build:
21-
name: Build (${{ matrix.os }})
22-
runs-on: ${{ matrix.os }}
23-
strategy:
24-
fail-fast: false
25-
matrix:
26-
os: [ubuntu-latest, macos-latest, windows-latest]
20+
build-linux:
21+
name: Build Linux
22+
runs-on: ubuntu-latest
2723

2824
steps:
2925
- name: Checkout
3026
uses: actions/checkout@v4
3127

32-
- name: Force npm to use Bash
33-
if: runner.os == 'Windows'
34-
run: npm config set script-shell "C:\Program Files\Git\bin\bash.exe"
35-
3628
- name: Setup Node.js
3729
uses: actions/setup-node@v4
3830
with:
3931
node-version: '24'
4032

41-
- name: Cache npm (Linux/macOS)
42-
if: runner.os != 'Windows'
33+
- name: Cache npm
4334
uses: actions/cache@v4
4435
with:
4536
path: ~/.npm
46-
key: npm-${{ runner.os }}-node-24-${{ hashFiles('package.json') }}
37+
key: npm-ubuntu-latest-node-24-${{ hashFiles('package.json') }}
4738
restore-keys: |
48-
npm-${{ runner.os }}-node-24-
39+
npm-ubuntu-latest-node-24-
40+
41+
- name: Install dependencies
42+
run: npm install --ignore-scripts --no-audit --no-fund
4943

50-
- name: Cache npm (Windows)
51-
if: runner.os == 'Windows'
44+
- name: Cache Electron downloads
5245
uses: actions/cache@v4
5346
with:
54-
path: ~\AppData\Local\npm-cache
55-
key: npm-${{ runner.os }}-node-24-${{ hashFiles('package.json') }}
47+
path: |
48+
~/.cache/electron
49+
~/.cache/electron-builder
50+
key: electron-ubuntu-latest-${{ hashFiles('package.json', 'package.json') }}
5651
restore-keys: |
57-
npm-${{ runner.os }}-node-24-
52+
electron-ubuntu-latest-
5853
59-
- name: Install root deps (no scripts)
60-
run: npm install --ignore-scripts --no-audit --no-fund
54+
- name: Build Electron app
55+
shell: bash
56+
run: npm run build:electron
57+
58+
- name: Upload artifact
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: FromChat-linux
62+
path: |
63+
frontend/build/electron/forge/make/*/**
64+
if-no-files-found: error
65+
66+
build-macos:
67+
name: Build macOS
68+
runs-on: macos-latest
69+
70+
steps:
71+
- name: Checkout
72+
uses: actions/checkout@v4
73+
74+
- name: Setup Node.js
75+
uses: actions/setup-node@v4
76+
with:
77+
node-version: '24'
78+
79+
- name: Cache npm
80+
uses: actions/cache@v4
81+
with:
82+
path: ~/.npm
83+
key: npm-macos-latest-node-24-${{ hashFiles('package.json') }}
84+
restore-keys: |
85+
npm-macos-latest-node-24-
6186
62-
- name: Install Electron Forge deps
63-
run: npm run frontend:electron:dependencies
87+
- name: Install root dependencies
88+
run: npm install --ignore-scripts --no-audit --no-fund
6489

65-
- name: Cache Electron downloads (Linux/macOS)
66-
if: runner.os != 'Windows'
90+
- name: Cache Electron downloads
6791
uses: actions/cache@v4
6892
with:
6993
path: |
7094
~/.cache/electron
7195
~/.cache/electron-builder
72-
key: electron-${{ runner.os }}-${{ hashFiles('package.json', 'frontend/electron/forge/package.json') }}
96+
key: electron-macos-latest-${{ hashFiles('package.json') }}
7397
restore-keys: |
74-
electron-${{ runner.os }}-
98+
electron-macos-latest-
99+
100+
- name: Build Electron app
101+
shell: bash
102+
run: npm run build:electron
75103

76-
- name: Cache Electron downloads (Windows)
77-
if: runner.os == 'Windows'
104+
- name: Upload artifact
105+
uses: actions/upload-artifact@v4
106+
with:
107+
name: FromChat-macOS
108+
path: |
109+
frontend/build/electron/forge/make/zip/darwin/*/**.zip
110+
if-no-files-found: error
111+
112+
build-windows:
113+
name: Build Windows
114+
runs-on: windows-latest
115+
116+
steps:
117+
- name: Checkout
118+
uses: actions/checkout@v4
119+
120+
- name: Force npm to use Bash
121+
run: npm config set script-shell "C:\Program Files\Git\bin\bash.exe"
122+
123+
- name: Setup Node.js
124+
uses: actions/setup-node@v4
125+
with:
126+
node-version: '24'
127+
128+
- name: Cache npm
129+
uses: actions/cache@v4
130+
with:
131+
path: |
132+
${{ env.LocalAppData }}\npm-cache
133+
key: npm-windows-latest-node-24-${{ hashFiles('package.json') }}
134+
restore-keys: |
135+
npm-windows-latest-node-24-
136+
137+
- name: Install root dependencies
138+
run: npm install --ignore-scripts --no-audit --no-fund
139+
140+
- name: Cache Electron downloads
78141
uses: actions/cache@v4
79142
with:
80143
path: |
81144
~\AppData\Local\electron\Cache
82145
~\AppData\Local\electron-builder\Cache
83-
key: electron-${{ runner.os }}-${{ hashFiles('package.json', 'frontend/electron/forge/package.json') }}
146+
key: electron-windows-latest-${{ hashFiles('package.json') }}
84147
restore-keys: |
85-
electron-${{ runner.os }}-
148+
electron-windows-latest-
86149
87150
- name: Build Electron app
88151
shell: bash
@@ -91,8 +154,7 @@ jobs:
91154
- name: Upload artifact
92155
uses: actions/upload-artifact@v4
93156
with:
94-
name: fromchat-${{ runner.os }}
157+
name: FromChat-windows
95158
path: |
96-
frontend/electron/forge/out/**
97-
if-no-files-found: error
98-
159+
frontend/build/electron/forge/make/zip/win32/x64
160+
if-no-files-found: error

.github/workflows/deploy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ on:
1313
- ".nvmrc"
1414
- ".github/workflows/deploy.yml"
1515
- "!frontend/electron/**"
16-
- "!frontend/src/electron/**"
1716
- "!**.d.ts"
1817
workflow_dispatch:
1918

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"files.exclude": {
33
"**/__pycache__": true,
44
"**/package-lock.json": true
5-
}
5+
},
6+
"github-actions.workflows.pinned.workflows": [],
7+
"github-actions.workflows.pinned.workflows.ignore": true,
8+
"github-actions.workflows.pinned.workflows.ignoreContextAccess": true
69
}

frontend/electron/forge/package.json

Lines changed: 0 additions & 33 deletions
This file was deleted.

frontend/electron/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ app.whenReady().then(() => {
1616
y: 16 - 4
1717
},
1818
titleBarOverlay: process.platform !== "darwin"
19-
})
19+
});
2020

2121
if (process.env.VITE_DEV_SERVER_URL) {
22-
win.loadURL(process.env.VITE_DEV_SERVER_URL)
22+
win.loadURL(process.env.VITE_DEV_SERVER_URL);
2323
} else {
24-
win.loadFile('dist/index.html');
24+
win.loadFile('frontend/build/electron/dist/index.html');
2525
}
2626
});
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
import { FusesPlugin } from '@electron-forge/plugin-fuses';
22
import { FuseV1Options, FuseVersion } from '@electron/fuses';
3-
import type { ForgeConfig } from "@electron-forge/shared-types";
3+
import type { ForgeConfig } from '@electron-forge/shared-types';
44

5-
const config: ForgeConfig = {
5+
export default {
66
packagerConfig: {
7-
asar: true
7+
asar: true,
88
},
9+
outDir: "frontend/build/electron/forge",
910
rebuildConfig: {},
1011
makers: [
11-
{
12-
name: '@electron-forge/maker-squirrel',
13-
config: {},
14-
},
1512
{
1613
name: '@electron-forge/maker-zip',
1714
config: {},
18-
platforms: ['darwin'],
15+
platforms: ['win32', 'darwin'],
1916
},
2017
{
2118
name: '@electron-forge/maker-deb',
2219
config: {},
20+
platforms: ['linux'],
2321
},
2422
{
2523
name: '@electron-forge/maker-rpm',
2624
config: {},
25+
platforms: ['linux'],
2726
},
2827
],
2928
plugins: [
@@ -43,6 +42,4 @@ const config: ForgeConfig = {
4342
[FuseV1Options.OnlyLoadAppFromAsar]: true,
4443
}),
4544
],
46-
};
47-
48-
export default config;
45+
} satisfies ForgeConfig;

frontend/vite.config.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,19 @@ if (process.env.VITE_ELECTRON) {
2525
electron({
2626
main: {
2727
entry: "electron/main.ts",
28+
vite: {
29+
build: {
30+
outDir: "build/electron/core"
31+
}
32+
}
2833
},
2934
preload: {
30-
input: "frontend/electron/preload.ts"
35+
input: "frontend/electron/preload.ts",
36+
vite: {
37+
build: {
38+
outDir: "build/electron/core"
39+
}
40+
}
3141
},
3242
renderer: {},
3343
})
@@ -68,6 +78,7 @@ export default defineConfig({
6878
}
6979
},
7080
cssMinify: true,
71-
assetsInlineLimit: 0
81+
assetsInlineLimit: 0,
82+
outDir: process.env.VITE_ELECTRON ? "build/electron/dist" : "build/normal/dist"
7283
}
7384
});

package.json

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
2-
"name": "pixelchat",
2+
"name": "FromChat",
33
"private": true,
44
"version": "0.0.0",
55
"type": "module",
6-
"main": "frontend/dist-electron/main.js",
6+
"main": "frontend/build/electron/core/main.js",
7+
"description": "A 100% Open Source Messenger",
8+
"license": "GPL-3.0",
9+
"authors": "denis0001-dev",
710
"scripts": {
811
"backend:run": "cd backend && dotenv -e ../deployment/.env -- ../.venv/bin/fastapi dev --port 8300 main.py",
912
"backend:dependencies": "python3 -m venv .venv && ./.venv/bin/pip3 install -r backend/requirements.txt",
@@ -13,8 +16,7 @@
1316
"frontend:typecheck": "tsc --project frontend",
1417
"frontend:build": "npm run frontend:typecheck && vite build frontend",
1518
"frontend:electron:dev": "VITE_ELECTRON=true npm run frontend:dev",
16-
"frontend:electron:dependencies": "cd frontend/electron/forge && npm install",
17-
"frontend:electron:build": "VITE_ELECTRON=true npm run frontend:build && cp -r frontend/dist frontend/dist-electron frontend/electron/forge && cd frontend/electron/forge && npm run make",
19+
"frontend:electron:build": "VITE_ELECTRON=true npm run frontend:build && rm -rf out && electron-forge make --force",
1820
"frontend:preview": "vite preview frontend",
1921
"frontend:dependencies": "npm install --ignore-scripts",
2022
"frontend:clean": "rm -rf frontend/dist",
@@ -25,10 +27,22 @@
2527
"preview": "cd deployment && docker compose up --build --watch",
2628
"preview:clean": "cd deployment && docker compose down -v",
2729
"clean": "npm run backend:clean && npm run frontend:clean && npm run preview:clean",
28-
"install": "npm run backend:dependencies && npm run frontend:electron:dependencies && cp deployment/.env.example deployment/.env",
30+
"install": "npm run backend:dependencies && cp deployment/.env.example deployment/.env",
2931
"prepare": "husky"
3032
},
33+
"files": [
34+
"frontend/build/electron"
35+
],
3136
"devDependencies": {
37+
"@electron-forge/cli": "^7.9.0",
38+
"@electron-forge/maker-deb": "^7.9.0",
39+
"@electron-forge/maker-dmg": "^7.9.0",
40+
"@electron-forge/maker-rpm": "^7.9.0",
41+
"@electron-forge/maker-squirrel": "^7.9.0",
42+
"@electron-forge/maker-zip": "^7.9.0",
43+
"@electron-forge/plugin-auto-unpack-natives": "^7.9.0",
44+
"@electron-forge/plugin-fuses": "^7.9.0",
45+
"@electron/fuses": "^1.8.0",
3246
"@types/react": "^19.1.12",
3347
"@types/react-dom": "^19.1.9",
3448
"@vitejs/plugin-react": "^5.0.2",
@@ -47,11 +61,15 @@
4761
"vite-plugin-html": "^3.2.2"
4862
},
4963
"dependencies": {
64+
"electron-squirrel-startup": "^1.0.1",
5065
"mdui": "^2.1.4",
5166
"react": "^19.1.1",
5267
"react-dom": "^19.1.1",
5368
"tweetnacl": "^1.0.3",
5469
"use-immer": "^0.11.0",
5570
"zustand": "^5.0.8"
71+
},
72+
"config": {
73+
"forge": "frontend/forge.config.ts"
5674
}
5775
}

0 commit comments

Comments
 (0)