Skip to content

Commit

Permalink
Merge pull request #515 from vcync/next
Browse files Browse the repository at this point in the history
fix(macos): adds entitlements and function call to request macos medi…
  • Loading branch information
TimPietrusky authored Dec 17, 2020
2 parents caec808 + ab565d9 commit a1090e0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
4 changes: 4 additions & 0 deletions build/entitlements.mac.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>
</dict>
</plist>
55 changes: 52 additions & 3 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
screen,
shell,
BrowserWindow,
Menu
Menu,
systemPreferences
} from "electron";

import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
Expand All @@ -18,6 +19,52 @@ import store from "./media-manager/store";

const isDevelopment = process.env.NODE_ENV !== "production";

async function checkMediaPermission() {
const { platform } = process;

let macOSMediaDialogsAccepted = false;
let hasMediaPermission = false;

const microphoneAccessStatus = systemPreferences.getMediaAccessStatus(
"microphone"
);
const cameraAccessStatus = systemPreferences.getMediaAccessStatus("camera");

hasMediaPermission =
microphoneAccessStatus === "granted" && cameraAccessStatus === "granted";

if (platform === "darwin" && !hasMediaPermission) {
macOSMediaDialogsAccepted = await getMediaPermission();
} else if (platform === "darwin" && hasMediaPermission) {
macOSMediaDialogsAccepted = true;
}

if (
(platform === "win32" && !hasMediaPermission) ||
(platform === "darwin" && !macOSMediaDialogsAccepted)
) {
dialog.showMessageBox({
type: "warning",
message: "modV does not have access to camera or microphone",
detail:
"While modV can still be used without these permissions, some functionality will be limited or broken. Please close modV, update your Security permissions and start modV again."
});
}
}

// Asks macOS permission to access media devices
async function getMediaPermission() {
let accessGrantedMicrophone = false;
let accessGrantedCamera = false;

accessGrantedMicrophone = await systemPreferences.askForMediaAccess(
"microphone"
);
accessGrantedCamera = await systemPreferences.askForMediaAccess("camera");

return accessGrantedMicrophone && accessGrantedCamera;
}

// Keep a global reference of the window objects, if you don't, the windows will
// be closed automatically when the JavaScript objects are garbage collected.
const windows = {};
Expand Down Expand Up @@ -70,7 +117,7 @@ const windowPrefs = {
};
},

create(window) {
async create(window) {
// Configure child windows to open without a menubar (windows/linux)
window.webContents.on(
"new-window",
Expand Down Expand Up @@ -163,6 +210,8 @@ const windowPrefs = {

// Check for updates
autoUpdater.checkForUpdatesAndNotify();

await checkMediaPermission();
},

destroy() {
Expand Down Expand Up @@ -472,7 +521,7 @@ app.on("window-all-closed", () => {
}
});

app.on("activate", () => {
app.on("activate", async () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
createWindow("mainWindow");
Expand Down
8 changes: 7 additions & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ module.exports = {
hardenedRuntime: true,
gatekeeperAssess: false,
entitlements: "build/entitlements.mac.plist",
entitlementsInherit: "build/entitlements.mac.plist"
entitlementsInherit: "build/entitlements.mac.plist",
extendInfo: {
NSCameraUsageDescription:
"This app requires camera access to record video.",
NSMicrophoneUsageDescription:
"This app requires microphone access to record audio."
}
},

dmg: {
Expand Down

0 comments on commit a1090e0

Please sign in to comment.