signal-desktop/ts/windows/permissions/preload.ts
2023-04-20 17:23:19 -04:00

40 lines
1.1 KiB
TypeScript

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { contextBridge } from 'electron';
import { MinimalSignalContext } from '../minimalContext';
import { createSetting } from '../../util/preload';
import { drop } from '../../util/drop';
const mediaCameraPermissions = createSetting('mediaCameraPermissions', {
getter: false,
});
const mediaPermissions = createSetting('mediaPermissions', {
getter: false,
});
const params = new URLSearchParams(document.location.search);
const forCalling = params.get('forCalling') === 'true';
const forCamera = params.get('forCamera') === 'true';
function onClose() {
drop(MinimalSignalContext.executeMenuRole('close'));
}
const Signal = {
PermissionsWindowProps: {
forCalling,
forCamera,
onAccept: () => {
if (!forCamera) {
drop(mediaPermissions.setValue(true));
} else {
drop(mediaCameraPermissions.setValue(true));
}
onClose();
},
onClose,
},
};
contextBridge.exposeInMainWorld('Signal', Signal);
contextBridge.exposeInMainWorld('SignalContext', MinimalSignalContext);