signal-desktop/ts/windows/permissions/preload.ts

63 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-06-23 19:15:27 +00:00
// Copyright 2021-2022 Signal Messenger, LLC
2021-09-17 22:24:21 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import ReactDOM from 'react-dom';
import { contextBridge } from 'electron';
2021-09-17 22:24:21 +00:00
import { SignalContext } from '../context';
2021-09-17 22:24:21 +00:00
import { createSetting } from '../../util/preload';
import { PermissionsPopup } from '../../components/PermissionsPopup';
const mediaCameraPermissions = createSetting('mediaCameraPermissions', {
getter: false,
});
const mediaPermissions = createSetting('mediaPermissions', {
getter: false,
});
contextBridge.exposeInMainWorld(
'nativeThemeListener',
window.SignalContext.nativeThemeListener
);
contextBridge.exposeInMainWorld('SignalContext', {
...SignalContext,
2021-09-17 22:24:21 +00:00
renderWindow: () => {
const { forCalling, forCamera } = SignalContext.config;
2021-09-17 22:24:21 +00:00
let message;
if (forCalling) {
if (forCamera) {
message = SignalContext.i18n('videoCallingPermissionNeeded');
2021-09-17 22:24:21 +00:00
} else {
message = SignalContext.i18n('audioCallingPermissionNeeded');
2021-09-17 22:24:21 +00:00
}
} else {
message = SignalContext.i18n('audioPermissionNeeded');
2021-09-17 22:24:21 +00:00
}
function onClose() {
void SignalContext.executeMenuRole('close');
2021-09-17 22:24:21 +00:00
}
ReactDOM.render(
React.createElement(PermissionsPopup, {
i18n: SignalContext.i18n,
2021-09-17 22:24:21 +00:00
message,
onAccept: () => {
if (!forCamera) {
void mediaPermissions.setValue(true);
2021-09-17 22:24:21 +00:00
} else {
void mediaCameraPermissions.setValue(true);
2021-09-17 22:24:21 +00:00
}
onClose();
},
onClose,
}),
document.getElementById('app')
);
},
});