notarize icon indicating copy to clipboard operation
notarize copied to clipboard

fix: app name contains spaces

Open heyikang opened this issue 1 year ago • 9 comments

fix #193

heyikang avatar May 09 '24 07:05 heyikang

App Name: 900 TG

• Notarizing app: /path/to/dist/mac-arm64/900 TG.app ⨯ Failed to display codesign info on your application with code: 1

900 TG.app: No such process Failed to codesign your application with code: 1 900 TG.app: No such process 900 TG.app: No such process

This PR fixed this issue

kangfenmao avatar Aug 27 '24 11:08 kangfenmao

@MarshallOfSound This PR actually solves the fact that the spawn of the codesign MacOS utility has the correct fullpath to the packaged app.

The previous version would simply try to codesign the packaged app in the current working directory (which is wrong of course) because of wrong arguments passing. Which causes official Electron boilerplates like (https://www.electronforge.io/templates/vite-+-typescript) to fail to pass the signing step when using yarn make.

shide1989 avatar Sep 09 '24 17:09 shide1989

When notarizing, using a relative path for the codesign parameter and an application name with spaces causes the notarization to fail. This issue does not occur with absolute paths.

heyikang avatar Sep 28 '24 16:09 heyikang

For usage with https://www.npmjs.com/package/patch-package

Create file patches/@electron+notarize+2.3.2.patch with following content:

diff --git a/node_modules/@electron/notarize/lib/check-signature.js b/node_modules/@electron/notarize/lib/check-signature.js
index 324568a..c3d65f8 100644
--- a/node_modules/@electron/notarize/lib/check-signature.js
+++ b/node_modules/@electron/notarize/lib/check-signature.js
@@ -41,16 +41,14 @@ const spawn_1 = require("./spawn");
 const debug_1 = __importDefault(require("debug"));
 const d = (0, debug_1.default)('electron-notarize');
 const codesignDisplay = (opts) => __awaiter(void 0, void 0, void 0, function* () {
-    const result = yield (0, spawn_1.spawn)('codesign', ['-dv', '-vvvv', '--deep', path.basename(opts.appPath)], {
+    const result = yield (0, spawn_1.spawn)('codesign', ['-dv', '-vvvv', '--deep', opts.appPath], {
         cwd: path.dirname(opts.appPath),
     });
     return result;
 });
 const codesign = (opts) => __awaiter(void 0, void 0, void 0, function* () {
     d('attempting to check codesign of app:', opts.appPath);
-    const result = yield (0, spawn_1.spawn)('codesign', ['-vvv', '--deep', '--strict', path.basename(opts.appPath)], {
-        cwd: path.dirname(opts.appPath),
-    });
+    const result = yield (0, spawn_1.spawn)('codesign', ['-vvv', '--deep', '--strict', opts.appPath]);
     return result;
 });
 function checkSignatures(opts) {

paradite avatar Oct 03 '24 12:10 paradite

I'm seeing this same error even without spaces.

# All of these run in the same folder with App-Name.app

# Does not work
codesign -vvv --deep --strict "App-Name.app"
codesign -vvv --deep --strict "App Name.app"

# Works
codesign -vvv --deep --strict "./App-Name.app"
codesign -vvv --deep --strict "./App Name.app"
codesign -vvv --deep --strict "/Users/<username>/src/app-name/out/mac-arm64/App-Name.app"
codesign -vvv --deep --strict "/Users/<username>/src/app-name/out/mac-arm64/App Name.app"

kelsin avatar Nov 10 '24 02:11 kelsin

Since this was blocking me I ended up replacing @electron/notarize with a very simple (but no error handling for now) script. In my package.json I have:

"build": {
  "mac": {
    "notarize": false
  },
  "afterSign": "electron/notarize.js"
}

as normal. This is the same as if you are writing your own custom @electron/notarize script. My script however is just:

import { execSync } from "node:child_process";

async function notarizing(context) {
  const { electronPlatformName, appOutDir } = context;

  if (electronPlatformName !== "darwin") {
    return;
  }

  if (!process.env.APPLEIDPASS) {
    return;
  }

  const appName = context.packager.appInfo.productFilename;
  const appPath = `${appOutDir}/${appName}.app`;
  const zipPath = `${appOutDir}/${appName}.zip`;
  const appleId = process.env.APPLE_ID;
  const appleIdPassword = process.env.APPLEIDPASS;
  const teamId = process.env.APPLE_TEAM_ID;

  console.log(
    execSync(`ditto -c -k --keepParent "${appPath}" "${zipPath}"`, {
      encoding: "utf8",
    }),
  );

  console.log(
    execSync(
      `xcrun notarytool submit "${zipPath}" --team-id "${teamId}" --apple-id "${appleId}" --password "${appleIdPassword}" --wait`,
      { encoding: "utf8" },
    ),
  );

  console.log(
    execSync(`xcrun stapler staple "${appPath}"`, { encoding: "utf8" }),
  );
}

export default notarizing;

Use as your own risk and make sure to check what environment variables you are using for CI/etc. This is working in my github actions and now my app is being packaged and notarizing again. Clearly the current logic used to run codesign with only the app bundle basename is not working. Until @electron/notarize updates to fix things I'll be using this.

kelsin avatar Nov 10 '24 03:11 kelsin

# All of these run in the same folder with App-Name.app

# Does not work
codesign -vvv --deep --strict "App-Name.app"
codesign -vvv --deep --strict "App Name.app"

# Works
codesign -vvv --deep --strict "./App-Name.app"
codesign -vvv --deep --strict "./App Name.app"
codesign -vvv --deep --strict "/Users/<username>/src/app-name/out/mac-arm64/App-Name.app"
codesign -vvv --deep --strict "/Users/<username>/src/app-name/out/mac-arm64/App Name.app"

Do you mean the following?

# All of these run in the same folder with App-Name.app

# Does not work
codesign -vvv --deep --strict "App-Name.app"
codesign -vvv --deep --strict "App Name.app"

# Works
codesign -vvv --deep --strict "/Users/<username>/src/app-name/out/mac-arm64/App-Name.app"
codesign -vvv --deep --strict "/Users/<username>/src/app-name/out/mac-arm64/App Name.app"

I-Want-ToBelieve avatar May 14 '25 07:05 I-Want-ToBelieve

@MarshallOfSound Mar Hi, Consider merging this PR. There shouldn't be any side effects. Since codesign is closed source, the specific reason is difficult to adjust. This may be a bug in codesign.

I-Want-ToBelieve avatar May 14 '25 07:05 I-Want-ToBelieve