Simplify permissions popup IPC

This commit is contained in:
David Sanders 2021-11-05 01:47:32 -07:00
parent c822c45310
commit 50dc534164
7 changed files with 18 additions and 25 deletions

View File

@ -1871,24 +1871,14 @@ ipc.on(
// Permissions Popup-related IPC calls
ipc.handle('show-permissions-popup', async () => {
try {
await showPermissionsPopupWindow(false, false);
} catch (error) {
getLogger().error(
'show-permissions-popup error:',
error && error.stack ? error.stack : error
);
}
});
ipc.handle(
'show-calling-permissions-popup',
async (_event: Electron.Event, forCamera: boolean) => {
'show-permissions-popup',
async (_event: Electron.Event, forCalling: boolean, forCamera: boolean) => {
try {
await showPermissionsPopupWindow(true, forCamera);
await showPermissionsPopupWindow(forCalling, forCamera);
} catch (error) {
getLogger().error(
'show-calling-permissions-popup error:',
'show-permissions-popup error:',
error && error.stack ? error.stack : error
);
}

View File

@ -238,9 +238,8 @@ try {
// Settings-related events
window.showSettings = () => ipc.send('show-settings');
window.showPermissionsPopup = () => ipc.invoke('show-permissions-popup');
window.showCallingPermissionsPopup = forCamera =>
ipc.invoke('show-calling-permissions-popup', forCamera);
window.showPermissionsPopup = (forCalling, forCamera) =>
ipc.invoke('show-permissions-popup', forCalling, forCamera);
ipc.on('show-keyboard-shortcuts', () => {
window.Events.showKeyboardShortcuts();

View File

@ -44,7 +44,7 @@ export class RecorderClass {
}
async start(): Promise<boolean> {
const hasMicrophonePermission = await requestMicrophonePermissions();
const hasMicrophonePermission = await requestMicrophonePermissions(false);
if (!hasMicrophonePermission) {
log.info(
'Recorder/start: Microphone permission was denied, new audio recording not allowed.'

View File

@ -1502,7 +1502,7 @@ export class CallingClass {
private async requestCameraPermissions(): Promise<boolean> {
const cameraPermission = await window.getMediaCameraPermissions();
if (!cameraPermission) {
await window.showCallingPermissionsPopup(true);
await window.showPermissionsPopup(true, true);
// Check the setting again (from the source of truth).
return window.getMediaCameraPermissions();
@ -1512,7 +1512,7 @@ export class CallingClass {
}
private async requestPermissions(isVideoCall: boolean): Promise<boolean> {
const microphonePermission = await requestMicrophonePermissions();
const microphonePermission = await requestMicrophonePermissions(true);
if (microphonePermission) {
if (isVideoCall) {
return this.requestCameraPermissions();

View File

@ -3,7 +3,7 @@
export async function requestCameraPermissions(): Promise<boolean> {
if (!(await window.getMediaCameraPermissions())) {
await window.showCallingPermissionsPopup(true);
await window.showPermissionsPopup(true, true);
// Check the setting again (from the source of truth).
return window.getMediaCameraPermissions();

View File

@ -1,10 +1,12 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export async function requestMicrophonePermissions(): Promise<boolean> {
export async function requestMicrophonePermissions(
forCalling: boolean
): Promise<boolean> {
const microphonePermission = await window.getMediaPermissions();
if (!microphonePermission) {
await window.showCallingPermissionsPopup(false);
await window.showPermissionsPopup(forCalling, false);
// Check the setting again (from the source of truth).
return window.getMediaPermissions();

6
ts/window.d.ts vendored
View File

@ -160,7 +160,10 @@ declare global {
QRCode: any;
removeSetupMenuItems: () => unknown;
showPermissionsPopup: () => Promise<void>;
showPermissionsPopup: (
forCalling: boolean,
forCamera: boolean
) => Promise<void>;
FontFace: typeof FontFace;
_: typeof Underscore;
@ -211,7 +214,6 @@ declare global {
getTitle: () => string;
waitForEmptyEventQueue: () => Promise<void>;
getVersion: () => string;
showCallingPermissionsPopup: (forCamera: boolean) => Promise<void>;
i18n: LocalizerType;
isActive: () => boolean;
isAfterVersion: (version: string, anotherVersion: string) => boolean;