Add @MainActor to some of the hook points.

This commit is contained in:
Doug
2025-11-14 14:05:38 +00:00
committed by Stefan Ceriu
parent 449349ce36
commit 022bc76c52
8 changed files with 35 additions and 33 deletions
+25 -24
View File
@@ -62,8 +62,11 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
super.init()
}
override func didReceive(_ request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
Task { await handle(request, withContentHandler: contentHandler) }
}
private func handle(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) async {
guard !DataProtectionManager.isDeviceLockedAfterReboot(containerURL: URL.appGroupContainerDirectory),
let roomID = request.content.roomID,
let eventID = request.content.eventID,
@@ -78,7 +81,7 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
}
let homeserverURL = credentials.restorationToken.session.homeserverUrl
appHooks.remoteSettingsHook.loadCache(forHomeserver: homeserverURL, applyingTo: settings)
await appHooks.remoteSettingsHook.loadCache(forHomeserver: homeserverURL, applyingTo: settings)
guard let mutableContent = request.content.mutableCopy() as? UNMutableNotificationContent else {
return contentHandler(request.content)
@@ -90,27 +93,25 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
MXLog.info("\(tag) Received payload: \(request.content.userInfo)")
Task {
do {
let userSession = try await NSEUserSession(credentials: credentials,
roomID: roomID,
clientSessionDelegate: keychainController,
appHooks: appHooks,
appSettings: settings)
notificationHandler = NotificationHandler(userSession: userSession,
settings: settings,
contentHandler: contentHandler,
notificationContent: mutableContent,
tag: tag)
ExtensionLogger.logMemory(with: tag)
MXLog.info("\(tag) Configured user session")
await notificationHandler?.processEvent(eventID, roomID: roomID)
} catch {
MXLog.error("Failed creating user session with error: \(error)")
}
do {
let userSession = try await NSEUserSession(credentials: credentials,
roomID: roomID,
clientSessionDelegate: keychainController,
appHooks: appHooks,
appSettings: settings)
notificationHandler = NotificationHandler(userSession: userSession,
settings: settings,
contentHandler: contentHandler,
notificationContent: mutableContent,
tag: tag)
ExtensionLogger.logMemory(with: tag)
MXLog.info("\(tag) Configured user session")
await notificationHandler?.processEvent(eventID, roomID: roomID)
} catch {
MXLog.error("Failed creating user session with error: \(error)")
}
}