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
@@ -9,7 +9,7 @@
import Compound import Compound
protocol CompoundHookProtocol { protocol CompoundHookProtocol {
func override(colors: CompoundColors, uiColors: CompoundUIColors) @MainActor func override(colors: CompoundColors, uiColors: CompoundUIColors)
} }
struct DefaultCompoundHook: CompoundHookProtocol { struct DefaultCompoundHook: CompoundHookProtocol {
@@ -15,11 +15,11 @@ enum RemoteSettingsError: Error {
protocol RemoteSettingsHookProtocol { protocol RemoteSettingsHookProtocol {
#if IS_MAIN_APP #if IS_MAIN_APP
func initializeCache(using client: ClientProtocol, applyingTo appSettings: CommonSettingsProtocol) async -> Result<Void, RemoteSettingsError> @MainActor func initializeCache(using client: ClientProtocol, applyingTo appSettings: CommonSettingsProtocol) async -> Result<Void, RemoteSettingsError>
func updateCache(using client: ClientProtocol) async func updateCache(using client: ClientProtocol) async
func reset(_ appSettings: CommonSettingsProtocol) @MainActor func reset(_ appSettings: CommonSettingsProtocol)
#endif #endif
func loadCache(forHomeserver homeserver: String, applyingTo appSettings: CommonSettingsProtocol) @MainActor func loadCache(forHomeserver homeserver: String, applyingTo appSettings: CommonSettingsProtocol)
} }
struct DefaultRemoteSettingsHook: RemoteSettingsHookProtocol { struct DefaultRemoteSettingsHook: RemoteSettingsHookProtocol {
@@ -113,7 +113,7 @@ class UserSessionStore: UserSessionStoreProtocol {
} }
let homeserverURL = credentials.restorationToken.session.homeserverUrl let homeserverURL = credentials.restorationToken.session.homeserverUrl
appHooks.remoteSettingsHook.loadCache(forHomeserver: homeserverURL, applyingTo: appSettings) await appHooks.remoteSettingsHook.loadCache(forHomeserver: homeserverURL, applyingTo: appSettings)
let builder = ClientBuilder let builder = ClientBuilder
.baseBuilder(httpProxy: URL(string: homeserverURL)?.globalProxy, .baseBuilder(httpProxy: URL(string: homeserverURL)?.globalProxy,
+25 -24
View File
@@ -62,8 +62,11 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
super.init() super.init()
} }
override func didReceive(_ request: UNNotificationRequest, override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
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), guard !DataProtectionManager.isDeviceLockedAfterReboot(containerURL: URL.appGroupContainerDirectory),
let roomID = request.content.roomID, let roomID = request.content.roomID,
let eventID = request.content.eventID, let eventID = request.content.eventID,
@@ -78,7 +81,7 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
} }
let homeserverURL = credentials.restorationToken.session.homeserverUrl 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 { guard let mutableContent = request.content.mutableCopy() as? UNMutableNotificationContent else {
return contentHandler(request.content) return contentHandler(request.content)
@@ -90,27 +93,25 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
MXLog.info("\(tag) Received payload: \(request.content.userInfo)") MXLog.info("\(tag) Received payload: \(request.content.userInfo)")
Task { do {
do { let userSession = try await NSEUserSession(credentials: credentials,
let userSession = try await NSEUserSession(credentials: credentials, roomID: roomID,
roomID: roomID, clientSessionDelegate: keychainController,
clientSessionDelegate: keychainController, appHooks: appHooks,
appHooks: appHooks, appSettings: settings)
appSettings: settings)
notificationHandler = NotificationHandler(userSession: userSession,
notificationHandler = NotificationHandler(userSession: userSession, settings: settings,
settings: settings, contentHandler: contentHandler,
contentHandler: contentHandler, notificationContent: mutableContent,
notificationContent: mutableContent, tag: tag)
tag: tag)
ExtensionLogger.logMemory(with: tag)
ExtensionLogger.logMemory(with: tag) MXLog.info("\(tag) Configured user session")
MXLog.info("\(tag) Configured user session")
await notificationHandler?.processEvent(eventID, roomID: roomID)
await notificationHandler?.processEvent(eventID, roomID: roomID) } catch {
} catch { MXLog.error("Failed creating user session with error: \(error)")
MXLog.error("Failed creating user session with error: \(error)")
}
} }
} }
+2 -2
View File
@@ -5,8 +5,8 @@
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
"location" : "https://github.com/element-hq/compound-design-tokens", "location" : "https://github.com/element-hq/compound-design-tokens",
"state" : { "state" : {
"revision" : "be5d26dfd4ad659b0d3b3aec1ad1cccd0dc8d063", "revision" : "93b48b3c88473562fb42c34100e45df25a4aea97",
"version" : "6.0.0" "version" : "6.3.0"
} }
}, },
{ {
@@ -40,7 +40,7 @@ public class CompoundColors {
/// Customise the colour at the specified key path with the supplied colour. /// Customise the colour at the specified key path with the supplied colour.
/// Supplying `nil` as the colour will remove any existing customisation. /// Supplying `nil` as the colour will remove any existing customisation.
public func override(_ keyPath: KeyPath<CompoundColorTokens, Color>, with color: Color?) { @MainActor public func override(_ keyPath: KeyPath<CompoundColorTokens, Color>, with color: Color?) {
overrides[keyPath] = color overrides[keyPath] = color
} }
@@ -35,7 +35,7 @@ public class CompoundUIColors {
/// Customise the colour at the specified key path with the supplied colour. /// Customise the colour at the specified key path with the supplied colour.
/// Supplying `nil` as the colour will remove any existing customisation. /// Supplying `nil` as the colour will remove any existing customisation.
public func override(_ keyPath: KeyPath<CompoundUIColorTokens, UIColor>, with color: UIColor?) { @MainActor public func override(_ keyPath: KeyPath<CompoundUIColorTokens, UIColor>, with color: UIColor?) {
overrides[keyPath] = color overrides[keyPath] = color
} }
@@ -11,6 +11,7 @@ import Foundation
@testable import Compound @testable import Compound
import XCTest import XCTest
@MainActor
class OverrideColorTests: XCTestCase { class OverrideColorTests: XCTestCase {
func testSwiftUI() { func testSwiftUI() {
let colors = CompoundColors() let colors = CompoundColors()