Skip to content

Commit

Permalink
#1095 Show fallback prompt if already asked for screen cap permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
thethomasz committed Aug 28, 2022
1 parent 4601c0f commit 3d75c9d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
10 changes: 9 additions & 1 deletion 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';
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,13 +76,18 @@ const screenCaptureFallback = promptSystemPreferences({
});

export const ensureScreenCapturePermissions = (fallback = screenCaptureFallback) => {
// Check for screen capture permissions
const status = getAuthStatus('screen');
if (status === 'authorized') {
return true;
}

// If not authorized for screen capture, ask for permissions
askForScreenCaptureAccess();
fallback();
openSync(hasAskedForScreenCapturePermissionsPath, 'w');

// If we've already asked, then prompt user again to give permission
fallback({hasAsked: !existsSync(hasAskedForScreenCapturePermissionsPath)});
return false;
};

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==

[email protected]:
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==

[email protected]:
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

0 comments on commit 3d75c9d

Please sign in to comment.