Skip to content

Commit a580b87

Browse files
committed
Improve Electron experience and build system
1 parent 89492b2 commit a580b87

File tree

17 files changed

+190
-139
lines changed

17 files changed

+190
-139
lines changed

.github/workflows/build.yml

Lines changed: 100 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,72 +17,134 @@ 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 dependencies
4334
uses: actions/cache@v4
4435
with:
45-
path: ~/.npm
46-
key: npm-${{ runner.os }}-node-24-${{ hashFiles('package.json') }}
36+
path: node_modules
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
6157

62-
- name: Install Electron Forge deps
63-
run: npm run frontend:electron:dependencies
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
6473

65-
- name: Cache Electron downloads (Linux/macOS)
66-
if: runner.os != 'Windows'
74+
- name: Setup Node.js
75+
uses: actions/setup-node@v4
76+
with:
77+
node-version: '24'
78+
79+
- name: Cache dependencies
6780
uses: actions/cache@v4
6881
with:
82+
path: node_modules
83+
key: npm-macos-latest-node-24-${{ hashFiles('package.json') }}
84+
restore-keys: |
85+
npm-macos-latest-node-24-
86+
87+
- name: Install dependencies
88+
run: npm install --ignore-scripts --no-audit --no-fund
89+
90+
# - name: Cache Electron downloads
91+
# uses: actions/cache@v4
92+
# with:
93+
# path: |
94+
# ~/.cache/electron
95+
# ~/.cache/electron-builder
96+
# key: electron-macos-latest-${{ hashFiles('package.json') }}
97+
# restore-keys: |
98+
# electron-macos-latest-
99+
100+
- name: Build Electron app
101+
shell: bash
102+
run: npm run build:electron
103+
104+
- name: Upload artifact
105+
uses: actions/upload-artifact@v4
106+
with:
107+
name: FromChat-macOS
69108
path: |
70-
~/.cache/electron
71-
~/.cache/electron-builder
72-
key: electron-${{ runner.os }}-${{ hashFiles('package.json', 'frontend/electron/forge/package.json') }}
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 dependencies
129+
uses: actions/cache@v4
130+
with:
131+
path: node_modules
132+
key: npm-windows-latest-node-24-${{ hashFiles('package.json') }}
73133
restore-keys: |
74-
electron-${{ runner.os }}-
134+
npm-windows-latest-node-24-
75135
76-
- name: Cache Electron downloads (Windows)
77-
if: runner.os == 'Windows'
136+
- name: Install dependencies
137+
run: npm install --ignore-scripts --no-audit --no-fund
138+
139+
- name: Cache Electron downloads
78140
uses: actions/cache@v4
79141
with:
80142
path: |
81143
~\AppData\Local\electron\Cache
82144
~\AppData\Local\electron-builder\Cache
83-
key: electron-${{ runner.os }}-${{ hashFiles('package.json', 'frontend/electron/forge/package.json') }}
145+
key: electron-windows-latest-${{ hashFiles('package.json') }}
84146
restore-keys: |
85-
electron-${{ runner.os }}-
147+
electron-windows-latest-
86148
87149
- name: Build Electron app
88150
shell: bash
@@ -91,8 +153,7 @@ jobs:
91153
- name: Upload artifact
92154
uses: actions/upload-artifact@v4
93155
with:
94-
name: fromchat-${{ runner.os }}
156+
name: FromChat-windows
95157
path: |
96-
frontend/electron/forge/out/**
97-
if-no-files-found: error
98-
158+
frontend/build/electron/forge/make/zip/win32/x64
159+
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
}

deployment/frontend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ USER app
3636

3737
# 3.1. Frontend static files
3838
WORKDIR /app
39-
COPY --from=frontend --chown=app /app/frontend/dist .
39+
COPY --from=frontend --chown=app /app/frontend/build/normal/dist .
4040

4141
# 3.2. Static file server
4242
WORKDIR /server

frontend/electron/forge/package.json

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

frontend/electron/main.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from "node:path";
44
app.whenReady().then(() => {
55
const win = new BrowserWindow({
66
title: 'Main window',
7-
minWidth: 650,
7+
minWidth: 800,
88
minHeight: 420,
99
webPreferences: {
1010
preload: path.join(import.meta.dirname, "preload.mjs")
@@ -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/src/electron/electron.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
* @version 1.0.0
66
*/
77

8-
import { PRODUCT_NAME } from "../core/config.ts";
9-
import { id } from "../utils/utils.ts";
8+
export const isElectron = import.meta.env.VITE_ELECTRON && window.electronInterface != undefined;
109

11-
if (window.electronInterface !== undefined) {
10+
if (isElectron) {
1211
console.log("Running in Electron");
1312
document.documentElement.classList.add("electron", `platform-${window.electronInterface.platform}`);
14-
id("window-title").textContent = PRODUCT_NAME;
1513
} else {
1614
console.log("Running in normal browser");
1715
}

frontend/src/main.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import "mdui/mdui.css";
1010

1111
import "./utils/material";
1212
import "./core/init";
13+
import "./electron/electron";
1314
import { createRoot } from 'react-dom/client';
1415
import App from './ui/App';
1516
import { StrictMode } from 'react';

frontend/src/resources/css/_electron.scss

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ html.electron {
99
display: flex;
1010
flex-direction: row;
1111
gap: 8px;
12-
height: 40px;
12+
min-height: 40px;
1313
background-color: $color-dark-surface-container;
1414
width: 100%;
1515
-webkit-app-region: drag;
1616
user-select: none;
1717
z-index: 10;
1818
transition: background-color 0.5s ease;
19+
flex-shrink: 0;
1920

2021
&.color-surface {
2122
background-color: $color-dark-surface;
@@ -29,15 +30,12 @@ html.electron {
2930
font-weight: 500;
3031
}
3132

32-
&.platform-darwin .macos-padding {
33-
width: 70px;
33+
#main-wrapper {
34+
flex: 1;
35+
min-height: 0;
3436
}
3537

36-
// .window-controls {
37-
// -webkit-app-region: no-drag;
38-
39-
// .hidden {
40-
// display: none;
41-
// }
42-
// }
38+
&.platform-darwin .macos-padding {
39+
width: 80px;
40+
}
4341
}

0 commit comments

Comments
 (0)