Use new Reachability.internetIsReachable.
This commit is contained in:
parent
46645f700a
commit
3b59ffc446
|
@ -221,18 +221,9 @@ import Secrets
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func internetIsReachable() -> Bool {
|
|
||||||
|
|
||||||
guard let reachability = try? Reachability(hostname: "apple.com"), reachability.connection != .unavailable else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
public func refreshAll(errorHandler: ((Error) -> Void)? = nil) async {
|
public func refreshAll(errorHandler: ((Error) -> Void)? = nil) async {
|
||||||
|
|
||||||
guard internetIsReachable() else {
|
guard Reachability.internetIsReachable else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,13 +90,7 @@ enum CloudKitAccountDelegateError: LocalizedError {
|
||||||
|
|
||||||
func refreshAll(for account: Account) async throws {
|
func refreshAll(for account: Account) async throws {
|
||||||
|
|
||||||
guard refreshProgress.isComplete else {
|
guard refreshProgress.isComplete, Reachability.internetIsReachable else {
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let reachability = SCNetworkReachabilityCreateWithName(nil, "apple.com")
|
|
||||||
var flags = SCNetworkReachabilityFlags()
|
|
||||||
guard SCNetworkReachabilityGetFlags(reachability!, &flags), flags.contains(.reachable) else {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,34 +20,29 @@ struct CacheCleaner {
|
||||||
AppDefaults.shared.lastImageCacheFlushDate = Date()
|
AppDefaults.shared.lastImageCacheFlushDate = Date()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the image disk cache hasn't been flushed for 3 days and the network is available, delete it
|
// If the image disk cache hasn't been flushed for 3 days and the network is available, delete it
|
||||||
if flushDate.addingTimeInterval(3600 * 24 * 3) < Date() {
|
if flushDate.addingTimeInterval(3600 * 24 * 3) < Date() {
|
||||||
if let reachability = try? Reachability(hostname: "apple.com") {
|
if Reachability.internetIsReachable {
|
||||||
if reachability.connection != .unavailable {
|
|
||||||
|
|
||||||
let tempDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
|
let tempDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
|
||||||
let faviconsFolderURL = tempDir.appendingPathComponent("Favicons")
|
let faviconsFolderURL = tempDir.appendingPathComponent("Favicons")
|
||||||
let imagesFolderURL = tempDir.appendingPathComponent("Images")
|
let imagesFolderURL = tempDir.appendingPathComponent("Images")
|
||||||
let feedURLToIconURL = tempDir.appendingPathComponent("FeedURLToIconURLCache.plist")
|
let feedURLToIconURL = tempDir.appendingPathComponent("FeedURLToIconURLCache.plist")
|
||||||
let homePageToIconURL = tempDir.appendingPathComponent("HomePageToIconURLCache.plist")
|
let homePageToIconURL = tempDir.appendingPathComponent("HomePageToIconURLCache.plist")
|
||||||
let homePagesWithNoIconURL = tempDir.appendingPathComponent("HomePagesWithNoIconURLCache.plist")
|
let homePagesWithNoIconURL = tempDir.appendingPathComponent("HomePagesWithNoIconURLCache.plist")
|
||||||
|
|
||||||
for tempItem in [faviconsFolderURL, imagesFolderURL, feedURLToIconURL, homePageToIconURL, homePagesWithNoIconURL] {
|
for tempItem in [faviconsFolderURL, imagesFolderURL, feedURLToIconURL, homePageToIconURL, homePagesWithNoIconURL] {
|
||||||
do {
|
do {
|
||||||
os_log(.info, log: self.log, "Removing cache file: %@", tempItem.absoluteString)
|
os_log(.info, log: self.log, "Removing cache file: %@", tempItem.absoluteString)
|
||||||
try FileManager.default.removeItem(at: tempItem)
|
try FileManager.default.removeItem(at: tempItem)
|
||||||
} catch {
|
} catch {
|
||||||
os_log(.error, log: self.log, "Could not delete cache file: %@", error.localizedDescription)
|
os_log(.error, log: self.log, "Could not delete cache file: %@", error.localizedDescription)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AppDefaults.shared.lastImageCacheFlushDate = Date()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppDefaults.shared.lastImageCacheFlushDate = Date()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue