From 5daa934f88e31dc40c4ef5aa5467d900d72031cd Mon Sep 17 00:00:00 2001 From: Lucas Barrena Date: Fri, 6 Mar 2020 13:00:09 -0300 Subject: [PATCH] Add preference to mute call ringtone (#1273) --- source/config.ts | 5 +++++ source/index.ts | 14 ++++++++++++++ source/menu.ts | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/source/config.ts b/source/config.ts index 2be59c9bb..d22640afd 100644 --- a/source/config.ts +++ b/source/config.ts @@ -33,6 +33,7 @@ type StoreType = { sidebar: 'default' | 'hidden' | 'narrow' | 'wide'; autoHideMenuBar: boolean; notificationsMuted: boolean; + callRingtoneMuted: boolean; hardwareAcceleration: boolean; quitOnWindowClose: boolean; keepMeSignedIn: boolean; @@ -166,6 +167,10 @@ const schema: {[Key in keyof StoreType]: Store.Schema} = { type: 'boolean', default: false }, + callRingtoneMuted: { + type: 'boolean', + default: false + }, hardwareAcceleration: { type: 'boolean', default: true diff --git a/source/index.ts b/source/index.ts index b82b2a6d7..7b1ee7040 100644 --- a/source/index.ts +++ b/source/index.ts @@ -232,6 +232,20 @@ function initRequestsFiltering(): void { callback({cancel: config.get('block.deliveryReceipt' as any)}); } }); + + session.defaultSession.webRequest.onHeadersReceived({ + urls: ['*://static.xx.fbcdn.net/rsrc.php/*'] + }, ({responseHeaders}, callback) => { + if (!config.get('callRingtoneMuted') || !responseHeaders) { + callback({}); + return; + } + + const callRingtoneHash = '2NAu/QVqg211BbktgY5GkA=='; + callback({ + cancel: responseHeaders['content-md5'][0] === callRingtoneHash + }); + }); } function setUserLocale(): void { diff --git a/source/menu.ts b/source/menu.ts index 70def8468..9e1a9bc34 100644 --- a/source/menu.ts +++ b/source/menu.ts @@ -247,6 +247,14 @@ Press Command/Ctrl+R in Caprine to see your changes. sendAction('toggle-mute-notifications'); } }, + { + label: 'Mute Call Ringtone', + type: 'checkbox', + checked: config.get('callRingtoneMuted'), + click() { + config.set('callRingtoneMuted', !config.get('callRingtoneMuted')); + } + }, { label: 'Show Unread Badge', type: 'checkbox',