Add script for running Electron in development mode and update package.json and main.cjs accordingly

This commit is contained in:
2026-03-20 09:15:14 +01:00
parent 63b164dafc
commit f76474280d
3 changed files with 74 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ const REPO_ROOT = path.resolve(__dirname, '..')
const UPDATE_REMOTE_URL = 'https://giers10.uber.space/giers10/Heimgeist.git'
const UPDATE_BRANCH = 'master'
const GIT_ENV = { ...process.env, GIT_TERMINAL_PROMPT: '0' }
const DEV_WRAPPER_RELAUNCH_CODE = Number(process.env.HEIMGEIST_DEV_RELAUNCH_CODE || 75)
const settingsFilePath = process.env.HEIMGEIST_SETTINGS_FILE || path.join(app.getPath('userData'), 'settings.json')
let appSettings = {}
let lastUpdateCheckResult = null
@@ -145,6 +146,11 @@ async function runGitCommand(args, options = {}) {
function scheduleAppRestart() {
setTimeout(() => {
if (process.env.HEIMGEIST_DEV_WRAPPER === '1') {
app.exit(DEV_WRAPPER_RELAUNCH_CODE)
return
}
app.relaunch()
app.exit(0)
}, 300)

View File

@@ -8,7 +8,7 @@
"dev": "concurrently -k \"npm:dev:backend\" \"npm:dev:renderer\" \"npm:dev:electron\"",
"dev:backend": "node scripts/run-backend.cjs",
"dev:renderer": "vite --port 5173 --strictPort",
"dev:electron": "wait-on http://localhost:5173 tcp:8000 && cross-env VITE_DEV_SERVER_URL=http://localhost:5173 electron .",
"dev:electron": "node scripts/run-electron-dev.cjs",
"build": "vite build",
"start": "electron ."
},

View File

@@ -0,0 +1,67 @@
const { spawn } = require('child_process')
const path = require('path')
const waitOn = require('wait-on')
const projectRoot = path.resolve(__dirname, '..')
const electronBinary = require('electron')
const relaunchExitCode = 75
const startupResources = ['http://localhost:5173', 'tcp:8000']
const env = {
...process.env,
VITE_DEV_SERVER_URL: process.env.VITE_DEV_SERVER_URL || 'http://localhost:5173',
HEIMGEIST_DEV_WRAPPER: '1',
HEIMGEIST_DEV_RELAUNCH_CODE: String(relaunchExitCode),
}
async function waitForDependencies() {
await waitOn({
resources: startupResources,
timeout: 120000,
})
}
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}
function runElectronOnce() {
return new Promise((resolve) => {
const child = spawn(electronBinary, ['.'], {
cwd: projectRoot,
env,
stdio: 'inherit',
})
child.on('exit', (code, signal) => {
resolve({ code, signal })
})
})
}
async function main() {
await waitForDependencies()
while (true) {
const { code, signal } = await runElectronOnce()
if (signal) {
process.kill(process.pid, signal)
return
}
if (code === relaunchExitCode) {
await sleep(750)
await waitForDependencies()
continue
}
process.exit(code ?? 0)
}
}
main().catch((error) => {
console.error('Failed to launch Electron dev wrapper:', error)
process.exit(1)
})