mas-dev build won't show open file dialog on an electron app

247 Views Asked by At

I've been trying to pack and sign my electron app using this guide. I've signed the app and am able to open app, however, I'm unable to show the open file dialog. Here is the relevant code and configs:

package.json

"scripts": {
"build": "tsc",
"watch": "tsc -w",
"lint": "tslint -c tslint.json -p tsconfig.json",
"copy": "copyfiles -u 1 src/**/*.html src/**/*.css src/**/*.js dist/ && copyfiles -u 1 src/ui/assets/**/*.* dist/ && copyfiles package.json dist/",
"buildAndCopy": "npm run build && npm run copy",
"start": "npm run build && npm run copy && npm run pack && electron dist/main.js",
"test": "npm run buildAndCopy && jest --testPathPattern=tests/ --coverage",
"uitest": "npm run buildAndCopy && jest --testPathPattern=uitests/",
"pack": "npm run buildAndCopy && electron-builder --dir --config electron-builder.json -c.extraMetadata.main=dist/main.js",
"dist": "npm run buildAndCopy && electron-builder --config electron-builder.json -c.extraMetadata.main=dist/main.js",
"sign-mas": "electron-osx-sign artifacts/mas-dev/DiffLens.app --identity='Apple Development' --provisioning-profile=build/AppleDevelopment.provisionprofile",
"sign-mac": "electron-osx-sign artifacts/mac/DiffLens.app --identity='Apple Development' --provisioning-profile=build/AppleDevelopment.provisionprofile"

electron-builder.json

.
.
.
"files": [
    "dist/**/*",
    "node_modules/**/*",
    "lib/**/*",
    "package.json"
],
"mac": {
  "category": "public.app-category.developer-tools",
  "electronLanguages": ["en"],
  "target": "mas-dev",
  "type": "development",
  "hardenedRuntime": true,
  "gatekeeperAssess": false,
  "icon": "build/icon.icns",
  "entitlements": "build/entitlements.mas.plist",
  "entitlementsInherit": "build/entitlements.mas.inherit.plist",
  "provisioningProfile": "build/AppleDevelopment.provisionprofile"
}

build/entitlements.mas.plist

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.application-groups</key>
    <array>
        <string>com.difflens.mac</string>
    </array>
    <key>com.apple.security.files.downloads.read-write</key>
    <true/>
    <key>com.apple.security.files.user-selected.read-write</key>
    <true/>
</dict>
</plist>

I have a menu option in my app (File -> Open) which in turn calls

let result = dialog.showOpenDialogSync(Globals.getMainWindow()); When I try to open a file, the app just gets stuck. The open dialog box never appears (almost as if MacOS is restricting my app from accessing system files). I tried looking in Console -> System Log but nothing caught my eye there. AFAICT, I've specified com.apple.security.files.downloads.read-write in the .plist file, so I should be able to do open files. What am I missing? How do I debug this?

For reference, I build the app by running npm run dist first and then signing it with npm run sign-mas. The app works perfectly when I run it locally i.e. by just running npm run start. The error only occurs when I try to run the packaged version produced by electron builder. Any help is greatly appreciated!

0

There are 0 best solutions below