mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 16:26:04 +00:00
Delete no-longer-used AccountMetadataFile.
This commit is contained in:
1 parent
2f047374f5
commit
6aba4439e7
1 file changed
-70
@@ -1,70 +0,0 @@
|
||||
//
|
||||
// AccountMetadataFile.swift
|
||||
// Account
|
||||
//
|
||||
// Created by Maurice Parker on 9/13/19.
|
||||
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import os.log
|
||||
import RSCore
|
||||
|
||||
final class AccountMetadataFile {
|
||||
private let fileURL: URL
|
||||
private let account: Account
|
||||
|
||||
@MainActor private var isDirty = false {
|
||||
didSet {
|
||||
queueSaveToDiskIfNeeded()
|
||||
}
|
||||
}
|
||||
private let saveQueue = CoalescingQueue(name: "Save Queue", interval: 0.5)
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "AccountMetadataFile")
|
||||
|
||||
init(filename: String, account: Account) {
|
||||
self.fileURL = URL(fileURLWithPath: filename)
|
||||
self.account = account
|
||||
}
|
||||
|
||||
@MainActor func markAsDirty() {
|
||||
isDirty = true
|
||||
}
|
||||
|
||||
@MainActor func load() {
|
||||
if let fileData = try? Data(contentsOf: fileURL) {
|
||||
let decoder = PropertyListDecoder()
|
||||
account.metadata = (try? decoder.decode(AccountMetadata.self, from: fileData)) ?? AccountMetadata()
|
||||
}
|
||||
account.metadata.delegate = account
|
||||
}
|
||||
|
||||
@MainActor func save() {
|
||||
guard !account.isDeleted else { return }
|
||||
|
||||
let encoder = PropertyListEncoder()
|
||||
encoder.outputFormat = .binary
|
||||
|
||||
do {
|
||||
let data = try encoder.encode(account.metadata)
|
||||
try data.write(to: fileURL)
|
||||
} catch let error as NSError {
|
||||
Self.logger.error("AccountMetadataFile accountID: \(self.account.accountID) save to disk failed: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension AccountMetadataFile {
|
||||
|
||||
@MainActor func queueSaveToDiskIfNeeded() {
|
||||
saveQueue.add(self, #selector(saveToDiskIfNeeded))
|
||||
}
|
||||
|
||||
@MainActor @objc func saveToDiskIfNeeded() {
|
||||
if isDirty {
|
||||
isDirty = false
|
||||
save()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user