Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src-build/ci-setupDistFolders.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { EOL } from "os";
import os from "os";
import fs from 'fs';
import {patchTauriConfigWithMetricsHTML} from "./utils.js";
import {patchTauriConfigWithMetricsHTML, patchElectronStageBranding} from "./utils.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down Expand Up @@ -182,6 +182,8 @@ function createElectronReleaseAssets() {
console.log('gaMetricsURL:', effectiveConfig.gaMetricsURL);
console.log('version:', effectiveConfig.version);
fs.writeFileSync(configEffectivePath, JSON.stringify(effectiveConfig, null, 2));

patchElectronStageBranding(electronDir, effectiveConfig.productName);
}

ciCreateTauriDistReleaseConfig();
Expand Down
4 changes: 3 additions & 1 deletion src-build/createDistRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { dirname, join } from 'path';
import fs from 'fs';
import * as os from 'os';
import chalk from 'chalk';
import { getPlatformDetails, patchTauriConfigWithMetricsHTML } from './utils.js';
import { getPlatformDetails, patchTauriConfigWithMetricsHTML, patchElectronStageBranding } from './utils.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down Expand Up @@ -164,6 +164,8 @@ function createElectronConfig() {
console.log('gaMetricsURL:', effectiveConfig.gaMetricsURL);
console.log('version:', effectiveConfig.version);
fs.writeFileSync(configEffectivePath, JSON.stringify(effectiveConfig, null, 2));

patchElectronStageBranding(electronDir, effectiveConfig.productName);
}

function buildElectron() {
Expand Down
4 changes: 3 additions & 1 deletion src-build/createDistTestRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { dirname, join } from 'path';
import fs from 'fs';
import * as os from 'os';
import chalk from 'chalk';
import { getPlatformDetails } from './utils.js';
import { getPlatformDetails, patchElectronStageBranding } from './utils.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down Expand Up @@ -160,6 +160,8 @@ function createElectronConfig() {
console.log('gaMetricsURL:', effectiveConfig.gaMetricsURL);
console.log('version:', effectiveConfig.version);
fs.writeFileSync(configEffectivePath, JSON.stringify(effectiveConfig, null, 2));

patchElectronStageBranding(electronDir, effectiveConfig.productName);
}

function buildElectron() {
Expand Down
4 changes: 3 additions & 1 deletion src-build/createSrcRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { dirname, join } from 'path';
import fs from 'fs';
import * as os from 'os';
import chalk from 'chalk';
import { getPlatformDetails } from './utils.js';
import { getPlatformDetails, patchElectronStageBranding } from './utils.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down Expand Up @@ -136,6 +136,8 @@ function createElectronConfig() {
console.log('gaMetricsURL:', effectiveConfig.gaMetricsURL);
console.log('version:', effectiveConfig.version);
fs.writeFileSync(configEffectivePath, JSON.stringify(effectiveConfig, null, 2));

patchElectronStageBranding(electronDir, effectiveConfig.productName);
}

function buildElectron() {
Expand Down
29 changes: 29 additions & 0 deletions src-build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,35 @@ const METRIC_URL_FOR_STAGE = {
"production": "https://phcode.dev/desktop-metrics.html"
};

/**
* Patches the electron build inputs so each stage has a unique app identity:
* - src-electron/package.json `desktopName` (Electron 41.5+ uses this as the Wayland app_id)
* - src-electron/electron-builder.yml `productName` (becomes the .desktop StartupWMClass + binary name)
* Both are set to the kebab-case form of `productName` so they match. Without matching values,
* the running window can't be paired to its .desktop entry and falls back to the generic Electron icon.
*
* @param {string} electronDir - absolute path to src-electron/
* @param {string} productName - stage-specific display name from config-effective.json
* (e.g. "Phoenix Code", "Phoenix Code Pre-release", "Phoenix Code Experimental Build")
*/
export function patchElectronStageBranding(electronDir, productName) {
const appId = productName.toLowerCase().trim().replace(/\s+/g, '-');
console.log(`Patching electron stage branding -> ${appId}`);

const pkgPath = path.join(electronDir, 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath));
pkg.desktopName = appId;
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));

const builderPath = path.join(electronDir, 'electron-builder.yml');
const builderYml = fs.readFileSync(builderPath, 'utf8');
const productNameRegex = /^productName:.*$/m;
if (!productNameRegex.test(builderYml)) {
throw new Error(`Could not find productName line in ${builderPath}`);
}
fs.writeFileSync(builderPath, builderYml.replace(productNameRegex, `productName: ${appId}`));
}

export function patchTauriConfigWithMetricsHTML(tauriConf, useClonedPhoenix) {
const platform = getPlatformDetails().platform;
let phoenixConfigPath = (platform === "win") ? `${__dirname}\\..\\..\\phoenix\\dist\\config.json`
Expand Down
4 changes: 3 additions & 1 deletion src-electron/electron-builder.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appId: io.phcode.dev
productName: phoenix-code
productName: phoenix-code-experimental-build
copyright: Copyright © 2024 phcode.dev

asar: true
Expand Down Expand Up @@ -27,6 +27,8 @@ extraResources:
to: "bin"
- from: "phoenix-dist"
to: "phoenix-dist"
- from: "../src-tauri/icons/icon.png"
to: "icon.png"

extraMetadata:
main: main.js
Expand Down
4 changes: 3 additions & 1 deletion src-electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ async function createWindow() {
contextIsolation: true,
nodeIntegration: false
},
icon: path.join(__dirname, '..', 'src-tauri', 'icons', 'icon.png')
icon: app.isPackaged
? path.join(process.resourcesPath, 'icon.png')
: path.join(__dirname, '..', 'src-tauri', 'icons', 'icon.png')
});

// Track window state for persistence
Expand Down
12 changes: 6 additions & 6 deletions src-electron/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src-electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"version": "5.1.8",
"productName": "Phoenix Code Experimental Build",
"desktopName": "phoenix-code-experimental-build",
"description": "Phoenix Code Experimental Build",
"main": "main.js",
"scripts": {
Expand All @@ -19,7 +20,7 @@
"keytar": "^7.9.0"
},
"devDependencies": {
"electron": "^41.1.1",
"electron": "^41.5.1",
"electron-builder": "^24.13.3"
}
}
Loading