From 50dc5341642dd2fb803ac586be4a74a765fd40a9 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Fri, 5 Nov 2021 01:47:32 -0700 Subject: [PATCH] Simplify permissions popup IPC --- app/main.ts | 18 ++++-------------- preload.js | 5 ++--- ts/services/audioRecorder.ts | 2 +- ts/services/calling.ts | 4 ++-- ts/util/callingPermissions.ts | 2 +- ts/util/requestMicrophonePermissions.ts | 6 ++++-- ts/window.d.ts | 6 ++++-- 7 files changed, 18 insertions(+), 25 deletions(-) diff --git a/app/main.ts b/app/main.ts index 3c76bb76c..a28a1f585 100644 --- a/app/main.ts +++ b/app/main.ts @@ -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 ); } diff --git a/preload.js b/preload.js index 635296370..1c6583b99 100644 --- a/preload.js +++ b/preload.js @@ -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(); diff --git a/ts/services/audioRecorder.ts b/ts/services/audioRecorder.ts index 3a8c70dc5..010784f9e 100644 --- a/ts/services/audioRecorder.ts +++ b/ts/services/audioRecorder.ts @@ -44,7 +44,7 @@ export class RecorderClass { } async start(): Promise { - const hasMicrophonePermission = await requestMicrophonePermissions(); + const hasMicrophonePermission = await requestMicrophonePermissions(false); if (!hasMicrophonePermission) { log.info( 'Recorder/start: Microphone permission was denied, new audio recording not allowed.' diff --git a/ts/services/calling.ts b/ts/services/calling.ts index 6048900fc..e9689d8f3 100644 --- a/ts/services/calling.ts +++ b/ts/services/calling.ts @@ -1502,7 +1502,7 @@ export class CallingClass { private async requestCameraPermissions(): Promise { 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 { - const microphonePermission = await requestMicrophonePermissions(); + const microphonePermission = await requestMicrophonePermissions(true); if (microphonePermission) { if (isVideoCall) { return this.requestCameraPermissions(); diff --git a/ts/util/callingPermissions.ts b/ts/util/callingPermissions.ts index d14042426..196922538 100644 --- a/ts/util/callingPermissions.ts +++ b/ts/util/callingPermissions.ts @@ -3,7 +3,7 @@ export async function requestCameraPermissions(): Promise { 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(); diff --git a/ts/util/requestMicrophonePermissions.ts b/ts/util/requestMicrophonePermissions.ts index ce74bee60..581627e06 100644 --- a/ts/util/requestMicrophonePermissions.ts +++ b/ts/util/requestMicrophonePermissions.ts @@ -1,10 +1,12 @@ // Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -export async function requestMicrophonePermissions(): Promise { +export async function requestMicrophonePermissions( + forCalling: boolean +): Promise { 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(); diff --git a/ts/window.d.ts b/ts/window.d.ts index a4555209f..df1ee200f 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -160,7 +160,10 @@ declare global { QRCode: any; removeSetupMenuItems: () => unknown; - showPermissionsPopup: () => Promise; + showPermissionsPopup: ( + forCalling: boolean, + forCamera: boolean + ) => Promise; FontFace: typeof FontFace; _: typeof Underscore; @@ -211,7 +214,6 @@ declare global { getTitle: () => string; waitForEmptyEventQueue: () => Promise; getVersion: () => string; - showCallingPermissionsPopup: (forCamera: boolean) => Promise; i18n: LocalizerType; isActive: () => boolean; isAfterVersion: (version: string, anotherVersion: string) => boolean;