diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index fa2a48643..4ff545696 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -5451,7 +5451,7 @@ repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift"; requirement = { kind = exactVersion; - version = "1.0.106-alpha"; + version = "1.0.107-alpha"; }; }; 821C67C9A7F8CC3FD41B28B4 /* XCRemoteSwiftPackageReference "emojibase-bindings" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index bcce8e7ad..a955f1508 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -129,8 +129,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/matrix-org/matrix-rust-components-swift", "state" : { - "revision" : "e9c185dc6a9d01c198fae36161b0e4180dfcfdd6", - "version" : "1.0.106-alpha" + "revision" : "28211915a5a5ca926798d12bedc3bf1a352714fd", + "version" : "1.0.107-alpha" } }, { diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 0194e1281..39dce87a8 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -538,7 +538,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate, // MARK: - Application State private func stopSync() { - userSession?.clientProxy.pauseSync() + userSession?.clientProxy.stopSync() clientProxyObserver = nil } @@ -595,7 +595,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate, @objc private func applicationWillTerminate() { - userSession?.clientProxy.pauseSync() + userSession?.clientProxy.stopSync() } @objc @@ -609,7 +609,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate, backgroundTask = backgroundTaskService.startBackgroundTask(withName: "SuspendApp: \(UUID().uuidString)") { [weak self] in guard let self else { return } - userSession?.clientProxy.pauseSync() + userSession?.clientProxy.stopSync() backgroundTask?.stop() backgroundTask = nil @@ -629,7 +629,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate, backgroundTask?.stop() backgroundTask = nil - if isSuspended, userSession?.clientProxy.isSyncing == false { + if isSuspended { startSync() } @@ -681,9 +681,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate, return } - if !userSession.clientProxy.isSyncing { - startSync() - } + startSync() // Be a good citizen, run for a max of 10 SS responses or 10 seconds // An SS request will time out after 30 seconds if no new data is available diff --git a/ElementX/Sources/Other/Logging/MXLog.swift b/ElementX/Sources/Other/Logging/MXLog.swift index 6abd0b4a5..f23039336 100644 --- a/ElementX/Sources/Other/Logging/MXLog.swift +++ b/ElementX/Sources/Other/Logging/MXLog.swift @@ -75,7 +75,7 @@ enum MXLog { self.target = Constants.target } - rootSpan = Span(file: #file, line: #line, column: #column, level: .info, target: self.target, name: "root") + rootSpan = Span(file: #file, line: #line, level: .info, target: self.target, name: "root") rootSpan.enter() @@ -181,7 +181,7 @@ enum MXLog { rootSpan.enter() } - return Span(file: file, line: UInt32(line), column: UInt32(column), level: level, target: target, name: name) + return Span(file: file, line: UInt32(line), level: level, target: target, name: name) } private static func log(_ message: Any, @@ -199,6 +199,6 @@ enum MXLog { rootSpan.enter() } - logEvent(file: (file as NSString).lastPathComponent, line: UInt32(line), column: UInt32(column), level: level, target: target, message: "\(message)") + logEvent(file: (file as NSString).lastPathComponent, line: UInt32(line), level: level, target: target, message: "\(message)") } } diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index 406f52592..40c03fe1e 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -53,7 +53,7 @@ class ClientProxy: ClientProxyProtocol { deinit { client.setDelegate(delegate: nil) - pauseSync() + stopSync() } let callbacks = PassthroughSubject() @@ -109,37 +109,23 @@ class ClientProxy: ClientProxyProtocol { } } - var isSyncing: Bool { - isStartingSync || syncService?.currentState() == .running - } - - /// Ensure we don't call start sync whilst awaiting a previous call. - private var isStartingSync = false - func startSync() { - guard !isSyncing else { return } - MXLog.info("Starting sync") - isStartingSync = true Task { - do { - try await syncService?.start() - } catch { - MXLog.error("Failed starting app service with error: \(error)") - } - - isStartingSync = false + await syncService?.start() } } - func pauseSync() { + func stopSync() { MXLog.info("Stopping sync") - - do { - try syncService?.pause() - } catch { - MXLog.error("Failed pausing app service with error: \(error)") + + Task { + do { + try await syncService?.stop() + } catch { + MXLog.error("Failed stopping the sync service with error: \(error)") + } } } @@ -367,19 +353,17 @@ class ClientProxy: ClientProxyProtocol { // MARK: Private private func restartSync(delay: Duration = .zero) { - isStartingSync = true - Task { try await Task.sleep(for: delay) do { - MXLog.info("Restart the app service.") - try await self.syncService?.start() + MXLog.info("Restarting the sync service.") + try await self.syncService?.stop() } catch { - MXLog.error("Failed restarting app service after error.") + MXLog.error("Failed restarting the sync service with error: \(error)") } - self.isStartingSync = false + await self.syncService?.start() } } @@ -437,7 +421,7 @@ class ClientProxy: ClientProxyProtocol { syncService.state(listener: SyncServiceStateObserverProxy { [weak self] state in guard let self else { return } - MXLog.info("Received app service update: \(state)") + MXLog.info("Received sync service update: \(state)") switch state { case .running, .terminated, .idle: @@ -454,7 +438,7 @@ class ClientProxy: ClientProxyProtocol { guard let self, state != .error, state != .terminated else { - // The app service is responsible of handling error and termination + // The sync service is responsible of handling error and termination return } diff --git a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift index 0cea3ba5c..0786f92df 100644 --- a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift +++ b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift @@ -79,12 +79,10 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol { var roomSummaryProvider: RoomSummaryProviderProtocol? { get } var inviteSummaryProvider: RoomSummaryProviderProtocol? { get } - - var isSyncing: Bool { get } func startSync() - func pauseSync() + func stopSync() func directRoomForUserID(_ userID: String) async -> Result diff --git a/ElementX/Sources/Services/Client/MockClientProxy.swift b/ElementX/Sources/Services/Client/MockClientProxy.swift index 67db53c5e..36eb461b6 100644 --- a/ElementX/Sources/Services/Client/MockClientProxy.swift +++ b/ElementX/Sources/Services/Client/MockClientProxy.swift @@ -32,8 +32,6 @@ class MockClientProxy: ClientProxyProtocol { var avatarURLPublisher: AnyPublisher { Empty().eraseToAnyPublisher() } - var isSyncing: Bool { false } - init(userID: String, deviceID: String? = nil, roomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()) { self.userID = userID self.deviceID = deviceID @@ -46,7 +44,7 @@ class MockClientProxy: ClientProxyProtocol { func stopSync(completionHandler: () -> Void) { } - func pauseSync() { } + func stopSync() { } func directRoomForUserID(_ userID: String) async -> Result { .failure(.failedRetrievingDirectRoom) diff --git a/project.yml b/project.yml index 9ec2acefe..cdcbf8d43 100644 --- a/project.yml +++ b/project.yml @@ -45,7 +45,7 @@ packages: # Element/Matrix dependencies MatrixRustSDK: url: https://github.com/matrix-org/matrix-rust-components-swift - exactVersion: 1.0.106-alpha + exactVersion: 1.0.107-alpha # path: ../matrix-rust-sdk DesignKit: path: DesignKit