@@ -43,7 +43,6 @@ import { MatrixClientPeg } from "../../MatrixClientPeg";
4343import { OwnProfileStore } from "../OwnProfileStore" ;
4444import WidgetUtils from "../../utils/WidgetUtils" ;
4545import { IntegrationManagers } from "../../integrations/IntegrationManagers" ;
46- import SettingsStore from "../../settings/SettingsStore" ;
4746import { WidgetType } from "../../widgets/WidgetType" ;
4847import ActiveWidgetStore from "../ActiveWidgetStore" ;
4948import { objectShallowClone } from "../../utils/objects" ;
@@ -52,7 +51,7 @@ import { Action } from "../../dispatcher/actions";
5251import { ElementWidgetActions , IHangupCallApiRequest , IViewRoomApiRequest } from "./ElementWidgetActions" ;
5352import { ModalWidgetStore } from "../ModalWidgetStore" ;
5453import { IApp , isAppWidget } from "../WidgetStore" ;
55- import ThemeWatcher from "../../settings/watchers/ThemeWatcher" ;
54+ import ThemeWatcher , { ThemeWatcherEvent } from "../../settings/watchers/ThemeWatcher" ;
5655import { getCustomTheme } from "../../theme" ;
5756import { ElementWidgetCapabilities } from "./ElementWidgetCapabilities" ;
5857import { ELEMENT_CLIENT_ID } from "../../identifiers" ;
@@ -163,6 +162,7 @@ export class StopGapWidget extends EventEmitter {
163162 private viewedRoomId : string | null = null ;
164163 private kind : WidgetKind ;
165164 private readonly virtual : boolean ;
165+ private readonly themeWatcher = new ThemeWatcher ( ) ;
166166 private readUpToMap : { [ roomId : string ] : string } = { } ; // room ID to event ID
167167 // This promise will be called and needs to resolve before the widget will actually become sticky.
168168 private stickyPromise ?: ( ) => Promise < void > ;
@@ -213,7 +213,7 @@ export class StopGapWidget extends EventEmitter {
213213 userDisplayName : OwnProfileStore . instance . displayName ?? undefined ,
214214 userHttpAvatarUrl : OwnProfileStore . instance . getHttpAvatarUrl ( ) ?? undefined ,
215215 clientId : ELEMENT_CLIENT_ID ,
216- clientTheme : SettingsStore . getValue ( "theme" ) ,
216+ clientTheme : this . themeWatcher . getEffectiveTheme ( ) ,
217217 clientLanguage : getUserLanguage ( ) ,
218218 deviceId : this . client . getDeviceId ( ) ?? undefined ,
219219 baseUrl : this . client . baseUrl ,
@@ -245,6 +245,10 @@ export class StopGapWidget extends EventEmitter {
245245 return ! ! this . messaging ;
246246 }
247247
248+ private onThemeChange = ( theme : string ) : void => {
249+ this . messaging ?. updateTheme ( { name : theme } ) ;
250+ } ;
251+
248252 private onOpenModal = async ( ev : CustomEvent < IModalWidgetOpenRequest > ) : Promise < void > => {
249253 ev . preventDefault ( ) ;
250254 if ( ModalWidgetStore . instance . canOpenModalWidget ( ) ) {
@@ -288,9 +292,14 @@ export class StopGapWidget extends EventEmitter {
288292 this . messaging = new ClientWidgetApi ( this . mockWidget , iframe , driver ) ;
289293 this . messaging . on ( "preparing" , ( ) => this . emit ( "preparing" ) ) ;
290294 this . messaging . on ( "error:preparing" , ( err : unknown ) => this . emit ( "error:preparing" , err ) ) ;
291- this . messaging . on ( "ready" , ( ) => {
295+ this . messaging . once ( "ready" , ( ) => {
292296 WidgetMessagingStore . instance . storeMessaging ( this . mockWidget , this . roomId , this . messaging ! ) ;
293297 this . emit ( "ready" ) ;
298+
299+ this . themeWatcher . start ( ) ;
300+ this . themeWatcher . on ( ThemeWatcherEvent . Change , this . onThemeChange ) ;
301+ // Theme may have changed while messaging was starting
302+ this . onThemeChange ( this . themeWatcher . getEffectiveTheme ( ) ) ;
294303 } ) ;
295304 this . messaging . on ( "capabilitiesNotified" , ( ) => this . emit ( "capabilitiesNotified" ) ) ;
296305 this . messaging . on ( `action:${ WidgetApiFromWidgetAction . OpenModalWidget } ` , this . onOpenModal ) ;
0 commit comments