@@ -23,8 +23,50 @@ import Olm from 'olm';
2323
2424import * as languageHandler from 'matrix-react-sdk/src/languageHandler' ;
2525import SettingsStore from "matrix-react-sdk/src/settings/SettingsStore" ;
26+ import ElectronPlatform from "./platform/ElectronPlatform" ;
27+ import WebPlatform from "./platform/WebPlatform" ;
28+ import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg' ;
29+ import SdkConfig from "matrix-react-sdk/src/SdkConfig" ;
2630
2731
32+ export function preparePlatform ( ) {
33+ if ( ( < any > window ) . ipcRenderer ) {
34+ console . log ( "Using Electron platform" ) ;
35+ const plaf = new ElectronPlatform ( ) ;
36+ PlatformPeg . set ( plaf ) ;
37+ } else {
38+ console . log ( "Using Web platform" ) ;
39+ PlatformPeg . set ( new WebPlatform ( ) ) ;
40+ }
41+ }
42+
43+ export async function loadConfig ( ) : Promise < { configError ?: Error , configSyntaxError : boolean } > {
44+ const platform = PlatformPeg . get ( ) ;
45+
46+ let configJson ;
47+ let configError ;
48+ let configSyntaxError = false ;
49+ try {
50+ configJson = await platform . getConfig ( ) ;
51+ } catch ( e ) {
52+ configError = e ;
53+
54+ if ( e && e . err && e . err instanceof SyntaxError ) {
55+ console . error ( "SyntaxError loading config:" , e ) ;
56+ configSyntaxError = true ;
57+ configJson = { } ; // to prevent errors between here and loading CSS for the error box
58+ }
59+ }
60+
61+ // XXX: We call this twice, once here and once in MatrixChat as a prop. We call it here to ensure
62+ // granular settings are loaded correctly and to avoid duplicating the override logic for the theme.
63+ //
64+ // Note: this isn't called twice for some wrappers, like the Jitsi wrapper.
65+ SdkConfig . put ( configJson ) ;
66+
67+ return { configError, configSyntaxError} ;
68+ }
69+
2870export function loadOlm ( ) : Promise < void > {
2971 /* Load Olm. We try the WebAssembly version first, and then the legacy,
3072 * asm.js version if that fails. For this reason we need to wait for this
0 commit comments