Compare commits
3 Commits
d224f47b8c
...
cccde29e6c
Author | SHA1 | Date |
---|---|---|
Shadowfacts | cccde29e6c | |
Shadowfacts | aa0629d202 | |
Shadowfacts | ba209fa4d2 |
|
@ -21,7 +21,7 @@ class DiskCache<T> {
|
|||
let defaultExpiry: CacheExpiry
|
||||
let transformer: DiskCacheTransformer<T>
|
||||
|
||||
private var fileStates = [String: FileState]()
|
||||
private var fileStates = MultiThreadDictionary<String, FileState>()
|
||||
|
||||
init(name: String, defaultExpiry: CacheExpiry, transformer: DiskCacheTransformer<T>, fileManager: FileManager = .default) throws {
|
||||
self.defaultExpiry = defaultExpiry
|
||||
|
@ -117,7 +117,9 @@ class DiskCache<T> {
|
|||
func removeAll() throws {
|
||||
try fileManager.removeItem(atPath: path)
|
||||
try createDirectory()
|
||||
fileStates.removeAll()
|
||||
fileStates.withLock { dict in
|
||||
dict.removeAll()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,13 +16,7 @@ class MultiThreadDictionary<Key: Hashable & Sendable, Value: Sendable> {
|
|||
private let lock: LockHolder<[AnyHashable: Any]>
|
||||
|
||||
init() {
|
||||
if #available(iOS 16.0, *) {
|
||||
let lock = OSAllocatedUnfairLock(initialState: [:])
|
||||
self.lock = LockHolder(withLock: lock.withLock(_:))
|
||||
} else {
|
||||
let lock = UnfairLock(initialState: [:])
|
||||
self.lock = LockHolder(withLock: lock.withLock(_:))
|
||||
}
|
||||
self.lock = LockHolder(initialState: [:])
|
||||
}
|
||||
|
||||
subscript(key: Key) -> Value? {
|
||||
|
@ -66,6 +60,16 @@ class MultiThreadDictionary<Key: Hashable & Sendable, Value: Sendable> {
|
|||
// see #178
|
||||
fileprivate struct LockHolder<State> {
|
||||
let withLock: (_ body: @Sendable (inout State) throws -> any Sendable) throws -> any Sendable
|
||||
|
||||
init(initialState: State) {
|
||||
if #available(iOS 16.0, *) {
|
||||
let lock = OSAllocatedUnfairLock(initialState: initialState)
|
||||
self.withLock = lock.withLock(_:)
|
||||
} else {
|
||||
let lock = UnfairLock(initialState: initialState)
|
||||
self.withLock = lock.withLock(_:)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: replace this only with OSAllocatedUnfairLock
|
||||
|
|
|
@ -142,6 +142,7 @@ class IssueReporterViewController: UIViewController {
|
|||
let url = dir.appendingPathComponent(reportFilename)
|
||||
try! reportText.data(using: .utf8)!.write(to: url)
|
||||
let activityController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
|
||||
activityController.popoverPresentationController?.sourceView = sendReportButton
|
||||
present(activityController, animated: true)
|
||||
}
|
||||
|
||||
|
@ -154,7 +155,11 @@ class IssueReporterViewController: UIViewController {
|
|||
extension IssueReporterViewController: MFMailComposeViewControllerDelegate {
|
||||
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
|
||||
controller.dismiss(animated: true) {
|
||||
if result == .cancelled {
|
||||
// don't dismiss ourself, to allowe the user to send the report a different way
|
||||
} else {
|
||||
self.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue