From 6767f71a6b458cdc91f3169765fc4b12bf6d911d Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 10 Mar 2020 10:49:07 +1100 Subject: [PATCH] Make getMediaPermissions synchronous --- main.js | 9 +++------ preload.js | 20 ++------------------ 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/main.js b/main.js index 75746d222..e0d0cb770 100644 --- a/main.js +++ b/main.js @@ -1073,13 +1073,10 @@ function removeDarkOverlay() { } } -// This one is different because its single source of truth is userConfig, not IndexedDB +// This should be called with an ipc sendSync ipc.on('get-media-permissions', event => { - event.sender.send( - 'get-success-media-permissions', - null, - userConfig.get('mediaPermissions') || false - ); + // eslint-disable-next-line no-param-reassign + event.returnValue = userConfig.get('mediaPermissions') || false; }); ipc.on('set-media-permissions', (event, value) => { userConfig.set('mediaPermissions', value); diff --git a/preload.js b/preload.js index c688b3696..b6a14af4b 100644 --- a/preload.js +++ b/preload.js @@ -212,13 +212,7 @@ window.getSettingValue = (settingID, comparisonValue = null) => { // returns 'false' when the value is 'dark'. if (settingID === 'media-permissions') { - let permissionValue; - // eslint-disable-next-line more/no-then - window.getMediaPermissions().then(value => { - permissionValue = value; - }); - - return permissionValue; + return window.getMediaPermissions(); } const settingVal = window.storage.get(settingID); @@ -236,17 +230,7 @@ window.setSettingValue = (settingID, value) => { // Get the message TTL setting window.getMessageTTL = () => window.storage.get('message-ttl', 24); -window.getMediaPermissions = () => - new Promise((resolve, reject) => { - ipc.once('get-success-media-permissions', (_event, error, value) => { - if (error) { - return reject(error); - } - - return resolve(value); - }); - ipc.send('get-media-permissions'); - }); +window.getMediaPermissions = () => ipc.sendSync('get-media-permissions') window.addSetupMenuItems = () => ipc.send('add-setup-menu-items'); window.removeSetupMenuItems = () => ipc.send('remove-setup-menu-items');