Add AccountManager.resumeAll, Account.resume. Add suspend() and resume() to AccountDelegate and to individual AccountDelegate instances.

This commit is contained in:
Brent Simmons 2019-11-29 22:57:14 -08:00
parent 8ee169d915
commit b5f1c69f8e
8 changed files with 75 additions and 5 deletions

View File

@ -407,9 +407,16 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
public func suspend() {
delegate.cancelAll(for: self)
delegate.suspend()
database.suspend()
save()
}
public func resume() {
database.resume()
delegate.resume()
}
public func save() {
metadataFile.save()
webFeedMetadataFile.save()

View File

@ -50,5 +50,8 @@ protocol AccountDelegate {
func accountWillBeDeleted(_ account: Account)
static func validateCredentials(transport: Transport, credentials: Credentials, endpoint: URL?, completion: @escaping (Result<Credentials?, Error>) -> Void)
// For iOS, so we can suspend and resume properly.
func suspend() // Make sure no SQLite databases are open.
func resume()
}

View File

@ -166,7 +166,11 @@ public final class AccountManager: UnreadCountProvider {
public func suspendAll() {
accounts.forEach { $0.suspend() }
}
public func resumeAll() {
accounts.forEach { $0.resume() }
}
public func refreshAll(errorHandler: @escaping (Error) -> Void, completion: (() ->Void)? = nil) {
let group = DispatchGroup()

View File

@ -438,6 +438,18 @@ final class FeedWranglerAccountDelegate: AccountDelegate {
}
}
}
// MARK: Suspend and Resume (for iOS)
/// Suspend the sync database so that it can close its SQLite file.
func suspend() {
database.suspend()
}
/// Resume the sync database let it reopen its SQLite file.
func resume() {
database.resume()
}
}
// MARK: Private

View File

@ -555,7 +555,18 @@ final class FeedbinAccountDelegate: AccountDelegate {
}
}
// MARK: Suspend and Resume (for iOS)
/// Suspend the sync database so that it can close its SQLite file.
func suspend() {
database.suspend()
}
/// Resume the sync database let it reopen its SQLite file.
func resume() {
database.resume()
}
}
// MARK: Private

View File

@ -510,4 +510,16 @@ final class FeedlyAccountDelegate: AccountDelegate {
assertionFailure("An `account` instance should enqueue an \(FeedlyRefreshAccessTokenOperation.self) instead.")
completion(.success(credentials))
}
// MARK: Suspend and Resume (for iOS)
/// Suspend the sync database so that it can close its SQLite file.
func suspend() {
database.suspend()
}
/// Resume the sync database let it reopen its SQLite file.
func resume() {
database.resume()
}
}

View File

@ -202,4 +202,14 @@ final class LocalAccountDelegate: AccountDelegate {
static func validateCredentials(transport: Transport, credentials: Credentials, endpoint: URL? = nil, completion: (Result<Credentials?, Error>) -> Void) {
return completion(.success(nil))
}
// MARK: Suspend and Resume (for iOS)
func suspend() {
// Nothing to do
}
func resume() {
// Nothing to do
}
}

View File

@ -436,7 +436,18 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
}
}
// MARK: Suspend and Resume (for iOS)
/// Suspend the sync database so that it can close its SQLite file.
func suspend() {
database.suspend()
}
/// Resume the sync database let it reopen its SQLite file.
func resume() {
database.resume()
}
}
// MARK: Private