Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Fix "identity of the developer cannot be confirmed" bug when capturing screenshot on macOS #266

Merged
merged 2 commits into from
Dec 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ jobs:
env:
CI: true
CI_PULL_REQUEST: ${{ github.event_name == 'pull_request' }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }}
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
CSC_LINK: ${{ secrets.CSC_LINK }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
Binary file not shown.
18 changes: 0 additions & 18 deletions build-resources/entitlements.mac.inherit.plist

This file was deleted.

18 changes: 0 additions & 18 deletions build-resources/entitlements.mac.plist

This file was deleted.

63 changes: 9 additions & 54 deletions dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,13 @@ const fs = require('fs-extra');
const builder = require('electron-builder');
const glob = require('glob');
const del = require('del');
const { notarize } = require('electron-notarize');
const semver = require('semver');
const { exec, spawn } = require('child_process');
const { spawn } = require('child_process');
const { getSignVendorPath } = require('app-builder-lib/out/codeSign/windowsCodeSign');

const packageJson = require('./package.json');
const displayLanguages = require('./public/libs/locales/languages');

// sometimes, notarization works but *.app does not have a ticket stapled to it
// this ensure the *.app has the notarization ticket
const verifyNotarizationAsync = (filePath) => new Promise((resolve, reject) => {
// eslint-disable-next-line no-console
console.log(`xcrun stapler validate ${filePath.replace(/ /g, '\\ ')}`);

exec(`xcrun stapler validate ${filePath.replace(/ /g, '\\ ')}`, (e, stdout, stderr) => {
if (e instanceof Error) {
reject(e);
return;
}

if (stderr) {
reject(new Error(stderr));
return;
}

if (stdout.indexOf('The validate action worked!') > -1) {
resolve(stdout);
} else {
reject(new Error(stdout));
}
});
});

// https://stackoverflow.com/a/17466459
const runCmd = (cmd, args, callBack) => {
const child = spawn(cmd, args);
Expand All @@ -59,8 +33,8 @@ const appVersion = fs.readJSONSync(path.join(__dirname, 'package.json')).version
let targets;
switch (process.platform) {
case 'darwin': {
targets = Platform.MAC.createTarget(['mas'], Arch.universal);
// targets = Platform.MAC.createTarget(['mas-dev'], Arch.universal);
// targets = Platform.MAC.createTarget(['mas'], Arch.universal);
targets = Platform.MAC.createTarget([process.env.FORCE_DEV ? 'mas-dev' : 'mas'], Arch.universal);
break;
}
case 'win32': {
Expand All @@ -77,6 +51,9 @@ switch (process.platform) {
const opts = {
targets,
config: {
asarUnpack: [
'node_modules/node-mac-permissions/build',
],
appId: 'com.moderntranslator.app', // Backward compatibility
// https://github.com/electron-userland/electron-builder/issues/3730
buildVersion: process.platform === 'darwin' ? appVersion : undefined,
Expand Down Expand Up @@ -109,8 +86,9 @@ const opts = {
},
mas: {
category: 'public.app-category.productivity',
provisioningProfile: 'build-resources/embedded.provisionprofile',
// provisioningProfile: 'build-resources/embedded-development.provisionprofile', # mas-dev
provisioningProfile: process.env.FORCE_DEV
? 'build-resources/embedded-development.provisionprofile' // mas-dev
: 'build-resources/embedded.provisionprofile',
darkModeSupport: true,
},
linux: {
Expand Down Expand Up @@ -174,29 +152,6 @@ const opts = {
resolve();
}
}),
afterSign: (context) => {
// Only notarize app when forced in pull requests or when releasing using tag
const shouldNotarize = process.platform === 'darwin' && context.electronPlatformName === 'darwin' && process.env.CI_BUILD_TAG;
if (!shouldNotarize) return null;

console.log('Notarizing app...');
// https://kilianvalkhof.com/2019/electron/notarizing-your-electron-application/
const { appOutDir } = context;

const appName = context.packager.appInfo.productFilename;
const appPath = `${appOutDir}/${appName}.app`;
return notarize({
appBundleId: 'com.moderntranslator.app',
appPath,
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_ID_PASSWORD,
})
.then(() => verifyNotarizationAsync(appPath))
.then((notarizedInfo) => {
// eslint-disable-next-line no-console
console.log(notarizedInfo);
});
},
},
};

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test-ui": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"dist": "yarn run build && babel-node dist.js",
"dist-dev": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false yarn dist",
"dist-dev": "cross-env FORCE_DEV=1 yarn dist",
"lint": "eslint ./src ./public ./*.js ./test --ext js",
"test": "mocha"
},
Expand Down Expand Up @@ -53,7 +53,6 @@
"dotenv": "8.2.0",
"electron": "11.1.1",
"electron-builder": "22.10.4",
"electron-notarize": "1.0.0",
"eslint": "6.8.0",
"eslint-config-airbnb": "18.2.1",
"eslint-plugin-header": "3.1.0",
Expand Down
1 change: 1 addition & 0 deletions public/preload/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ window.ipcRenderer = ipcRenderer;
window.desktopCapturer = desktopCapturer;

window.machineId = machineId.machineIdSync();
window.macPermissions = process.platform === 'darwin' ? require('node-mac-permissions') : null;
5 changes: 2 additions & 3 deletions src/helpers/take-screenshot-to-blob-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ const takeScreenshotToBlob = () => {
// shell.openExternal('x-apple.systempreferences...') is not sufficient as it doesn't ensure
// the app is added to app list in system pref
if (window.process.platform === 'darwin') {
const permissions = window.remote.require('node-mac-permissions');
const authStatus = permissions.getAuthStatus('screen');
const authStatus = window.macPermissions.getAuthStatus('screen');
if (authStatus === 'denied' || authStatus === 'restricted') {
permissions.askForScreenCaptureAccess();
window.macPermissions.askForScreenCaptureAccess();
return Promise.resolve();
}
}
Expand Down
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5436,14 +5436,6 @@ electron-is-dev@1.2.0:
resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-1.2.0.tgz#2e5cea0a1b3ccf1c86f577cee77363ef55deb05e"
integrity sha512-R1oD5gMBPS7PVU8gJwH6CtT0e6VSoD0+SzSnYpNm+dBkcijgA+K7VAMHDfnRq/lkKPZArpzplTW6jfiMYosdzw==

electron-notarize@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/electron-notarize/-/electron-notarize-1.0.0.tgz#bc925b1ccc3f79e58e029e8c4706572b01a9fd8f"
integrity sha512-dsib1IAquMn0onCrNMJ6gtEIZn/azG8hZMCYOuZIMVMUeRMgBYHK1s5TK9P8xAcrAjh/2aN5WYHzgVSWX314og==
dependencies:
debug "^4.1.1"
fs-extra "^9.0.1"

electron-positioner@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/electron-positioner/-/electron-positioner-4.1.0.tgz#e158f8f6aabd6725a8a9b4f2279b9504bcbea1b0"
Expand Down