Commit d21ff2dd authored by edy's avatar edy

feat(desktop): support home image fallback and dev dock icon

parent 43eb29a5
import path from "node:path";
import { access, appendFile, readFile, writeFile } from "node:fs/promises";
import { BrowserWindow, app } from "electron";
import { BrowserWindow, app, nativeImage } from "electron";
import { GatewayClient } from "@qjclaw/gateway-client";
import { RuntimeManager } from "@qjclaw/runtime-manager";
import type { AppConfig, RuntimeCloudFetchAction, RuntimeModePreference, SaveConfigInput, SystemSummary } from "@qjclaw/shared-types";
......@@ -212,6 +212,45 @@ async function countFilePatternMatches(filePath: string, pattern: string): Promi
}
}
async function firstExistingPath(paths: string[]): Promise<string | undefined> {
for (const candidate of paths) {
try {
await access(candidate);
return candidate;
} catch {
// Try the next candidate.
}
}
return undefined;
}
async function resolveDevelopmentApplicationIconPath(systemSummary: SystemSummary): Promise<string | undefined> {
if (systemSummary.isPackaged) {
return undefined;
}
const projectDir = path.resolve(systemSummary.appPath);
return firstExistingPath([
path.join(projectDir, "build", "icon.png"),
path.join(projectDir, "build", "icons", "brand-icon.png")
]);
}
async function configureDevelopmentDockIcon(systemSummary: SystemSummary): Promise<string | undefined> {
const iconPath = await resolveDevelopmentApplicationIconPath(systemSummary);
if (!iconPath || process.platform !== "darwin" || systemSummary.isPackaged || !app.dock) {
return iconPath;
}
const icon = nativeImage.createFromPath(iconPath);
if (!icon.isEmpty()) {
app.dock.setIcon(icon);
}
return iconPath;
}
function snapshotMainWindowState(window: BrowserWindow | null): Record<string, unknown> {
if (!window || window.isDestroyed()) {
return {
......@@ -2097,6 +2136,8 @@ async function bootstrap(): Promise<void> {
startupLogger = new StartupLogger(systemSummary.logsPath);
startupLoggerRef = startupLogger;
await traceBootstrap("when-ready", { isPackaged: systemSummary.isPackaged, userDataPath: systemSummary.userDataPath, logsPath: systemSummary.logsPath, smokeEnabled, smokeCloudBootstrapEnabled });
const developmentIconPath = await configureDevelopmentDockIcon(systemSummary);
await traceBootstrap("development-icon-configured", { developmentIconPath });
const configService = new AppConfigService(systemSummary.userDataPath);
const config = await configService.load();
......@@ -2469,8 +2510,3 @@ if (!hasSingleInstanceLock) {
This diff is collapsed.
......@@ -1368,4 +1368,3 @@ export class ProjectBundleService {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment