Skip to content

Commit b44ed39

Browse files
committed
build: dynamic electron config loading
1 parent 3fc6adf commit b44ed39

8 files changed

Lines changed: 49 additions & 15 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ phoenix
2222
# Electron things
2323
src-electron/bin
2424
src-electron/src-node
25+
src-electron/config-effective.json
2526

2627
node_modules
2728
dist

src-build/serveForPlatform.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {getPlatformDetails} from "./utils.js";
22
import {execa} from "execa";
33
import chalk from "chalk";
44
import {resolve} from "path";
5+
import {copyFileSync} from "fs";
56

67
const {platform} = getPlatformDetails();
78

@@ -57,6 +58,13 @@ if (target === "tauri") {
5758
console.log(`Running "npm install" in ${srcNodePath}`);
5859
await execa("npm", ["install"], {cwd: srcNodePath, stdio: "inherit"});
5960

61+
// Copy config.json to config-effective.json (dev config for serve)
62+
const electronDir = resolve("src-electron");
63+
const configSrc = resolve(electronDir, "config.json");
64+
const configDest = resolve(electronDir, "config-effective.json");
65+
console.log('Copying config.json to config-effective.json...');
66+
copyFileSync(configSrc, configDest);
67+
6068
console.log('Starting Electron...');
6169
await execa("./src-electron/node_modules/.bin/electron", ["src-electron/main.js"], {stdio: "inherit"});
6270
}

src-build/setupElectron.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { execSync } from 'child_process';
22
import { fileURLToPath } from 'url';
33
import { dirname, join } from 'path';
4+
import { copyFileSync } from 'fs';
45

56
const __filename = fileURLToPath(import.meta.url);
67
const __dirname = dirname(__filename);
@@ -10,3 +11,10 @@ const electronDir = join(__dirname, '..', 'src-electron');
1011
console.log('Installing src-electron dependencies...');
1112
execSync('npm ci', { cwd: electronDir, stdio: 'inherit' });
1213
console.log('src-electron dependencies installed successfully!');
14+
15+
// Copy config.json to config-effective.json (dev config by default)
16+
const configSrc = join(electronDir, 'config.json');
17+
const configDest = join(electronDir, 'config-effective.json');
18+
console.log('Copying config.json to config-effective.json...');
19+
copyFileSync(configSrc, configDest);
20+
console.log('Config file copied successfully!');

src-electron/config-prod.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"identifier": "io.phcode",
3+
"stage": "production",
4+
"productName": "Phoenix Code"
5+
}

src-electron/config-staging.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"identifier": "io.phcode.staging",
3+
"stage": "stage",
4+
"productName": "Phoenix Code Pre-release"
5+
}

src-electron/config.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22
* Centralized Configuration Module
33
*
44
* This module provides a single source of truth for all configuration values.
5-
* It reads from package.json and can apply stage-wise transforms as needed.
5+
* It reads from config.json and can apply stage-wise transforms as needed.
66
*
77
* Usage:
88
* const { stage, trustedElectronDomains, productName } = require('./config');
99
*/
1010

11-
const packageJson = require('./package.json');
11+
const configJson = require('./config-effective.json');
1212

13-
// Core package.json values
14-
const name = packageJson.name;
15-
const identifier = packageJson.identifier;
16-
const stage = packageJson.stage;
17-
const version = packageJson.version;
18-
const productName = packageJson.productName;
19-
const description = packageJson.description;
13+
// Core config values
14+
const identifier = configJson.identifier;
15+
const phoenixLoadURL = configJson.phoenixLoadURL;
16+
const stage = configJson.stage;
17+
const version = configJson.version;
18+
const productName = configJson.productName;
2019

2120
// Security configuration
22-
const trustedElectronDomains = packageJson.trustedElectronDomains || [];
21+
const trustedElectronDomains = configJson.trustedElectronDomains || [];
2322

2423
/**
2524
* Initialize configuration (call once at app startup if needed).
@@ -35,13 +34,12 @@ function initConfig() {
3534
}
3635

3736
module.exports = {
38-
// Package info
39-
name,
37+
// App info
4038
identifier,
39+
phoenixLoadURL,
4140
stage,
4241
version,
4342
productName,
44-
description,
4543

4644
// Security
4745
trustedElectronDomains,

src-electron/config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"identifier": "io.phcode.dev",
3+
"phoenixLoadURL": "http://localhost:8000/src/",
4+
"stage": "dev",
5+
"trustedElectronDomains": ["phtauri://localhost/", "https://phcode.dev/"],
6+
"version": "5.0.5",
7+
"productName": "Phoenix Code Experimental Build"
8+
}

src-electron/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { registerCredIpcHandlers } = require('./main-cred-ipc');
88
const { registerWindowIpcHandlers, registerWindow } = require('./main-window-ipc');
99
const { assertTrusted } = require('./ipc-security');
1010
const { getWindowOptions, trackWindowState, DEFAULTS } = require('./window-state');
11+
const { phoenixLoadURL } = require('./config');
1112

1213
// Request single instance lock - only one instance of the app should run at a time
1314
const gotTheLock = app.requestSingleInstanceLock();
@@ -54,8 +55,8 @@ async function createWindow() {
5455
// uncomment line below if you want to open dev tools at app start
5556
// win.webContents.openDevTools();
5657

57-
// Load the test page from the http-server
58-
win.loadURL('http://localhost:8000/src/');
58+
// Load Phoenix from configured URL
59+
win.loadURL(phoenixLoadURL);
5960
}
6061

6162
async function gracefulShutdown(exitCode = 0) {

0 commit comments

Comments
 (0)