Update SDK (#1323)

Handle async start.
This commit is contained in:
Doug 2023-07-13 17:10:09 +01:00 committed by GitHub
parent dff18d7851
commit 4a03c4f715
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 20 deletions

View File

@ -5283,7 +5283,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift";
requirement = {
kind = exactVersion;
version = "1.0.98-alpha";
version = "1.0.99-alpha";
};
};
96495DD8554E2F39D3954354 /* XCRemoteSwiftPackageReference "posthog-ios" */ = {

View File

@ -111,8 +111,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-rust-components-swift",
"state" : {
"revision" : "985708733af7d2db1684f90f0a954854ca3a83ad",
"version" : "1.0.98-alpha"
"revision" : "3e2beb52294aa5dd87203cdcb3ac685f1a022c6b",
"version" : "1.0.99-alpha"
}
},
{

View File

@ -110,19 +110,26 @@ class ClientProxy: ClientProxyProtocol {
}
var isSyncing: Bool {
roomListService?.isSyncing() ?? false
isStartingSync || roomListService?.isSyncing() ?? false
}
func startSync() {
MXLog.info("Starting sync")
guard !isSyncing else {
return
}
/// Ensure we don't call start sync whilst awaiting a previous call.
private var isStartingSync = false
do {
try appService?.start()
} catch {
MXLog.error("Failed starting app service with error: \(error)")
func startSync() {
guard !isSyncing else { return }
MXLog.info("Starting sync")
isStartingSync = true
Task {
do {
try await appService?.start()
} catch {
MXLog.error("Failed starting app service with error: \(error)")
}
isStartingSync = false
}
}
@ -352,9 +359,21 @@ class ClientProxy: ClientProxyProtocol {
// MARK: Private
private func restartSync() {
pauseSync()
startSync()
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.appService?.start()
} catch {
MXLog.error("Failed restarting app service after error.")
}
self.isStartingSync = false
}
}
private func loadUserAvatarURLFromCache() {
@ -378,7 +397,7 @@ class ClientProxy: ClientProxyProtocol {
}
do {
let appService = try client
let appService = try await client
.app()
.withEncryptionSync(withCrossProcessLock: appSettings.isEncryptionSyncEnabled,
appIdentifier: "MainApp")
@ -410,10 +429,10 @@ class ClientProxy: ClientProxyProtocol {
guard let self else { return }
MXLog.info("Received app service update: \(state)")
switch state {
case .error:
restartSync()
case .terminated, .running:
case .running, .terminated:
break
case .error:
restartSync(delay: .seconds(1))
}
})
}

View File

@ -44,7 +44,7 @@ include:
packages:
MatrixRustSDK:
url: https://github.com/matrix-org/matrix-rust-components-swift
exactVersion: 1.0.98-alpha
exactVersion: 1.0.99-alpha
# path: ../matrix-rust-sdk
DesignKit:
path: DesignKit