Bump SDK to v1.0.107-alpha. Simplify syncService state handling

This commit is contained in:
Stefan Ceriu 2023-08-16 13:24:43 +03:00 committed by Stefan Ceriu
parent 8d409e7817
commit 5400910855
8 changed files with 30 additions and 52 deletions

View File

@ -5451,7 +5451,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift"; repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift";
requirement = { requirement = {
kind = exactVersion; kind = exactVersion;
version = "1.0.106-alpha"; version = "1.0.107-alpha";
}; };
}; };
821C67C9A7F8CC3FD41B28B4 /* XCRemoteSwiftPackageReference "emojibase-bindings" */ = { 821C67C9A7F8CC3FD41B28B4 /* XCRemoteSwiftPackageReference "emojibase-bindings" */ = {

View File

@ -129,8 +129,8 @@
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-rust-components-swift", "location" : "https://github.com/matrix-org/matrix-rust-components-swift",
"state" : { "state" : {
"revision" : "e9c185dc6a9d01c198fae36161b0e4180dfcfdd6", "revision" : "28211915a5a5ca926798d12bedc3bf1a352714fd",
"version" : "1.0.106-alpha" "version" : "1.0.107-alpha"
} }
}, },
{ {

View File

@ -538,7 +538,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
// MARK: - Application State // MARK: - Application State
private func stopSync() { private func stopSync() {
userSession?.clientProxy.pauseSync() userSession?.clientProxy.stopSync()
clientProxyObserver = nil clientProxyObserver = nil
} }
@ -595,7 +595,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
@objc @objc
private func applicationWillTerminate() { private func applicationWillTerminate() {
userSession?.clientProxy.pauseSync() userSession?.clientProxy.stopSync()
} }
@objc @objc
@ -609,7 +609,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
backgroundTask = backgroundTaskService.startBackgroundTask(withName: "SuspendApp: \(UUID().uuidString)") { [weak self] in backgroundTask = backgroundTaskService.startBackgroundTask(withName: "SuspendApp: \(UUID().uuidString)") { [weak self] in
guard let self else { return } guard let self else { return }
userSession?.clientProxy.pauseSync() userSession?.clientProxy.stopSync()
backgroundTask?.stop() backgroundTask?.stop()
backgroundTask = nil backgroundTask = nil
@ -629,7 +629,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
backgroundTask?.stop() backgroundTask?.stop()
backgroundTask = nil backgroundTask = nil
if isSuspended, userSession?.clientProxy.isSyncing == false { if isSuspended {
startSync() startSync()
} }
@ -681,9 +681,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
return return
} }
if !userSession.clientProxy.isSyncing { startSync()
startSync()
}
// Be a good citizen, run for a max of 10 SS responses or 10 seconds // 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 // An SS request will time out after 30 seconds if no new data is available

View File

@ -75,7 +75,7 @@ enum MXLog {
self.target = Constants.target 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() rootSpan.enter()
@ -181,7 +181,7 @@ enum MXLog {
rootSpan.enter() 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, private static func log(_ message: Any,
@ -199,6 +199,6 @@ enum MXLog {
rootSpan.enter() 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)")
} }
} }

View File

@ -53,7 +53,7 @@ class ClientProxy: ClientProxyProtocol {
deinit { deinit {
client.setDelegate(delegate: nil) client.setDelegate(delegate: nil)
pauseSync() stopSync()
} }
let callbacks = PassthroughSubject<ClientProxyCallback, Never>() let callbacks = PassthroughSubject<ClientProxyCallback, Never>()
@ -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() { func startSync() {
guard !isSyncing else { return }
MXLog.info("Starting sync") MXLog.info("Starting sync")
isStartingSync = true
Task { Task {
do { await syncService?.start()
try await syncService?.start()
} catch {
MXLog.error("Failed starting app service with error: \(error)")
}
isStartingSync = false
} }
} }
func pauseSync() { func stopSync() {
MXLog.info("Stopping sync") MXLog.info("Stopping sync")
do { Task {
try syncService?.pause() do {
} catch { try await syncService?.stop()
MXLog.error("Failed pausing app service with error: \(error)") } catch {
MXLog.error("Failed stopping the sync service with error: \(error)")
}
} }
} }
@ -367,19 +353,17 @@ class ClientProxy: ClientProxyProtocol {
// MARK: Private // MARK: Private
private func restartSync(delay: Duration = .zero) { private func restartSync(delay: Duration = .zero) {
isStartingSync = true
Task { Task {
try await Task.sleep(for: delay) try await Task.sleep(for: delay)
do { do {
MXLog.info("Restart the app service.") MXLog.info("Restarting the sync service.")
try await self.syncService?.start() try await self.syncService?.stop()
} catch { } 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 syncService.state(listener: SyncServiceStateObserverProxy { [weak self] state in
guard let self else { return } guard let self else { return }
MXLog.info("Received app service update: \(state)") MXLog.info("Received sync service update: \(state)")
switch state { switch state {
case .running, .terminated, .idle: case .running, .terminated, .idle:
@ -454,7 +438,7 @@ class ClientProxy: ClientProxyProtocol {
guard let self, guard let self,
state != .error, state != .error,
state != .terminated else { state != .terminated else {
// The app service is responsible of handling error and termination // The sync service is responsible of handling error and termination
return return
} }

View File

@ -79,12 +79,10 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
var roomSummaryProvider: RoomSummaryProviderProtocol? { get } var roomSummaryProvider: RoomSummaryProviderProtocol? { get }
var inviteSummaryProvider: RoomSummaryProviderProtocol? { get } var inviteSummaryProvider: RoomSummaryProviderProtocol? { get }
var isSyncing: Bool { get }
func startSync() func startSync()
func pauseSync() func stopSync()
func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError> func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError>

View File

@ -32,8 +32,6 @@ class MockClientProxy: ClientProxyProtocol {
var avatarURLPublisher: AnyPublisher<URL?, Never> { Empty().eraseToAnyPublisher() } var avatarURLPublisher: AnyPublisher<URL?, Never> { Empty().eraseToAnyPublisher() }
var isSyncing: Bool { false }
init(userID: String, deviceID: String? = nil, roomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()) { init(userID: String, deviceID: String? = nil, roomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()) {
self.userID = userID self.userID = userID
self.deviceID = deviceID self.deviceID = deviceID
@ -46,7 +44,7 @@ class MockClientProxy: ClientProxyProtocol {
func stopSync(completionHandler: () -> Void) { } func stopSync(completionHandler: () -> Void) { }
func pauseSync() { } func stopSync() { }
func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError> { func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError> {
.failure(.failedRetrievingDirectRoom) .failure(.failedRetrievingDirectRoom)

View File

@ -45,7 +45,7 @@ packages:
# Element/Matrix dependencies # Element/Matrix dependencies
MatrixRustSDK: MatrixRustSDK:
url: https://github.com/matrix-org/matrix-rust-components-swift url: https://github.com/matrix-org/matrix-rust-components-swift
exactVersion: 1.0.106-alpha exactVersion: 1.0.107-alpha
# path: ../matrix-rust-sdk # path: ../matrix-rust-sdk
DesignKit: DesignKit:
path: DesignKit path: DesignKit