Use channel mac executable identity

This commit is contained in:
PerishCode 2026-05-14 19:35:51 +08:00
parent 7ea77cf8b1
commit 9ef4b1c048
6 changed files with 31 additions and 5 deletions

View file

@ -104,7 +104,7 @@ export async function runElectronBuilder(
},
electronDist: config.electronDistPath,
electronVersion: config.electronVersion,
executableName: PRODUCT_NAME,
executableName: identity.executableName,
extraMetadata: {
main: "./main.cjs",
name: "open-design-packaged-app",

View file

@ -5,6 +5,7 @@ import { PRODUCT_NAME } from "./constants.js";
export type MacInstallIdentity = {
appId: string;
executableName: string;
productName: string;
publicAppBundleName: string;
systemAppBundleName: string;
@ -36,6 +37,7 @@ export function resolveMacInstallIdentity(config: Pick<ToolPackConfig, "namespac
return {
...channelIdentity,
executableName: channelIdentity.productName,
publicAppBundleName,
systemAppBundleName,
};

View file

@ -133,7 +133,7 @@ function commandMatchesDesktopMarker(
command: string,
marker: DesktopRootIdentityMarker,
): boolean {
return command.includes(marker.executablePath) || command.includes(macAppExecutablePath(marker.appPath));
return command.includes(marker.executablePath) || command.includes(macAppExecutablePath(marker.appPath, basename(marker.executablePath)));
}
async function resolveDesktopRootIdentityFallback(config: ToolPackConfig): Promise<{
@ -446,6 +446,7 @@ async function resolvePackedMacStartTarget(config: ToolPackConfig): Promise<{
source: MacStartSource;
}> {
const paths = resolveMacPaths(config);
const identity = resolveMacInstallIdentity(config);
const candidates: Array<{ appPath: string; source: MacStartSource }> = [
{ appPath: paths.installedAppPath, source: "installed" },
{ appPath: paths.userApplicationsAppPath, source: "user-applications" },
@ -454,7 +455,7 @@ async function resolvePackedMacStartTarget(config: ToolPackConfig): Promise<{
];
for (const candidate of candidates) {
const executablePath = macAppExecutablePath(candidate.appPath);
const executablePath = macAppExecutablePath(candidate.appPath, identity.executableName);
if (await pathExists(executablePath)) {
return { ...candidate, executablePath };
}

View file

@ -25,8 +25,8 @@ export function macAppBundleName(namespace: string): string {
return `${PRODUCT_NAME}.${sanitizeNamespace(namespace)}.app`;
}
export function macAppExecutablePath(appPath: string): string {
return join(appPath, "Contents", "MacOS", PRODUCT_NAME);
export function macAppExecutablePath(appPath: string, executableName = PRODUCT_NAME): string {
return join(appPath, "Contents", "MacOS", executableName);
}
export function resolveMacAppOutputDirectoryName(): string {

View file

@ -56,6 +56,7 @@ describe("resolveMacInstallIdentity", () => {
expect(resolveMacInstallIdentity(config)).toEqual({
appId: "io.open-design.desktop.beta",
executableName: "Open Design Beta",
productName: "Open Design Beta",
publicAppBundleName: "Open Design Beta.app",
systemAppBundleName: "Open Design Beta.app",
@ -68,6 +69,7 @@ describe("resolveMacInstallIdentity", () => {
expect(resolveMacInstallIdentity(config)).toEqual({
appId: "io.open-design.desktop.preview",
executableName: "Open Design Preview",
productName: "Open Design Preview",
publicAppBundleName: "Open Design Preview.app",
systemAppBundleName: "Open Design Preview.app",

View file

@ -146,4 +146,25 @@ describe("startPackedMacApp", () => {
await rm(root, { force: true, recursive: true });
}
});
it("uses the preview executable name for preview release namespaces", async () => {
const root = await mkdtemp(join(tmpdir(), "open-design-tools-pack-mac-lifecycle-"));
try {
const config = makeConfig(root, { namespace: "release-preview" });
const paths = resolveMacPaths(config);
const executablePath = join(paths.installedAppPath, "Contents", "MacOS", "Open Design Preview");
await mkdir(join(paths.installedAppPath, "Contents", "MacOS"), { recursive: true });
await writeFile(executablePath, "#!/bin/sh\nexit 0\n", "utf8");
await chmod(executablePath, 0o755);
const result = await startPackedMacApp(config);
expect(result.source).toBe("installed");
expect(result.executablePath).toBe(executablePath);
expect(result.status?.state).toBe("running");
} finally {
await rm(root, { force: true, recursive: true });
}
});
});