diff --git a/app/components/ToggleThemeBtnGroup/index.tsx b/app/components/ToggleThemeBtnGroup/index.tsx index 553c895..2d6f9ae 100644 --- a/app/components/ToggleThemeBtnGroup/index.tsx +++ b/app/components/ToggleThemeBtnGroup/index.tsx @@ -1,12 +1,8 @@ -import { remote } from 'electron'; import React, { useContext, useCallback } from 'react'; import { Button, Classes, ControlGroup } from '@blueprintjs/core'; -import SharingSessionService from '../../features/SharingSessionService'; +import { ipcRenderer } from 'electron'; import { SettingsContext } from '../../containers/SettingsProvider'; - -const sharingSessionService = remote.getGlobal( - 'sharingSessionService' -) as SharingSessionService; +import { IpcEvents } from '../../main/IpcEvents.enum'; export default function ToggleThemeBtnGroup() { const { isDarkTheme, setIsDarkThemeHook } = useContext(SettingsContext); @@ -16,9 +12,7 @@ export default function ToggleThemeBtnGroup() { document.body.classList.toggle(Classes.DARK); setIsDarkThemeHook(true); } - sharingSessionService.sharingSessions.forEach((sharingSession) => { - sharingSession?.appThemeChanged(); - }); + ipcRenderer.invoke(IpcEvents.NotifyAllSessionsWithAppThemeChanged); }, [isDarkTheme, setIsDarkThemeHook]); const handleToggleLightTheme = useCallback(() => { @@ -26,9 +20,7 @@ export default function ToggleThemeBtnGroup() { document.body.classList.toggle(Classes.DARK); setIsDarkThemeHook(false); } - sharingSessionService.sharingSessions.forEach((sharingSession) => { - sharingSession?.appThemeChanged(); - }); + ipcRenderer.invoke(IpcEvents.NotifyAllSessionsWithAppThemeChanged); }, [isDarkTheme, setIsDarkThemeHook]); return ( diff --git a/app/main/IpcEvents.enum.ts b/app/main/IpcEvents.enum.ts index 1bdf022..b5d14bd 100644 --- a/app/main/IpcEvents.enum.ts +++ b/app/main/IpcEvents.enum.ts @@ -20,4 +20,5 @@ export enum IpcEvents { GetWaitingForConnectionSharingSessionRoomId = 'get-waiting-for-connection-sharing-session-room-id', GetDesktopSharingSourceIds = 'get-desktop-sharing-source-ids', SetDesktopCapturerSourceId = 'set-desktop-capturer-source-id', + NotifyAllSessionsWithAppThemeChanged = 'notify-all-sessions-with-app-theme-changed', } diff --git a/app/main/ipcMainHandlers.ts b/app/main/ipcMainHandlers.ts index ce319dc..031e7bc 100644 --- a/app/main/ipcMainHandlers.ts +++ b/app/main/ipcMainHandlers.ts @@ -266,4 +266,12 @@ export default function initIpcMainHandlers( id ); }); + + ipcMain.handle(IpcEvents.NotifyAllSessionsWithAppThemeChanged, () => { + getDeskreenGlobal().sharingSessionService.sharingSessions.forEach( + (sharingSession) => { + sharingSession?.appThemeChanged(); + } + ); + }); }