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

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2021 Signal Messenger, LLC
2021-09-17 22:24:21 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import { contextBridge } from 'electron';
import { MinimalSignalContext } from '../minimalContext';
2021-09-17 22:24:21 +00:00
import { createSetting } from '../../util/preload';
import { drop } from '../../util/drop';
2021-09-17 22:24:21 +00:00
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));
2021-09-17 22:24:21 +00:00
} else {
drop(mediaCameraPermissions.setValue(true));
2021-09-17 22:24:21 +00:00
}
onClose();
},
onClose,
2021-09-17 22:24:21 +00:00
},
};
contextBridge.exposeInMainWorld('Signal', Signal);
contextBridge.exposeInMainWorld('SignalContext', MinimalSignalContext);