@@ -37,7 +37,6 @@ import { MatrixClientPeg } from "../../MatrixClientPeg";
3737import { OwnProfileStore } from "../OwnProfileStore" ;
3838import WidgetUtils from "../../utils/WidgetUtils" ;
3939import { IntegrationManagers } from "../../integrations/IntegrationManagers" ;
40- import SettingsStore from "../../settings/SettingsStore" ;
4140import { WidgetType } from "../../widgets/WidgetType" ;
4241import ActiveWidgetStore from "../ActiveWidgetStore" ;
4342import { objectShallowClone } from "../../utils/objects" ;
@@ -46,7 +45,7 @@ import { Action } from "../../dispatcher/actions";
4645import { ElementWidgetActions , IHangupCallApiRequest , IViewRoomApiRequest } from "./ElementWidgetActions" ;
4746import { ModalWidgetStore } from "../ModalWidgetStore" ;
4847import { IApp , isAppWidget } from "../WidgetStore" ;
49- import ThemeWatcher from "../../settings/watchers/ThemeWatcher" ;
48+ import ThemeWatcher , { ThemeWatcherEvent } from "../../settings/watchers/ThemeWatcher" ;
5049import { getCustomTheme } from "../../theme" ;
5150import { ElementWidgetCapabilities } from "./ElementWidgetCapabilities" ;
5251import { ELEMENT_CLIENT_ID } from "../../identifiers" ;
@@ -153,6 +152,7 @@ export class StopGapWidget extends EventEmitter {
153152 private roomId ?: string ;
154153 private kind : WidgetKind ;
155154 private readonly virtual : boolean ;
155+ private readonly themeWatcher = new ThemeWatcher ( ) ;
156156 private readUpToMap : { [ roomId : string ] : string } = { } ; // room ID to event ID
157157 // This promise will be called and needs to resolve before the widget will actually become sticky.
158158 private stickyPromise ?: ( ) => Promise < void > ;
@@ -214,7 +214,7 @@ export class StopGapWidget extends EventEmitter {
214214 userDisplayName : OwnProfileStore . instance . displayName ?? undefined ,
215215 userHttpAvatarUrl : OwnProfileStore . instance . getHttpAvatarUrl ( ) ?? undefined ,
216216 clientId : ELEMENT_CLIENT_ID ,
217- clientTheme : SettingsStore . getValue ( "theme" ) ,
217+ clientTheme : this . themeWatcher . getEffectiveTheme ( ) ,
218218 clientLanguage : getUserLanguage ( ) ,
219219 deviceId : this . client . getDeviceId ( ) ?? undefined ,
220220 baseUrl : this . client . baseUrl ,
@@ -246,6 +246,10 @@ export class StopGapWidget extends EventEmitter {
246246 return ! ! this . messaging ;
247247 }
248248
249+ private onThemeChange = ( theme : string ) : void => {
250+ this . messaging ?. updateTheme ( { name : theme } ) ;
251+ } ;
252+
249253 private onOpenModal = async ( ev : CustomEvent < IModalWidgetOpenRequest > ) : Promise < void > => {
250254 ev . preventDefault ( ) ;
251255 if ( ModalWidgetStore . instance . canOpenModalWidget ( ) ) {
@@ -281,6 +285,11 @@ export class StopGapWidget extends EventEmitter {
281285 this . messaging . on ( "ready" , ( ) => {
282286 WidgetMessagingStore . instance . storeMessaging ( this . mockWidget , this . roomId , this . messaging ! ) ;
283287 this . emit ( "ready" ) ;
288+
289+ this . themeWatcher . start ( ) ;
290+ this . themeWatcher . on ( ThemeWatcherEvent . Change , this . onThemeChange ) ;
291+ // Theme may have changed while messaging was starting
292+ this . onThemeChange ( this . themeWatcher . getEffectiveTheme ( ) ) ;
284293 } ) ;
285294 this . messaging . on ( "capabilitiesNotified" , ( ) => this . emit ( "capabilitiesNotified" ) ) ;
286295 this . messaging . on ( `action:${ WidgetApiFromWidgetAction . OpenModalWidget } ` , this . onOpenModal ) ;
0 commit comments