Add a "clear cache" function
This commit is contained in:
@@ -716,6 +716,94 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Clear Cache" : {
|
||||||
|
"localizations" : {
|
||||||
|
"de" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Cache leeren"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"es" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Borrar caché"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fr" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Vider le cache"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Clear Cache?" : {
|
||||||
|
"localizations" : {
|
||||||
|
"de" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Cache leeren?"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"es" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "¿Borrar caché?"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fr" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Vider le cache ?"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"This will delete all locally cached artwork and library data. The next launch or reload may take longer while everything is fetched again." : {
|
||||||
|
"localizations" : {
|
||||||
|
"de" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Dadurch werden alle lokal gespeicherten Bilder und Bibliotheksdaten gelöscht. Der nächste Start oder das nächste Laden kann länger dauern, während alles neu abgerufen wird."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"es" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Esto eliminará todas las ilustraciones y datos de biblioteca almacenados localmente. El siguiente inicio o recarga puede tardar más mientras todo se vuelve a descargar."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fr" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Cela supprimera toutes les illustrations et données de bibliothèque stockées localement. Le prochain démarrage ou rechargement peut prendre plus de temps pendant que tout est à nouveau récupéré."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Clearing the cache removes all locally stored artwork and library data. The next launch or reload may take longer." : {
|
||||||
|
"localizations" : {
|
||||||
|
"de" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Das Leeren des Caches entfernt alle lokal gespeicherten Bilder und Bibliotheksdaten. Der nächste Start oder das nächste Laden kann länger dauern."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"es" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Borrar el caché elimina todas las ilustraciones y datos de biblioteca almacenados localmente. El siguiente inicio o recarga puede tardar más."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fr" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Vider le cache supprime toutes les illustrations et données de bibliothèque stockées localement. Le prochain démarrage ou rechargement peut prendre plus de temps."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"Connect" : {
|
"Connect" : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
"de" : {
|
"de" : {
|
||||||
|
|||||||
@@ -145,6 +145,36 @@ final class MALibraryManager {
|
|||||||
return try? JSONDecoder().decode(T.self, from: data)
|
return try? JSONDecoder().decode(T.self, from: data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Clears all cached library data from memory and disk.
|
||||||
|
func clearAll() {
|
||||||
|
artists = []
|
||||||
|
albumArtists = []
|
||||||
|
albums = []
|
||||||
|
playlists = []
|
||||||
|
podcasts = []
|
||||||
|
favoriteURIs = []
|
||||||
|
artistsOffset = 0
|
||||||
|
albumArtistsOffset = 0
|
||||||
|
albumsOffset = 0
|
||||||
|
hasMoreArtists = true
|
||||||
|
hasMoreAlbumArtists = true
|
||||||
|
hasMoreAlbums = true
|
||||||
|
lastArtistsRefresh = nil
|
||||||
|
lastAlbumArtistsRefresh = nil
|
||||||
|
lastAlbumsRefresh = nil
|
||||||
|
lastPlaylistsRefresh = nil
|
||||||
|
lastPodcastsRefresh = nil
|
||||||
|
|
||||||
|
let ud = UserDefaults.standard
|
||||||
|
for key in ["lib.lastArtistsRefresh", "lib.lastAlbumArtistsRefresh",
|
||||||
|
"lib.lastAlbumsRefresh", "lib.lastPlaylistsRefresh", "lib.lastPodcastsRefresh"] {
|
||||||
|
ud.removeObject(forKey: key)
|
||||||
|
}
|
||||||
|
|
||||||
|
try? FileManager.default.removeItem(at: cacheDirectory)
|
||||||
|
try? FileManager.default.createDirectory(at: cacheDirectory, withIntermediateDirectories: true)
|
||||||
|
}
|
||||||
|
|
||||||
private func markRefreshed(_ key: String) -> Date {
|
private func markRefreshed(_ key: String) -> Date {
|
||||||
let now = Date()
|
let now = Date()
|
||||||
UserDefaults.standard.set(now, forKey: key)
|
UserDefaults.standard.set(now, forKey: key)
|
||||||
|
|||||||
@@ -392,6 +392,7 @@ struct SettingsView: View {
|
|||||||
@Environment(\.localeManager) private var localeManager
|
@Environment(\.localeManager) private var localeManager
|
||||||
@Environment(MAStoreManager.self) private var storeManager
|
@Environment(MAStoreManager.self) private var storeManager
|
||||||
@State private var showThankYou = false
|
@State private var showThankYou = false
|
||||||
|
@State private var showClearCacheConfirm = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
@@ -476,12 +477,19 @@ struct SettingsView: View {
|
|||||||
|
|
||||||
// Actions Section
|
// Actions Section
|
||||||
Section {
|
Section {
|
||||||
|
Button(role: .destructive) {
|
||||||
|
showClearCacheConfirm = true
|
||||||
|
} label: {
|
||||||
|
Label("Clear Cache", systemImage: "trash")
|
||||||
|
}
|
||||||
Button(role: .destructive) {
|
Button(role: .destructive) {
|
||||||
service.disconnect()
|
service.disconnect()
|
||||||
service.authManager.logout()
|
service.authManager.logout()
|
||||||
} label: {
|
} label: {
|
||||||
Label("Disconnect", systemImage: "arrow.right.square")
|
Label("Disconnect", systemImage: "arrow.right.square")
|
||||||
}
|
}
|
||||||
|
} footer: {
|
||||||
|
Text("Clearing the cache removes all locally stored artwork and library data. The next launch or reload may take longer.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Support Development Section
|
// Support Development Section
|
||||||
@@ -536,6 +544,15 @@ struct SettingsView: View {
|
|||||||
.task {
|
.task {
|
||||||
await storeManager.loadProducts()
|
await storeManager.loadProducts()
|
||||||
}
|
}
|
||||||
|
.alert("Clear Cache?", isPresented: $showClearCacheConfirm) {
|
||||||
|
Button("Clear", role: .destructive) {
|
||||||
|
ImageCache.shared.clearAll()
|
||||||
|
service.libraryManager.clearAll()
|
||||||
|
}
|
||||||
|
Button("Cancel", role: .cancel) { }
|
||||||
|
} message: {
|
||||||
|
Text("This will delete all locally cached artwork and library data. The next launch or reload may take longer while everything is fetched again.")
|
||||||
|
}
|
||||||
.alert("Thank You!", isPresented: $showThankYou) {
|
.alert("Thank You!", isPresented: $showThankYou) {
|
||||||
Button("You're welcome!", role: .cancel) { }
|
Button("You're welcome!", role: .cancel) { }
|
||||||
} message: {
|
} message: {
|
||||||
|
|||||||
Reference in New Issue
Block a user