diff --git a/main.js b/main.js index b42610368..92efede4a 100644 --- a/main.js +++ b/main.js @@ -403,7 +403,10 @@ async function createWindow() { ), nativeWindowOpen: true, spellcheck: await getSpellCheckSetting(), - backgroundThrottling: false, + // We are evaluating background throttling in prerelease versions. If we decide to + // move forward, we can remove this line (as `backgroundThrottling` is true by + // default). + backgroundThrottling: !isProduction(app.getVersion()), enablePreferredSizeMode: true, }, icon: windowIcon, @@ -664,6 +667,29 @@ ipc.on('title-bar-double-click', () => { } }); +ipc.on('set-is-call-active', (_event, isCallActive) => { + if (!mainWindow) { + return; + } + + // We are evaluating background throttling in prerelease versions. If we decide to move + // forward, we can remove this check. + if (isProduction(app.getVersion())) { + return; + } + + let backgroundThrottling; + if (isCallActive) { + console.log('Background throttling disabled because a call is active'); + backgroundThrottling = false; + } else { + console.log('Background throttling enabled because no call is active'); + backgroundThrottling = true; + } + + mainWindow.webContents.setBackgroundThrottling(backgroundThrottling); +}); + ipc.on('convert-image', async (event, uuid, data) => { const { error, response } = await heicConverter(uuid, data); event.reply(`convert-image:${uuid}`, { error, response }); diff --git a/ts/components/CallManager.stories.tsx b/ts/components/CallManager.stories.tsx index af988bf2e..3706a6ac5 100644 --- a/ts/components/CallManager.stories.tsx +++ b/ts/components/CallManager.stories.tsx @@ -87,6 +87,7 @@ const createProps = (storyProps: Partial = {}): PropsType => ({ renderDeviceSelection: () =>
, renderSafetyNumberViewer: (_: SafetyNumberViewerProps) =>
, setGroupCallVideoRequest: action('set-group-call-video-request'), + setIsCallActive: action('set-is-call-active'), setLocalAudio: action('set-local-audio'), setLocalPreview: action('set-local-preview'), setLocalVideo: action('set-local-video'), diff --git a/ts/components/CallManager.tsx b/ts/components/CallManager.tsx index 02450defb..ec70bc7ca 100644 --- a/ts/components/CallManager.tsx +++ b/ts/components/CallManager.tsx @@ -86,6 +86,7 @@ export type PropsType = { openSystemPreferencesAction: () => unknown; playRingtone: () => unknown; setGroupCallVideoRequest: (_: SetGroupCallVideoRequestType) => void; + setIsCallActive: (_: boolean) => void; setLocalAudio: (_: SetLocalAudioType) => void; setLocalVideo: (_: SetLocalVideoType) => void; setLocalPreview: (_: SetLocalPreviewType) => void; @@ -366,9 +367,15 @@ export const CallManager: React.FC = props => { notifyForCall, playRingtone, stopRingtone, + setIsCallActive, setOutgoingRing, } = props; + const isCallActive = Boolean(activeCall); + useEffect(() => { + setIsCallActive(isCallActive); + }, [isCallActive, setIsCallActive]); + const shouldRing = getShouldRing(props); useEffect(() => { if (shouldRing) { diff --git a/ts/context/createNativeThemeListener.ts b/ts/context/createNativeThemeListener.ts index 75da5e835..558a77ae9 100644 --- a/ts/context/createNativeThemeListener.ts +++ b/ts/context/createNativeThemeListener.ts @@ -7,6 +7,9 @@ import { NativeThemeState } from '../types/NativeThemeNotifier.d'; export type Callback = (change: NativeThemeState) => void; export interface MinimalIPC { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + send(channel: string, ...args: ReadonlyArray): void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any sendSync(channel: string): any; diff --git a/ts/context/index.ts b/ts/context/index.ts index 9be7acf20..4738c8931 100644 --- a/ts/context/index.ts +++ b/ts/context/index.ts @@ -15,7 +15,11 @@ export class Context { public readonly nativeThemeListener; - constructor(ipc: MinimalIPC) { + constructor(private readonly ipc: MinimalIPC) { this.nativeThemeListener = createNativeThemeListener(ipc, window); } + + setIsCallActive(isCallActive: boolean): void { + this.ipc.send('set-is-call-active', isCallActive); + } } diff --git a/ts/state/ducks/calling.ts b/ts/state/ducks/calling.ts index 4df2a8f93..6f2974b0b 100644 --- a/ts/state/ducks/calling.ts +++ b/ts/state/ducks/calling.ts @@ -960,6 +960,14 @@ function returnToActiveCall(): ReturnToActiveCallActionType { }; } +function setIsCallActive( + isCallActive: boolean +): ThunkAction { + return () => { + window.SignalContext.setIsCallActive(isCallActive); + }; +} + function setLocalPreview( payload: SetLocalPreviewType ): ThunkAction { @@ -1203,6 +1211,7 @@ export const actions = { remoteVideoChange, returnToActiveCall, setGroupCallVideoRequest, + setIsCallActive, setLocalAudio, setLocalPreview, setLocalVideo, diff --git a/ts/test-electron/context/createNativeThemeListener_test.ts b/ts/test-electron/context/createNativeThemeListener_test.ts index a34d129d3..d5df773ad 100644 --- a/ts/test-electron/context/createNativeThemeListener_test.ts +++ b/ts/test-electron/context/createNativeThemeListener_test.ts @@ -20,6 +20,13 @@ class FakeIPC extends EventEmitter implements MinimalIPC { assert.strictEqual(channel, 'native-theme:init'); return this.state; } + + // eslint-disable-next-line class-methods-use-this + public send() { + throw new Error( + 'This should not be called. It is only here to satisfy the interface' + ); + } } describe('NativeThemeListener', () => {