@@ -17,7 +17,6 @@ import {
17
17
type OidcRegistrationClientMetadata ,
18
18
} from "matrix-js-sdk/src/matrix" ;
19
19
import React from "react" ;
20
- import { secureRandomString } from "matrix-js-sdk/src/randomstring" ;
21
20
import { logger } from "matrix-js-sdk/src/logger" ;
22
21
23
22
import BasePlatform , { UpdateCheckStatus , type UpdateStatus } from "../../BasePlatform" ;
@@ -97,8 +96,10 @@ function getUpdateCheckStatus(status: boolean | string): UpdateStatus {
97
96
export default class ElectronPlatform extends BasePlatform {
98
97
private readonly ipc = new IPCManager ( "ipcCall" , "ipcReply" ) ;
99
98
private readonly eventIndexManager : BaseEventIndexManager = new SeshatIndexManager ( ) ;
100
- // this is the opaque token we pass to the HS which when we get it in our callback we can resolve to a profile
101
- private readonly ssoID : string = secureRandomString ( 32 ) ;
99
+ private readonly initialised : Promise < void > ;
100
+ private protocol ! : string ;
101
+ private sessionId ! : string ;
102
+ private config ! : IConfigOptions ;
102
103
103
104
public constructor ( ) {
104
105
super ( ) ;
@@ -186,13 +187,21 @@ export default class ElectronPlatform extends BasePlatform {
186
187
await this . ipc . call ( "callDisplayMediaCallback" , source ?? { id : "" , name : "" , thumbnailURL : "" } ) ;
187
188
} ) ;
188
189
189
- void this . ipc . call ( "startSSOFlow" , this . ssoID ) ;
190
-
191
190
BreadcrumbsStore . instance . on ( UPDATE_EVENT , this . onBreadcrumbsUpdate ) ;
191
+
192
+ this . initialised = this . initialise ( ) ;
193
+ }
194
+
195
+ private async initialise ( ) : Promise < void > {
196
+ const { protocol, sessionId, config } = await window . electron ! . initialise ( ) ;
197
+ this . protocol = protocol ;
198
+ this . sessionId = sessionId ;
199
+ this . config = config ;
192
200
}
193
201
194
202
public async getConfig ( ) : Promise < IConfigOptions | undefined > {
195
- return this . ipc . call ( "getConfig" ) ;
203
+ await this . initialised ;
204
+ return this . config ;
196
205
}
197
206
198
207
private onBreadcrumbsUpdate = ( ) : void => {
@@ -391,7 +400,7 @@ export default class ElectronPlatform extends BasePlatform {
391
400
public getSSOCallbackUrl ( fragmentAfterLogin ?: string ) : URL {
392
401
const url = super . getSSOCallbackUrl ( fragmentAfterLogin ) ;
393
402
url . protocol = "element" ;
394
- url . searchParams . set ( SSO_ID_KEY , this . ssoID ) ;
403
+ url . searchParams . set ( SSO_ID_KEY , this . sessionId ) ;
395
404
return url ;
396
405
}
397
406
@@ -469,15 +478,15 @@ export default class ElectronPlatform extends BasePlatform {
469
478
}
470
479
471
480
public getOidcClientState ( ) : string {
472
- return `:${ SSO_ID_KEY } :${ this . ssoID } ` ;
481
+ return `:${ SSO_ID_KEY } :${ this . sessionId } ` ;
473
482
}
474
483
475
484
/**
476
485
* The URL to return to after a successful OIDC authentication
477
486
*/
478
487
public getOidcCallbackUrl ( ) : URL {
479
488
const url = super . getOidcCallbackUrl ( ) ;
480
- url . protocol = "io.element.desktop" ;
489
+ url . protocol = this . protocol ;
481
490
// Trim the double slash into a single slash to comply with https://datatracker.ietf.org/doc/html/rfc8252#section-7.1
482
491
if ( url . href . startsWith ( `${ url . protocol } //` ) ) {
483
492
url . href = url . href . replace ( "://" , ":/" ) ;
0 commit comments