mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-02-02 11:12:20 +00:00
Add settings to clear the cache
This commit is contained in:
parent
288a0eac9f
commit
8c7efb7df5
17 changed files with 61 additions and 3 deletions
|
@ -4,6 +4,7 @@ import DesignSystem
|
||||||
import Env
|
import Env
|
||||||
import Models
|
import Models
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import Timeline
|
||||||
|
|
||||||
struct AccountSettingsView: View {
|
struct AccountSettingsView: View {
|
||||||
@Environment(\.dismiss) private var dismiss
|
@Environment(\.dismiss) private var dismiss
|
||||||
|
@ -16,6 +17,7 @@ struct AccountSettingsView: View {
|
||||||
|
|
||||||
@State private var isEditingAccount: Bool = false
|
@State private var isEditingAccount: Bool = false
|
||||||
@State private var isEditingFilters: Bool = false
|
@State private var isEditingFilters: Bool = false
|
||||||
|
@State private var cachedPostsCount: Int = 0
|
||||||
|
|
||||||
let account: Account
|
let account: Account
|
||||||
let appAccount: AppAccount
|
let appAccount: AppAccount
|
||||||
|
@ -49,6 +51,18 @@ struct AccountSettingsView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.listRowBackground(theme.primaryBackgroundColor)
|
.listRowBackground(theme.primaryBackgroundColor)
|
||||||
|
|
||||||
|
Section {
|
||||||
|
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)
|
||||||
|
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.listRowBackground(theme.primaryBackgroundColor)
|
||||||
|
|
||||||
Section {
|
Section {
|
||||||
Button(role: .destructive) {
|
Button(role: .destructive) {
|
||||||
if let token = appAccount.oauthToken {
|
if let token = appAccount.oauthToken {
|
||||||
|
@ -82,6 +96,9 @@ struct AccountSettingsView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.task {
|
||||||
|
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient)
|
||||||
|
}
|
||||||
.navigationTitle(account.safeDisplayName)
|
.navigationTitle(account.safeDisplayName)
|
||||||
.scrollContentBackground(.hidden)
|
.scrollContentBackground(.hidden)
|
||||||
.background(theme.secondaryBackgroundColor)
|
.background(theme.secondaryBackgroundColor)
|
||||||
|
|
|
@ -138,6 +138,8 @@
|
||||||
"settings.display.font.scaling-%@" = "Escalat de la lletra: %@";
|
"settings.display.font.scaling-%@" = "Escalat de la lletra: %@";
|
||||||
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
// MARK: Tabs
|
// MARK: Tabs
|
||||||
"tab.explore" = "Exploreu";
|
"tab.explore" = "Exploreu";
|
||||||
|
|
|
@ -136,6 +136,8 @@
|
||||||
"settings.display.font.scaling-%@" = "Schriftskalierung: %@";
|
"settings.display.font.scaling-%@" = "Schriftskalierung: %@";
|
||||||
"settings.about.built-with" = "Ice Cubes wird mit folgender Open-Source-Software erstellt:";
|
"settings.about.built-with" = "Ice Cubes wird mit folgender Open-Source-Software erstellt:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
"enum.expand-media.show" = "Alle zeigen";
|
"enum.expand-media.show" = "Alle zeigen";
|
||||||
"enum.expand-media.hide" = "Alle ausblenden";
|
"enum.expand-media.hide" = "Alle ausblenden";
|
||||||
|
|
|
@ -140,6 +140,8 @@
|
||||||
"settings.other.autoplay-video" = "Auto Play Videos";
|
"settings.other.autoplay-video" = "Auto Play Videos";
|
||||||
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
// MARK: Tabs
|
// MARK: Tabs
|
||||||
"tab.explore" = "Explore";
|
"tab.explore" = "Explore";
|
||||||
|
|
|
@ -139,6 +139,8 @@
|
||||||
"settings.other.autoplay-video" = "Auto Play Videos";
|
"settings.other.autoplay-video" = "Auto Play Videos";
|
||||||
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
// MARK: Tabs
|
// MARK: Tabs
|
||||||
"tab.explore" = "Explore";
|
"tab.explore" = "Explore";
|
||||||
|
|
|
@ -136,6 +136,8 @@
|
||||||
"settings.display.font.scaling-%@" = "Escalado de tipografía: %@";
|
"settings.display.font.scaling-%@" = "Escalado de tipografía: %@";
|
||||||
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
"enum.expand-media.show" = "Siempre";
|
"enum.expand-media.show" = "Siempre";
|
||||||
"enum.expand-media.hide" = "Nunca";
|
"enum.expand-media.hide" = "Nunca";
|
||||||
|
|
|
@ -139,6 +139,8 @@
|
||||||
"settings.display.font.scaling-%@" = "Font scaling: %@";
|
"settings.display.font.scaling-%@" = "Font scaling: %@";
|
||||||
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
// MARK: Tabs
|
// MARK: Tabs
|
||||||
"tab.explore" = "Explorer";
|
"tab.explore" = "Explorer";
|
||||||
|
|
|
@ -139,6 +139,8 @@
|
||||||
"settings.other.autoplay-video" = "Auto Play dei video";
|
"settings.other.autoplay-video" = "Auto Play dei video";
|
||||||
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
// MARK: Tabs
|
// MARK: Tabs
|
||||||
"tab.explore" = "Esplora";
|
"tab.explore" = "Esplora";
|
||||||
|
|
|
@ -139,6 +139,8 @@
|
||||||
"settings.other.autoplay-video" = "動画の自動再生";
|
"settings.other.autoplay-video" = "動画の自動再生";
|
||||||
"settings.about.built-with" = "Ice Cubesは以下のオープンソースソフトウェアで構築されています:";
|
"settings.about.built-with" = "Ice Cubesは以下のオープンソースソフトウェアで構築されています:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
// MARK: Tabs
|
// MARK: Tabs
|
||||||
"tab.explore" = "エクスプローラー";
|
"tab.explore" = "エクスプローラー";
|
||||||
|
|
|
@ -139,6 +139,8 @@
|
||||||
"settings.display.font.scaling-%@" = "폰트 크기 조절: %@";
|
"settings.display.font.scaling-%@" = "폰트 크기 조절: %@";
|
||||||
"settings.about.built-with" = "Ice Cubes는 다음 오픈 소스 소프트웨어를 사용하여 개발되었습니다:";
|
"settings.about.built-with" = "Ice Cubes는 다음 오픈 소스 소프트웨어를 사용하여 개발되었습니다:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
// MARK: Tabs
|
// MARK: Tabs
|
||||||
"tab.explore" = "둘러보기";
|
"tab.explore" = "둘러보기";
|
||||||
|
|
|
@ -139,6 +139,8 @@
|
||||||
"settings.other.autoplay-video" = "Spill av videoer automatisk";
|
"settings.other.autoplay-video" = "Spill av videoer automatisk";
|
||||||
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
// MARK: Tabs
|
// MARK: Tabs
|
||||||
"tab.explore" = "Utforsk";
|
"tab.explore" = "Utforsk";
|
||||||
|
|
|
@ -136,6 +136,8 @@
|
||||||
"settings.display.font.scaling-%@" = "Font scaling: %@";
|
"settings.display.font.scaling-%@" = "Font scaling: %@";
|
||||||
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
// MARK: Tabs
|
// MARK: Tabs
|
||||||
"tab.explore" = "Ontdekken";
|
"tab.explore" = "Ontdekken";
|
||||||
|
|
|
@ -139,6 +139,8 @@
|
||||||
"settings.display.font.scaling-%@" = "Skalowanie czcionki: %@";
|
"settings.display.font.scaling-%@" = "Skalowanie czcionki: %@";
|
||||||
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
// MARK: Tabs
|
// MARK: Tabs
|
||||||
"tab.explore" = "Odkrywaj";
|
"tab.explore" = "Odkrywaj";
|
||||||
|
|
|
@ -139,6 +139,8 @@
|
||||||
"settings.display.font.scaling-%@" = "Font scaling: %@";
|
"settings.display.font.scaling-%@" = "Font scaling: %@";
|
||||||
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
// MARK: Tabs
|
// MARK: Tabs
|
||||||
"tab.explore" = "Explorar";
|
"tab.explore" = "Explorar";
|
||||||
|
|
|
@ -139,6 +139,8 @@
|
||||||
"settings.display.font.scaling-%@" = "Font scaling: %@";
|
"settings.display.font.scaling-%@" = "Font scaling: %@";
|
||||||
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
// MARK: Tabs
|
// MARK: Tabs
|
||||||
"tab.explore" = "Keşfet";
|
"tab.explore" = "Keşfet";
|
||||||
|
|
|
@ -134,6 +134,8 @@
|
||||||
"settings.other.autoplay-video" = "自动播放视频";
|
"settings.other.autoplay-video" = "自动播放视频";
|
||||||
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
|
||||||
"settings.about.title" = "Ice Cubes";
|
"settings.about.title" = "Ice Cubes";
|
||||||
|
"settings.account.cached-posts-%@" = "Cached posts: %@";
|
||||||
|
"settings.account.action.delete-cache" = "Clear cache";
|
||||||
|
|
||||||
"settings.display.font" = "时间线字体";
|
"settings.display.font" = "时间线字体";
|
||||||
"settings.display.font.system" = "系统";
|
"settings.display.font.system" = "系统";
|
||||||
|
|
|
@ -3,8 +3,8 @@ import Network
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import Boutique
|
import Boutique
|
||||||
|
|
||||||
actor TimelineCache {
|
public actor TimelineCache {
|
||||||
static let shared: TimelineCache = .init()
|
public static let shared: TimelineCache = .init()
|
||||||
|
|
||||||
private func storageFor(_ client: Client) -> SQLiteStorageEngine {
|
private func storageFor(_ client: Client) -> SQLiteStorageEngine {
|
||||||
SQLiteStorageEngine.default(appendingPath: client.id)
|
SQLiteStorageEngine.default(appendingPath: client.id)
|
||||||
|
@ -15,9 +15,20 @@ actor TimelineCache {
|
||||||
|
|
||||||
private init() {}
|
private init() {}
|
||||||
|
|
||||||
|
public func cachedPostsCount(for client: Client) async -> Int {
|
||||||
|
await storageFor(client).allKeys().count
|
||||||
|
}
|
||||||
|
|
||||||
|
public func clearCache(for client: Client) async {
|
||||||
|
let engine = storageFor(client)
|
||||||
|
do {
|
||||||
|
try await engine.removeAllData()
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
|
||||||
func set(statuses: [Status], client: Client) async {
|
func set(statuses: [Status], client: Client) async {
|
||||||
guard !statuses.isEmpty else { return }
|
guard !statuses.isEmpty else { return }
|
||||||
let statuses = statuses.prefix(upTo: min(300, statuses.count - 1)).map { $0 }
|
let statuses = statuses.prefix(upTo: min(400, statuses.count - 1)).map { $0 }
|
||||||
do {
|
do {
|
||||||
let engine = storageFor(client)
|
let engine = storageFor(client)
|
||||||
try await engine.removeAllData()
|
try await engine.removeAllData()
|
||||||
|
|
Loading…
Reference in a new issue