|
|
|
|
@ -177,11 +177,7 @@ public class StoreCenter { |
|
|
|
|
|
|
|
|
|
@objc fileprivate func _launchSynchronization() { |
|
|
|
|
Task { |
|
|
|
|
do { |
|
|
|
|
try await self.synchronizeLastUpdates() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
await self.synchronizeLastUpdates() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -579,22 +575,24 @@ public class StoreCenter { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Basically asks the server for new content |
|
|
|
|
public func synchronizeLastUpdates() async throws { |
|
|
|
|
@discardableResult public func synchronizeLastUpdates() async -> Error? { |
|
|
|
|
|
|
|
|
|
Logger.log("synchronizeLastUpdates: self.synchronizesData: \(self.synchronizesData) / self.isAuthenticated = \(self.isAuthenticated) / self.useSynchronization = \(self.useSynchronization)") |
|
|
|
|
guard self.isAuthenticated, self.useSynchronization else { |
|
|
|
|
return |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
guard !self.synchronizesData else { |
|
|
|
|
// Logger.log("*** blocked sync") |
|
|
|
|
self.wantsToSynchronize = true |
|
|
|
|
return |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
Logger.log("synchronizeLastUpdates started...") |
|
|
|
|
|
|
|
|
|
self.synchronizesData = true |
|
|
|
|
self.wantsToSynchronize = false |
|
|
|
|
|
|
|
|
|
let lastSync = self._settingsStorage.item.lastSynchronization |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
let syncGetCollection: ApiCallCollection<GetSyncData> = try self.apiCallCollection() |
|
|
|
|
if await syncGetCollection.hasPendingCalls() == false { |
|
|
|
|
Logger.log("*** START sync: \(lastSync)") |
|
|
|
|
@ -602,17 +600,13 @@ public class StoreCenter { |
|
|
|
|
getSyncData.date = lastSync |
|
|
|
|
try await syncGetCollection.sendGetRequest(instance: getSyncData) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if await syncGetCollection.hasPendingCalls() { |
|
|
|
|
// await syncGetCollection.rescheduleImmediately() |
|
|
|
|
// Logger.log("=> reschedule") |
|
|
|
|
// } else { |
|
|
|
|
// Logger.log("=> send GET") |
|
|
|
|
// let getSyncData = GetSyncData() |
|
|
|
|
// getSyncData.date = lastSync |
|
|
|
|
// try await syncGetCollection.sendGetRequest(instance: getSyncData) |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
} catch { |
|
|
|
|
self.synchronizesData = false |
|
|
|
|
Logger.error(error) |
|
|
|
|
return error |
|
|
|
|
} |
|
|
|
|
self.synchronizesData = false |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@discardableResult func testSynchronizeOnceAsync() async throws -> Data { |
|
|
|
|
@ -683,11 +677,7 @@ public class StoreCenter { |
|
|
|
|
|
|
|
|
|
self.synchronizesData = false |
|
|
|
|
if self.wantsToSynchronize { |
|
|
|
|
do { |
|
|
|
|
try await self.synchronizeLastUpdates() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
await self.synchronizeLastUpdates() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Logger.log(">>> SYNC ENDED") |
|
|
|
|
|