Skip to content
Open
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
26 changes: 17 additions & 9 deletions main/common/system-permissions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {join} from 'path';
import {existsSync, openSync} from 'fs';
import {systemPreferences, shell, dialog, app} from 'electron';
const {hasScreenCapturePermission, hasPromptedForPermission} = require('mac-screen-capture-permissions');
import {getAuthStatus, askForScreenCaptureAccess} from 'node-mac-permissions';
const {ensureDockIsShowing} = require('../utils/dock');

const hasAskedForScreenCapturePermissionsPath = join(app.getPath('userData'), '.has-asked-for-screen-capture-permissions');
let isDialogShowing = false;

const promptSystemPreferences = (options: {message: string; detail: string; systemPreferencesPath: string}) => async ({hasAsked}: {hasAsked?: boolean} = {}) => {
Expand Down Expand Up @@ -73,17 +76,22 @@ const screenCaptureFallback = promptSystemPreferences({
});

export const ensureScreenCapturePermissions = (fallback = screenCaptureFallback) => {
const hadAsked = hasPromptedForPermission();

const hasAccess = hasScreenCapturePermission();

if (hasAccess) {
// Check for screen capture permissions
const status = getAuthStatus('screen');
if (status === 'authorized') {
return true;
}

fallback({hasAsked: !hadAsked});
// If not authorized for screen capture and we haven't already asked, then ask for permissions now
if (!existsSync(hasAskedForScreenCapturePermissionsPath)) {
askForScreenCaptureAccess();
openSync(hasAskedForScreenCapturePermissionsPath, 'w');
return false;
}

// If we've already asked, then prompt user again to give permission
fallback();
return false;
};

export const hasScreenCaptureAccess = () => hasScreenCapturePermission();

export const hasScreenCaptureAccess = () => getAuthStatus('screen') === 'authorized';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"is-online": "^8.4.0",
"lodash": "^4.17.21",
"mac-open-with": "^1.2.3",
"mac-screen-capture-permissions": "^1.1.0",
"mac-windows": "^1.0.0",
"macos-audio-devices": "^1.4.0",
"macos-version": "^5.2.1",
Expand All @@ -69,6 +68,7 @@
"move-file": "^2.0.0",
"nearest-normal-aspect-ratio": "^1.2.1",
"node-mac-app-icon": "^1.4.0",
"node-mac-permissions": "^2.2.1",
"object-hash": "^2.1.1",
"p-cancelable": "^2.1.0",
"p-event": "^4.2.0",
Expand Down
36 changes: 26 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,13 @@ binary-extensions@^2.0.0:
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==

bindings@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==
dependencies:
file-uri-to-path "1.0.0"

bl@^1.0.0:
version "1.2.3"
resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.3.tgz#1e8dd80142eac80d7158c9dccc047fb620e035e7"
Expand Down Expand Up @@ -3302,7 +3309,7 @@ electron-util@^0.12.1:
electron-is-dev "^1.1.0"
new-github-issue-url "^0.2.1"

electron-util@^0.13.0, electron-util@^0.13.1:
electron-util@^0.13.1:
version "0.13.1"
resolved "https://registry.yarnpkg.com/electron-util/-/electron-util-0.13.1.tgz#ba3b9cb7e5fdb6a51970a01e9070877cf7855ef8"
integrity sha512-CvOuAyQPaPtnDp7SspwnT1yTb1yynw6yp4LrZCfEJ7TG/kJFiZW9RqMHlCEFWMn3QNoMkNhGVeCvWJV5NsYyuQ==
Expand Down Expand Up @@ -4243,6 +4250,11 @@ file-type@^8.1.0:
resolved "https://registry.yarnpkg.com/file-type/-/file-type-8.1.0.tgz#244f3b7ef641bbe0cca196c7276e4b332399f68c"
integrity sha512-qyQ0pzAy78gVoJsmYeNgl8uH8yKhr1lVhW7JbzJmnlRi0I4R2eEDEJZVKG8agpDnLpacwNbDhLNG/LMdxHD2YQ==

file-uri-to-path@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==

file-url@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/file-url/-/file-url-3.0.0.tgz#247a586a746ce9f7a8ed05560290968afc262a77"
Expand Down Expand Up @@ -6203,15 +6215,6 @@ mac-open-with@^1.2.3:
execa "^2.0.4"
macos-version "^5.2.0"

mac-screen-capture-permissions@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/mac-screen-capture-permissions/-/mac-screen-capture-permissions-1.1.0.tgz#a60ac7f06240d5037b0e86d409723ec36d077c8c"
integrity sha512-jMRumlB3FScui/7yW+5FqqbuO7CQ0XOJVT5oTsb7W9eRQDhCIpJpIF0XxLVXwq2DIOp0fYsz1LFiBjnyDYULyQ==
dependencies:
electron-util "^0.13.0"
execa "^2.0.4"
macos-version "^5.2.0"

mac-windows@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/mac-windows/-/mac-windows-1.0.0.tgz#d5c40f548f94ea075005af7ca766811324638326"
Expand Down Expand Up @@ -6689,6 +6692,11 @@ node-addon-api@^1.6.3:
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-1.7.2.tgz#3df30b95720b53c24e59948b49532b662444f54d"
integrity sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==

node-addon-api@^3.0.2:
version "3.2.1"
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161"
integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==

node-fetch@2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
Expand Down Expand Up @@ -6738,6 +6746,14 @@ node-mac-app-icon@^1.4.0:
electron-util "^0.4.1"
execa "^0.8.0"

node-mac-permissions@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/node-mac-permissions/-/node-mac-permissions-2.2.1.tgz#69497a08a47ebed336d794a005eb3b8949793f87"
integrity sha512-lmSuexF/XcAvtanSReDDrr61Bz4FveSmVl1wHY0Be6RV0+QpCK1RMpjWxtKG0ALqX4p+k2cJ/u7GBV8dkUeLeA==
dependencies:
bindings "^1.5.0"
node-addon-api "^3.0.2"

node-releases@^1.1.71, node-releases@^1.1.73:
version "1.1.74"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.74.tgz#e5866488080ebaa70a93b91144ccde06f3c3463e"
Expand Down