forked from boos/BoosAPI
6c51801e50
- Implemented afterPack script to ensure ad-hoc signature for macOS builds. - Created macosSignUtils module to handle app path retrieval, signature inspection, and ad-hoc signing. - Added functions to check if the app is signed and apply ad-hoc signing if necessary.
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import { execFile } from 'node:child_process';
|
|
import { promisify } from 'node:util';
|
|
|
|
const execFileAsync = promisify(execFile);
|
|
|
|
export function getMacAppPath(context) {
|
|
return `${context.appOutDir}/${context.packager.appInfo.productFilename}.app`;
|
|
}
|
|
|
|
export async function inspectSignature(appPath) {
|
|
try {
|
|
const { stdout, stderr } = await execFileAsync('codesign', ['-dv', '--verbose=4', appPath]);
|
|
const output = `${stdout}\n${stderr}`;
|
|
return {
|
|
signed: true,
|
|
isAdHoc: /Signature=adhoc/i.test(output) || !/Authority=/i.test(output),
|
|
details: output,
|
|
};
|
|
} catch {
|
|
return {
|
|
signed: false,
|
|
isAdHoc: false,
|
|
details: '',
|
|
};
|
|
}
|
|
}
|
|
|
|
export async function adHocSign(appPath) {
|
|
await execFileAsync('codesign', ['--force', '--deep', '--sign', '-', appPath]);
|
|
}
|
|
|
|
export async function ensureAdHocSignature(appPath) {
|
|
const signature = await inspectSignature(appPath);
|
|
if (signature.signed) {
|
|
return signature;
|
|
}
|
|
|
|
console.log('[metapi-desktop] No macOS signing identity detected, applying ad-hoc signature.');
|
|
await adHocSign(appPath);
|
|
return inspectSignature(appPath);
|
|
}
|