Remove some .shared usage
This commit is contained in:
parent
90fc2907d3
commit
60713101a7
|
@ -21,6 +21,7 @@ struct AccountSettingsView: View {
|
|||
@State private var isEditingAccount: Bool = false
|
||||
@State private var isEditingFilters: Bool = false
|
||||
@State private var cachedPostsCount: Int = 0
|
||||
@State private var timelineCache = TimelineCache()
|
||||
|
||||
let account: Account
|
||||
let appAccount: AppAccount
|
||||
|
@ -59,8 +60,8 @@ struct AccountSettingsView: View {
|
|||
Label("settings.account.cached-posts-\(String(cachedPostsCount))", systemImage: "internaldrive")
|
||||
Button("settings.account.action.delete-cache", role: .destructive) {
|
||||
Task {
|
||||
await TimelineCache.shared.clearCache(for: appAccountsManager.currentClient.id)
|
||||
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient.id)
|
||||
await timelineCache.clearCache(for: appAccountsManager.currentClient.id)
|
||||
cachedPostsCount = await timelineCache.cachedPostsCount(for: appAccountsManager.currentClient.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +81,7 @@ struct AccountSettingsView: View {
|
|||
if let token = appAccount.oauthToken {
|
||||
Task {
|
||||
let client = Client(server: appAccount.server, oauthToken: token)
|
||||
await TimelineCache.shared.clearCache(for: client.id)
|
||||
await timelineCache.clearCache(for: client.id)
|
||||
if let sub = pushNotifications.subscriptions.first(where: { $0.account.token == token }) {
|
||||
await sub.deleteSubscription()
|
||||
}
|
||||
|
@ -111,7 +112,7 @@ struct AccountSettingsView: View {
|
|||
}
|
||||
}
|
||||
.task {
|
||||
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient.id)
|
||||
cachedPostsCount = await timelineCache.cachedPostsCount(for: appAccountsManager.currentClient.id)
|
||||
}
|
||||
.navigationTitle(account.safeDisplayName)
|
||||
.scrollContentBackground(.hidden)
|
||||
|
|
|
@ -14,8 +14,6 @@ import SwiftUI
|
|||
var labelColor = Theme.shared.labelColor
|
||||
var lineSpacing = Theme.shared.lineSpacing
|
||||
var fontSizeScale = Theme.shared.fontSizeScale
|
||||
|
||||
init() {}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
@ -52,27 +50,27 @@ struct DisplaySettingsView: View {
|
|||
.background(theme.secondaryBackgroundColor)
|
||||
.task(id: localValues.tintColor) {
|
||||
do { try await Task.sleep(for: .microseconds(500)) } catch {}
|
||||
Theme.shared.tintColor = localValues.tintColor
|
||||
theme.tintColor = localValues.tintColor
|
||||
}
|
||||
.task(id: localValues.primaryBackgroundColor) {
|
||||
do { try await Task.sleep(for: .microseconds(500)) } catch {}
|
||||
Theme.shared.primaryBackgroundColor = localValues.primaryBackgroundColor
|
||||
theme.primaryBackgroundColor = localValues.primaryBackgroundColor
|
||||
}
|
||||
.task(id: localValues.secondaryBackgroundColor) {
|
||||
do { try await Task.sleep(for: .microseconds(500)) } catch {}
|
||||
Theme.shared.secondaryBackgroundColor = localValues.secondaryBackgroundColor
|
||||
theme.secondaryBackgroundColor = localValues.secondaryBackgroundColor
|
||||
}
|
||||
.task(id: localValues.labelColor) {
|
||||
do { try await Task.sleep(for: .microseconds(500)) } catch {}
|
||||
Theme.shared.labelColor = localValues.labelColor
|
||||
theme.labelColor = localValues.labelColor
|
||||
}
|
||||
.task(id: localValues.lineSpacing) {
|
||||
do { try await Task.sleep(for: .microseconds(500)) } catch {}
|
||||
Theme.shared.lineSpacing = localValues.lineSpacing
|
||||
theme.lineSpacing = localValues.lineSpacing
|
||||
}
|
||||
.task(id: localValues.fontSizeScale) {
|
||||
do { try await Task.sleep(for: .microseconds(500)) } catch {}
|
||||
Theme.shared.fontSizeScale = localValues.fontSizeScale
|
||||
theme.fontSizeScale = localValues.fontSizeScale
|
||||
}
|
||||
examplePost
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ struct SettingsTabs: View {
|
|||
@State private var addAccountSheetPresented = false
|
||||
@State private var isEditingAccount = false
|
||||
@State private var cachedRemoved = false
|
||||
@State private var timelineCache = TimelineCache()
|
||||
|
||||
@Binding var popToRootTab: Tab
|
||||
|
||||
|
@ -114,7 +115,7 @@ struct SettingsTabs: View {
|
|||
let sub = pushNotifications.subscriptions.first(where: { $0.account.token == token })
|
||||
{
|
||||
let client = Client(server: account.server, oauthToken: token)
|
||||
await TimelineCache.shared.clearCache(for: client.id)
|
||||
await timelineCache.clearCache(for: client.id)
|
||||
await sub.deleteSubscription()
|
||||
appAccountsManager.delete(account: account)
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ import Network
|
|||
import SwiftUI
|
||||
|
||||
public actor TimelineCache {
|
||||
public static let shared: TimelineCache = .init()
|
||||
|
||||
private func storageFor(_ client: String) -> SQLiteStorageEngine {
|
||||
SQLiteStorageEngine.default(appendingPath: client)
|
||||
}
|
||||
|
@ -13,7 +11,7 @@ public actor TimelineCache {
|
|||
private let decoder = JSONDecoder()
|
||||
private let encoder = JSONEncoder()
|
||||
|
||||
private init() {}
|
||||
public init() {}
|
||||
|
||||
public func cachedPostsCount(for client: String) async -> Int {
|
||||
await storageFor(client).allKeys().count
|
||||
|
|
|
@ -51,7 +51,7 @@ import SwiftUI
|
|||
|
||||
// Internal source of truth for a timeline.
|
||||
private var datasource = TimelineDatasource()
|
||||
private let cache: TimelineCache = .shared
|
||||
private let cache = TimelineCache()
|
||||
private var visibileStatusesIds = Set<String>()
|
||||
private var canStreamEvents: Bool = true
|
||||
|
||||
|
|
Loading…
Reference in New Issue