diff --git a/ElementX/Sources/AppHooks/Hooks/CompoundHook.swift b/ElementX/Sources/AppHooks/Hooks/CompoundHook.swift index f867be3bb..75d99bde1 100644 --- a/ElementX/Sources/AppHooks/Hooks/CompoundHook.swift +++ b/ElementX/Sources/AppHooks/Hooks/CompoundHook.swift @@ -9,7 +9,7 @@ import Compound protocol CompoundHookProtocol { - func override(colors: CompoundColors, uiColors: CompoundUIColors) + @MainActor func override(colors: CompoundColors, uiColors: CompoundUIColors) } struct DefaultCompoundHook: CompoundHookProtocol { diff --git a/ElementX/Sources/AppHooks/Hooks/RemoteSettingsHook.swift b/ElementX/Sources/AppHooks/Hooks/RemoteSettingsHook.swift index 7b0bab2e4..e5fdcd159 100644 --- a/ElementX/Sources/AppHooks/Hooks/RemoteSettingsHook.swift +++ b/ElementX/Sources/AppHooks/Hooks/RemoteSettingsHook.swift @@ -15,11 +15,11 @@ enum RemoteSettingsError: Error { protocol RemoteSettingsHookProtocol { #if IS_MAIN_APP - func initializeCache(using client: ClientProtocol, applyingTo appSettings: CommonSettingsProtocol) async -> Result + @MainActor func initializeCache(using client: ClientProtocol, applyingTo appSettings: CommonSettingsProtocol) async -> Result func updateCache(using client: ClientProtocol) async - func reset(_ appSettings: CommonSettingsProtocol) + @MainActor func reset(_ appSettings: CommonSettingsProtocol) #endif - func loadCache(forHomeserver homeserver: String, applyingTo appSettings: CommonSettingsProtocol) + @MainActor func loadCache(forHomeserver homeserver: String, applyingTo appSettings: CommonSettingsProtocol) } struct DefaultRemoteSettingsHook: RemoteSettingsHookProtocol { diff --git a/ElementX/Sources/Services/UserSession/UserSessionStore.swift b/ElementX/Sources/Services/UserSession/UserSessionStore.swift index 1e1590715..0b968df29 100644 --- a/ElementX/Sources/Services/UserSession/UserSessionStore.swift +++ b/ElementX/Sources/Services/UserSession/UserSessionStore.swift @@ -113,7 +113,7 @@ class UserSessionStore: UserSessionStoreProtocol { } let homeserverURL = credentials.restorationToken.session.homeserverUrl - appHooks.remoteSettingsHook.loadCache(forHomeserver: homeserverURL, applyingTo: appSettings) + await appHooks.remoteSettingsHook.loadCache(forHomeserver: homeserverURL, applyingTo: appSettings) let builder = ClientBuilder .baseBuilder(httpProxy: URL(string: homeserverURL)?.globalProxy, diff --git a/NSE/Sources/NotificationServiceExtension.swift b/NSE/Sources/NotificationServiceExtension.swift index 9aadde26c..a8a7795e8 100644 --- a/NSE/Sources/NotificationServiceExtension.swift +++ b/NSE/Sources/NotificationServiceExtension.swift @@ -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)") } } diff --git a/compound-ios/Package.resolved b/compound-ios/Package.resolved index 5398907f9..3502c9309 100644 --- a/compound-ios/Package.resolved +++ b/compound-ios/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/element-hq/compound-design-tokens", "state" : { - "revision" : "be5d26dfd4ad659b0d3b3aec1ad1cccd0dc8d063", - "version" : "6.0.0" + "revision" : "93b48b3c88473562fb42c34100e45df25a4aea97", + "version" : "6.3.0" } }, { diff --git a/compound-ios/Sources/Compound/Colors/CompoundColors.swift b/compound-ios/Sources/Compound/Colors/CompoundColors.swift index f44a8a9b2..d2fcc4183 100644 --- a/compound-ios/Sources/Compound/Colors/CompoundColors.swift +++ b/compound-ios/Sources/Compound/Colors/CompoundColors.swift @@ -40,7 +40,7 @@ public class CompoundColors { /// Customise the colour at the specified key path with the supplied colour. /// Supplying `nil` as the colour will remove any existing customisation. - public func override(_ keyPath: KeyPath, with color: Color?) { + @MainActor public func override(_ keyPath: KeyPath, with color: Color?) { overrides[keyPath] = color } diff --git a/compound-ios/Sources/Compound/Colors/CompoundUIColors.swift b/compound-ios/Sources/Compound/Colors/CompoundUIColors.swift index 5d8564db1..5d293f0b0 100644 --- a/compound-ios/Sources/Compound/Colors/CompoundUIColors.swift +++ b/compound-ios/Sources/Compound/Colors/CompoundUIColors.swift @@ -35,7 +35,7 @@ public class CompoundUIColors { /// Customise the colour at the specified key path with the supplied colour. /// Supplying `nil` as the colour will remove any existing customisation. - public func override(_ keyPath: KeyPath, with color: UIColor?) { + @MainActor public func override(_ keyPath: KeyPath, with color: UIColor?) { overrides[keyPath] = color } diff --git a/compound-ios/Tests/CompoundTests/OverrideColorTests.swift b/compound-ios/Tests/CompoundTests/OverrideColorTests.swift index fe82ef02c..52b41c031 100644 --- a/compound-ios/Tests/CompoundTests/OverrideColorTests.swift +++ b/compound-ios/Tests/CompoundTests/OverrideColorTests.swift @@ -11,6 +11,7 @@ import Foundation @testable import Compound import XCTest +@MainActor class OverrideColorTests: XCTestCase { func testSwiftUI() { let colors = CompoundColors()