I am using electron-builder to build my Electron and React app. When running locally it has apple automation permissions through the terminal
Automation preferences
However, when I build the App using electron-builder, the finished app does not allow any automation scripts to be run such as osascript for iMessage. Is there any reason why a notorized Electron app would not be given access to this?
Script I run: "package": "ts-node ./.erb/scripts/clean.js dist && npm run build && electron-builder build --publish never"
I am using codesign:
My package.json
"build": {
"buildVersion": "1",
"productName": "MyApp",
"appId": "me.hacker.myapp",
"asar": true,
"asarUnpack": "**\\*.{node,dll}",
"files": [
"dist",
"node_modules",
"package.json"
],
"afterSign": ".erb/scripts/notarize.js",
"mac": {
"target": {
"target": "default",
"arch": [
"arm64",
"x64"
]
},
"type": "distribution",
"hardenedRuntime": true,
"entitlements": "assets/entitlements.mac.plist",
"entitlementsInherit": "assets/entitlements.mac.plist",
"gatekeeperAssess": false
},
"dmg": {
"contents": [
{
"x": 130,
"y": 220
},
{
"x": 410,
"y": 220,
"type": "link",
"path": "/Applications"
}
]
},
"win": {
"target": [
"nsis"
]
},
"linux": {
"target": [
"AppImage"
],
"category": "Development"
},
"directories": {
"app": "release/app",
"buildResources": "assets",
"output": "release/build"
},
"extraResources": [
"./assets/**"
],
"publish": {
"provider": "github",
"owner": "electron-react-boilerplate",
"repo": "electron-react-boilerplate"
}
And my notorize script:
const x = await notarize({
appBundleId: build.appId,
appPath: `${appOutDir}/${appName}.app`,
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_ID_PASS,
ascProvider: '000000',
});
And the entitlements:
<!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.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.automation.apple-events</key>
<true/>
</dict>
</plist>
Related
I am using electron-builder to build mac and windows app. Abouve is my electron build output directory. I don't need autoupdater. So I just wanna .dmg and .exe files. How can I set builder config to diable electron generate those useless files(yal、yaml、zip、zip.blockmap)?
Below is my package.json
"build": {
"appId": "we-media-helper",
"copyright": "Copyright © 2022 Eve-Sama",
"generateUpdatesFilesForAllChannels": true,
"directories": {
"output": "./dist/installer"
},
"mac": {
"target": {
"target": "default",
"arch": [
"arm64",
"x64",
"universal"
]
},
"icon": "./assets/icons/mac-dock.icns",
"publish": {
"owner": "Eve-Sama",
"repo": "we-media-helper",
"provider": "github"
}
},
"dmg": {
"writeUpdateInfo": false
},
"nsis": {
"differentialPackage": false,
"oneClick": false,
"allowElevation": true,
"allowToChangeInstallationDirectory": true,
"installerIcon": "./assets/icons/win-taskbar.ico",
"uninstallerIcon": "./assets/icons/win-taskbar.ico",
"installerHeaderIcon": "./assets/icons/win-taskbar.ico",
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"artifactName": "${productName}_Setup_${version}.${ext}"
},
"win": {
"icon": "./assets/icons/win-taskbar.ico",
"target": [
{
"target": "nsis",
"arch": [
"ia32"
]
}
]
},
"files": [
"**/*",
"!dist/installer",
"!**/*.ts",
"!**/*.tsx",
"!src/",
"!public/",
"!.eslintignore",
"!.eslintrc.js",
"!.gitignore",
"!.prettierrc",
"!gulpfile.ts",
"!LICENSE",
"!package-lock.json",
"!README.md",
"!tsconfig.json",
"!yarn.lock"
],
"extends": null
},
And I have another question. As you can see, I set mac.target.arch as ['arm64', 'x64', 'universal']. And output directory contains folder mac rather than mac-x64. why? How can I set it as mac-x64
this is my first time building an electron app and I am getting confused about this error I got in my production package.
I've created my app using the electron-react-boilerplate, and I am running the package build with the default config.
"build": {
"productName": "App",
"appId": "org.erb.ElectronReact",
"asar": true,
"asarUnpack": "**\\*.{node,dll}",
"files": [
"dist",
"node_modules",
"package.json"
],
"afterSign": ".erb/scripts/notarize.js",
"mac": {
"target": {
"target": "default",
"arch": [
"arm64",
"x64"
]
},
"type": "distribution",
"hardenedRuntime": true,
"entitlements": "assets/entitlements.mac.plist",
"entitlementsInherit": "assets/entitlements.mac.plist",
"gatekeeperAssess": false
},
"dmg": {
"contents": [
{
"x": 130,
"y": 220
},
{
"x": 410,
"y": 220,
"type": "link",
"path": "/Applications"
}
]
},
"win": {
"target": [
"nsis"
]
},
"linux": {
"target": [
"AppImage"
],
"category": "Development"
},
"directories": {
"app": "release/app",
"buildResources": "assets",
"output": "release/build"
},
"extraResources": [
"./assets/**"
]
},
My preload.js file is requiring a module (module.umd.js) that is reading from three .trie files, so my folder structure looks like this:
Once builded, the app is not working and I see this error on the web console inspector:
Error: ENOENT, dist\main\data.trie not found in C:\Users\ivan\Desktop\app-electron\release\build\win-unpacked\resources\app.asar
So my question is: Do I have to somehow add those .trie files in app.asar in order to solve this problem?
This is my electron.manifest.json
{
"executable": "MyApplication.UI",
"splashscreen": {
"imageFile": "/wwwroot/assets/Animation.svg"
},
"author": "MyCompany",
"environment": "Production",
"singleInstance": false,
"build": {
"appId": "com.mycompany.myapplication",
"productName": "MyApplication",
"copyright": "Copyright # 2022",
"buildVersion": "2022.1.0",
"compression": "maximum",
"fileAssociations": [
{
"ext": "sdg",
"name": "MyApplication File",
"role": "Editor"
}
],
"publish": {
"provider": "generic",
"url": "https://mydomain.io/Installer/MyApplication/",
"channel": "latest"
},
"nsis": {
"allowToChangeInstallationDirectory": true,
"oneClick": false,
"perMachine": true,
"installerIcon": "bin/Assets/icon.ico",
"uninstallerIcon": "bin/Assets/icon.ico",
"installerHeaderIcon": "bin/Assets/icon.ico",
"menuCategory": true
},
"win": {
"target": [
"nsis"
],
"icon": "Assets/icon.ico"
},
"linux": {
"target": "deb",
"maintainer": "MyCompany",
"vendor": "MyCompany",
"synopsis": "MyApplication",
"executableName": "MyApplication",
"description": "Doing some magic.",
"category": "Development",
"icon": "./../../Assets/Icons/32x32.png"
},
"directories": {
"output": "../../../bin/Installer",
"buildResources": "Assets"
},
"extraResources": [
{
"from": "./bin",
"to": "bin",
"filter": [
"**/*"
]
}
],
"files": [
{
"from": "./ElectronHostHook/node_modules",
"to": "ElectronHostHook/node_modules",
"filter": [
"**/*"
]
},
"**/*"
]
}
}
The created .deb file when building for linux is called electron-net_{version}.deb. That wouldn't be a problem but when executed, the application name electron-net is shown.
How can I change that? I checked the documentation (here https://www.electron.build/configuration/linux) already but I dont see any more options in my config?
I am using ElectronNET.CLI Version 15.5.1 on Ubuntu 20.04.4, .NET Version 5.0.406
I think you're looking for the artifactName property under build for your file name and the name property under at root for the name that is displayed
{
"name" : "MyApplication",
"executable" : "MyApplication",
"build": {
"artifactName": "my-application.${ext}",
}
}
this is my first time working with service workers and I am having difficulties because I always get this error in the Network - Application - Manifest tab:
Some technical details:
package.json
"#angular/animations": "~9.1.0",
"#angular/common": "~9.1.0",
"#angular/compiler": "~9.1.0",
"#angular/core": "~9.1.0",
"#angular/forms": "~9.1.0",
"#angular/localize": "~9.1.0",
"#angular/platform-browser": "~9.1.0",
"#angular/platform-browser-dynamic": "~9.1.0",
"#angular/pwa": "^0.901.12",
"#angular/router": "~9.1.0",
"#angular/service-worker": "~9.1.0",
angular.json
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "projects/appName/src/environments/environment.ts",
"with": "projects/appName/src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "5mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
],
"serviceWorker": true,
"ngswConfigPath": "projects/appName/src/ngsw-config.json"
manifest.webmanifest
{
"name": "app name",
"short_name": "app",
"description": "test test",
"theme_color": "#003f8b",
"background_color": "#ffffff",
"display": "standalone",
"orientation": "portrait",
"scope": "/",
"start_url": "/",
"icons": [
{
"src": "favicon.ico",
"sizes": "16x16",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/flatwork.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/icon-withdrawal-mark.png",
"sizes": "27x23",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/incoming.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/input.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/master_data_icon.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/outgoing.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/output.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/rental_outfit.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/repair.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/scanned_on.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/tooltip_icon.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
}
]
}
index.html
<meta name="theme-color" content="#003f8b" />
<link rel="manifest" href="manifest.webmanifest" />
<body>
<bar-root></bar-root>
<noscript
>Please enable JavaScript to continue using this application.</noscript
>
</body>
app.module
imports: [
BrowserModule,
ServiceWorkerModule.register('../ngsw-worker.js', {
enabled: environment.production
}),
... // other imports
],
providers: [
{
provide: SwRegistrationOptions,
useFactory: () => ({
enabled: environment.production,
registrationStrategy: 'registerImmediately',
}),
},
]
ngsw-config.json
{
"$schema": "../../../node_modules/#angular/service-worker/config/schema.json",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/manifest.webmanifest",
"/*.css",
"/*.js"
]
}
},
{
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
]
}
}
]
}
Also, here is the project structure to check the path imports:
What am I missing? Also, what is the best way to test any config changes?
I found a solution regarding my issue, some small changes were required:
app.module - adjusted the service worker registration
ServiceWorkerModule.register('ngsw-worker.js', {
enabled: environment.production,
// Register the ServiceWorker as soon as the app is stable
// or after 30 seconds (whichever comes first).
registrationStrategy: 'registerWhenStable:30000',
}),
In angular.json if you have multiple builds for different environments, lets say production and qa, you can add these configs on both:
"serviceWorker": true,
"ngswConfigPath": "projects/appName/ngsw-config.json"
// or whichever path you have for the ngsw-config.json, but this will probably be generated automatically when installing #angular/pwa.
To test your changes, run ng build or ng build --prod or any other environments you want to test on.
To see the build for the prod environment I used http-server, which you can find in npm and install it. Your build will be created in a dist folder, and in the root folder of the app run(9191 being the port, you can change it to whatever you like, just make sure nothing runs on it):
http-server -p 9191 -c-1 dist/appName
You can open you 9191 localhost port and check in the Deveoper Tools, Application tab, under Manifest and Service Workers to make sure everything is running.
I also removed ngsw-worker.js from my project because it is moved automatically from node_modules when you do the builds.
I am using electron-builder taking nsis as target for making windows installer.
electron version is 1.7.9
electron-builder version is 19.40.0
Below are the package.json build config for windows setup.
"build": {
"appId": "com.conveyant.dispatcher",
"directories": {
"output": "./dist"
},
"mac": {
"category": "public.app-category.business"
},
"dmg": {
"contents": [
{
"x": 110,
"y": 150
},
{
"x": 240,
"y": 150,
"type": "link",
"path": "/Applications"
}
]
},
"win": {
"icon": "build/icon.ico",
"target": "nsis"
},
"nsis": {
"allowElevation": false,
"allowToChangeInstallationDirectory": true,
"oneClick": false,
"perMachine": true
}
}
It will create a win-package and windows installer, but installer will not working it shows error message
Error! Can't initialize plug-ins directory.Please try again later.