Skip to content

Commit 3d75c9d

Browse files
committed
#1095 Show fallback prompt if already asked for screen cap permissions
1 parent 4601c0f commit 3d75c9d

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

main/common/system-permissions.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import {join} from 'path';
2+
import {existsSync, openSync} from 'fs';
13
import {systemPreferences, shell, dialog, app} from 'electron';
24
import {getAuthStatus, askForScreenCaptureAccess} from 'node-mac-permissions';
35
const {ensureDockIsShowing} = require('../utils/dock');
46

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

710
const promptSystemPreferences = (options: {message: string; detail: string; systemPreferencesPath: string}) => async ({hasAsked}: {hasAsked?: boolean} = {}) => {
@@ -73,13 +76,18 @@ const screenCaptureFallback = promptSystemPreferences({
7376
});
7477

7578
export const ensureScreenCapturePermissions = (fallback = screenCaptureFallback) => {
79+
// Check for screen capture permissions
7680
const status = getAuthStatus('screen');
7781
if (status === 'authorized') {
7882
return true;
7983
}
8084

85+
// If not authorized for screen capture, ask for permissions
8186
askForScreenCaptureAccess();
82-
fallback();
87+
openSync(hasAskedForScreenCapturePermissionsPath, 'w');
88+
89+
// If we've already asked, then prompt user again to give permission
90+
fallback({hasAsked: !existsSync(hasAskedForScreenCapturePermissionsPath)});
8391
return false;
8492
};
8593

yarn.lock

+26-10
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,13 @@ binary-extensions@^2.0.0:
16801680
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
16811681
integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==
16821682

1683+
bindings@^1.5.0:
1684+
version "1.5.0"
1685+
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
1686+
integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==
1687+
dependencies:
1688+
file-uri-to-path "1.0.0"
1689+
16831690
bl@^1.0.0:
16841691
version "1.2.3"
16851692
resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.3.tgz#1e8dd80142eac80d7158c9dccc047fb620e035e7"
@@ -3302,7 +3309,7 @@ electron-util@^0.12.1:
33023309
electron-is-dev "^1.1.0"
33033310
new-github-issue-url "^0.2.1"
33043311

3305-
electron-util@^0.13.0, electron-util@^0.13.1:
3312+
electron-util@^0.13.1:
33063313
version "0.13.1"
33073314
resolved "https://registry.yarnpkg.com/electron-util/-/electron-util-0.13.1.tgz#ba3b9cb7e5fdb6a51970a01e9070877cf7855ef8"
33083315
integrity sha512-CvOuAyQPaPtnDp7SspwnT1yTb1yynw6yp4LrZCfEJ7TG/kJFiZW9RqMHlCEFWMn3QNoMkNhGVeCvWJV5NsYyuQ==
@@ -4243,6 +4250,11 @@ file-type@^8.1.0:
42434250
resolved "https://registry.yarnpkg.com/file-type/-/file-type-8.1.0.tgz#244f3b7ef641bbe0cca196c7276e4b332399f68c"
42444251
integrity sha512-qyQ0pzAy78gVoJsmYeNgl8uH8yKhr1lVhW7JbzJmnlRi0I4R2eEDEJZVKG8agpDnLpacwNbDhLNG/LMdxHD2YQ==
42454252

4253+
file-uri-to-path@1.0.0:
4254+
version "1.0.0"
4255+
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
4256+
integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==
4257+
42464258
file-url@^3.0.0:
42474259
version "3.0.0"
42484260
resolved "https://registry.yarnpkg.com/file-url/-/file-url-3.0.0.tgz#247a586a746ce9f7a8ed05560290968afc262a77"
@@ -6203,15 +6215,6 @@ mac-open-with@^1.2.3:
62036215
execa "^2.0.4"
62046216
macos-version "^5.2.0"
62056217

6206-
mac-screen-capture-permissions@^1.1.0:
6207-
version "1.1.0"
6208-
resolved "https://registry.yarnpkg.com/mac-screen-capture-permissions/-/mac-screen-capture-permissions-1.1.0.tgz#a60ac7f06240d5037b0e86d409723ec36d077c8c"
6209-
integrity sha512-jMRumlB3FScui/7yW+5FqqbuO7CQ0XOJVT5oTsb7W9eRQDhCIpJpIF0XxLVXwq2DIOp0fYsz1LFiBjnyDYULyQ==
6210-
dependencies:
6211-
electron-util "^0.13.0"
6212-
execa "^2.0.4"
6213-
macos-version "^5.2.0"
6214-
62156218
mac-windows@^1.0.0:
62166219
version "1.0.0"
62176220
resolved "https://registry.yarnpkg.com/mac-windows/-/mac-windows-1.0.0.tgz#d5c40f548f94ea075005af7ca766811324638326"
@@ -6689,6 +6692,11 @@ node-addon-api@^1.6.3:
66896692
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-1.7.2.tgz#3df30b95720b53c24e59948b49532b662444f54d"
66906693
integrity sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==
66916694

6695+
node-addon-api@^3.0.2:
6696+
version "3.2.1"
6697+
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161"
6698+
integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==
6699+
66926700
node-fetch@2.6.1:
66936701
version "2.6.1"
66946702
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
@@ -6738,6 +6746,14 @@ node-mac-app-icon@^1.4.0:
67386746
electron-util "^0.4.1"
67396747
execa "^0.8.0"
67406748

6749+
node-mac-permissions@^2.2.1:
6750+
version "2.2.1"
6751+
resolved "https://registry.yarnpkg.com/node-mac-permissions/-/node-mac-permissions-2.2.1.tgz#69497a08a47ebed336d794a005eb3b8949793f87"
6752+
integrity sha512-lmSuexF/XcAvtanSReDDrr61Bz4FveSmVl1wHY0Be6RV0+QpCK1RMpjWxtKG0ALqX4p+k2cJ/u7GBV8dkUeLeA==
6753+
dependencies:
6754+
bindings "^1.5.0"
6755+
node-addon-api "^3.0.2"
6756+
67416757
node-releases@^1.1.71, node-releases@^1.1.73:
67426758
version "1.1.74"
67436759
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.74.tgz#e5866488080ebaa70a93b91144ccde06f3c3463e"

0 commit comments

Comments
 (0)