Add a ClientBuilder hook. (#3056)

This commit is contained in:
Doug
2024-07-18 09:47:37 +01:00
committed by GitHub
parent 65dd6f3496
commit 288d2c2fdc
10 changed files with 61 additions and 18 deletions
@@ -50,6 +50,8 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
private var handler: ((UNNotificationContent) -> Void)?
private var modifiedContent: UNMutableNotificationContent?
private let appHooks = AppHooks()
// Used to create one single UserSession across process/instances/runs
private static let serialQueue = DispatchQueue(label: "io.element.elementx.nse")
private static var userSession: NSEUserSession?
@@ -82,9 +84,9 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
if Self.userSession == nil {
// This function might be run concurrently and from different processes
// It's imperative that we create **at most** one UserSession/Client per process
Task.synchronous {
Task.synchronous { [appHooks] in
do {
Self.userSession = try await NSEUserSession(credentials: credentials, clientSessionDelegate: keychainController)
Self.userSession = try await NSEUserSession(credentials: credentials, clientSessionDelegate: keychainController, appHooks: appHooks)
} catch {
MXLog.error("Failed creating user session with error: \(error)")
}
+3 -2
View File
@@ -25,7 +25,7 @@ final class NSEUserSession {
imageCache: .onlyOnDisk)
private let delegateHandle: TaskHandle?
init(credentials: KeychainCredentials, clientSessionDelegate: ClientSessionDelegate) async throws {
init(credentials: KeychainCredentials, clientSessionDelegate: ClientSessionDelegate, appHooks: AppHooks) async throws {
userID = credentials.userID
if credentials.restorationToken.passphrase != nil {
MXLog.info("Restoring client with encrypted store.")
@@ -35,7 +35,8 @@ final class NSEUserSession {
let clientBuilder = ClientBuilder
.baseBuilder(setupEncryption: false,
httpProxy: URL(string: homeserverURL)?.globalProxy,
sessionDelegate: clientSessionDelegate)
sessionDelegate: clientSessionDelegate,
appHooks: appHooks)
.sessionPath(path: credentials.restorationToken.sessionDirectory.path(percentEncoded: false))
.username(username: credentials.userID)
.homeserverUrl(url: homeserverURL)