Simplify permissions popup IPC
This commit is contained in:
parent
c822c45310
commit
50dc534164
18
app/main.ts
18
app/main.ts
|
@ -1871,24 +1871,14 @@ ipc.on(
|
||||||
|
|
||||||
// Permissions Popup-related IPC calls
|
// 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(
|
ipc.handle(
|
||||||
'show-calling-permissions-popup',
|
'show-permissions-popup',
|
||||||
async (_event: Electron.Event, forCamera: boolean) => {
|
async (_event: Electron.Event, forCalling: boolean, forCamera: boolean) => {
|
||||||
try {
|
try {
|
||||||
await showPermissionsPopupWindow(true, forCamera);
|
await showPermissionsPopupWindow(forCalling, forCamera);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
getLogger().error(
|
getLogger().error(
|
||||||
'show-calling-permissions-popup error:',
|
'show-permissions-popup error:',
|
||||||
error && error.stack ? error.stack : error
|
error && error.stack ? error.stack : error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,9 +238,8 @@ try {
|
||||||
// Settings-related events
|
// Settings-related events
|
||||||
|
|
||||||
window.showSettings = () => ipc.send('show-settings');
|
window.showSettings = () => ipc.send('show-settings');
|
||||||
window.showPermissionsPopup = () => ipc.invoke('show-permissions-popup');
|
window.showPermissionsPopup = (forCalling, forCamera) =>
|
||||||
window.showCallingPermissionsPopup = forCamera =>
|
ipc.invoke('show-permissions-popup', forCalling, forCamera);
|
||||||
ipc.invoke('show-calling-permissions-popup', forCamera);
|
|
||||||
|
|
||||||
ipc.on('show-keyboard-shortcuts', () => {
|
ipc.on('show-keyboard-shortcuts', () => {
|
||||||
window.Events.showKeyboardShortcuts();
|
window.Events.showKeyboardShortcuts();
|
||||||
|
|
|
@ -44,7 +44,7 @@ export class RecorderClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
async start(): Promise<boolean> {
|
async start(): Promise<boolean> {
|
||||||
const hasMicrophonePermission = await requestMicrophonePermissions();
|
const hasMicrophonePermission = await requestMicrophonePermissions(false);
|
||||||
if (!hasMicrophonePermission) {
|
if (!hasMicrophonePermission) {
|
||||||
log.info(
|
log.info(
|
||||||
'Recorder/start: Microphone permission was denied, new audio recording not allowed.'
|
'Recorder/start: Microphone permission was denied, new audio recording not allowed.'
|
||||||
|
|
|
@ -1502,7 +1502,7 @@ export class CallingClass {
|
||||||
private async requestCameraPermissions(): Promise<boolean> {
|
private async requestCameraPermissions(): Promise<boolean> {
|
||||||
const cameraPermission = await window.getMediaCameraPermissions();
|
const cameraPermission = await window.getMediaCameraPermissions();
|
||||||
if (!cameraPermission) {
|
if (!cameraPermission) {
|
||||||
await window.showCallingPermissionsPopup(true);
|
await window.showPermissionsPopup(true, true);
|
||||||
|
|
||||||
// Check the setting again (from the source of truth).
|
// Check the setting again (from the source of truth).
|
||||||
return window.getMediaCameraPermissions();
|
return window.getMediaCameraPermissions();
|
||||||
|
@ -1512,7 +1512,7 @@ export class CallingClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async requestPermissions(isVideoCall: boolean): Promise<boolean> {
|
private async requestPermissions(isVideoCall: boolean): Promise<boolean> {
|
||||||
const microphonePermission = await requestMicrophonePermissions();
|
const microphonePermission = await requestMicrophonePermissions(true);
|
||||||
if (microphonePermission) {
|
if (microphonePermission) {
|
||||||
if (isVideoCall) {
|
if (isVideoCall) {
|
||||||
return this.requestCameraPermissions();
|
return this.requestCameraPermissions();
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
export async function requestCameraPermissions(): Promise<boolean> {
|
export async function requestCameraPermissions(): Promise<boolean> {
|
||||||
if (!(await window.getMediaCameraPermissions())) {
|
if (!(await window.getMediaCameraPermissions())) {
|
||||||
await window.showCallingPermissionsPopup(true);
|
await window.showPermissionsPopup(true, true);
|
||||||
|
|
||||||
// Check the setting again (from the source of truth).
|
// Check the setting again (from the source of truth).
|
||||||
return window.getMediaCameraPermissions();
|
return window.getMediaCameraPermissions();
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
// Copyright 2021 Signal Messenger, LLC
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// 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();
|
const microphonePermission = await window.getMediaPermissions();
|
||||||
if (!microphonePermission) {
|
if (!microphonePermission) {
|
||||||
await window.showCallingPermissionsPopup(false);
|
await window.showPermissionsPopup(forCalling, false);
|
||||||
|
|
||||||
// Check the setting again (from the source of truth).
|
// Check the setting again (from the source of truth).
|
||||||
return window.getMediaPermissions();
|
return window.getMediaPermissions();
|
||||||
|
|
|
@ -160,7 +160,10 @@ declare global {
|
||||||
|
|
||||||
QRCode: any;
|
QRCode: any;
|
||||||
removeSetupMenuItems: () => unknown;
|
removeSetupMenuItems: () => unknown;
|
||||||
showPermissionsPopup: () => Promise<void>;
|
showPermissionsPopup: (
|
||||||
|
forCalling: boolean,
|
||||||
|
forCamera: boolean
|
||||||
|
) => Promise<void>;
|
||||||
|
|
||||||
FontFace: typeof FontFace;
|
FontFace: typeof FontFace;
|
||||||
_: typeof Underscore;
|
_: typeof Underscore;
|
||||||
|
@ -211,7 +214,6 @@ declare global {
|
||||||
getTitle: () => string;
|
getTitle: () => string;
|
||||||
waitForEmptyEventQueue: () => Promise<void>;
|
waitForEmptyEventQueue: () => Promise<void>;
|
||||||
getVersion: () => string;
|
getVersion: () => string;
|
||||||
showCallingPermissionsPopup: (forCamera: boolean) => Promise<void>;
|
|
||||||
i18n: LocalizerType;
|
i18n: LocalizerType;
|
||||||
isActive: () => boolean;
|
isActive: () => boolean;
|
||||||
isAfterVersion: (version: string, anotherVersion: string) => boolean;
|
isAfterVersion: (version: string, anotherVersion: string) => boolean;
|
||||||
|
|
Loading…
Reference in New Issue