Skip to content

Commit df34f1a

Browse files
committed
feat: add button to clear cache directory
Signed-off-by: Tommy van der Vorst <tommy@pixelspark.nl>
1 parent e116286 commit df34f1a

File tree

2 files changed

+226
-0
lines changed

2 files changed

+226
-0
lines changed

Localizable.xcstrings

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5962,6 +5962,52 @@
59625962
}
59635963
}
59645964
},
5965+
"Cache directory cleared" : {
5966+
"localizations" : {
5967+
"de" : {
5968+
"stringUnit" : {
5969+
"state" : "translated",
5970+
"value" : "Cache-Verzeichnis gelöscht"
5971+
}
5972+
},
5973+
"es" : {
5974+
"stringUnit" : {
5975+
"state" : "translated",
5976+
"value" : "Directorio de caché borrado"
5977+
}
5978+
},
5979+
"it" : {
5980+
"stringUnit" : {
5981+
"state" : "translated",
5982+
"value" : "Directory cache svuotata"
5983+
}
5984+
},
5985+
"ja" : {
5986+
"stringUnit" : {
5987+
"state" : "translated",
5988+
"value" : "キャッシュディレクトリをクリアしました"
5989+
}
5990+
},
5991+
"nl" : {
5992+
"stringUnit" : {
5993+
"state" : "translated",
5994+
"value" : "Cachemap gewist"
5995+
}
5996+
},
5997+
"uk" : {
5998+
"stringUnit" : {
5999+
"state" : "translated",
6000+
"value" : "Каталог кешу очищено"
6001+
}
6002+
},
6003+
"zh-Hans" : {
6004+
"stringUnit" : {
6005+
"state" : "translated",
6006+
"value" : "缓存目录已清除"
6007+
}
6008+
}
6009+
}
6010+
},
59656011
"Cache inside folder" : {
59666012
"localizations" : {
59676013
"de" : {
@@ -6744,6 +6790,52 @@
67446790
}
67456791
}
67466792
},
6793+
"Clear cache directory" : {
6794+
"localizations" : {
6795+
"de" : {
6796+
"stringUnit" : {
6797+
"state" : "translated",
6798+
"value" : "Cache-Verzeichnis leeren"
6799+
}
6800+
},
6801+
"es" : {
6802+
"stringUnit" : {
6803+
"state" : "translated",
6804+
"value" : "Limpiar directorio de caché"
6805+
}
6806+
},
6807+
"it" : {
6808+
"stringUnit" : {
6809+
"state" : "translated",
6810+
"value" : "Cancella la directory della cache"
6811+
}
6812+
},
6813+
"ja" : {
6814+
"stringUnit" : {
6815+
"state" : "translated",
6816+
"value" : "キャッシュディレクトリをクリア"
6817+
}
6818+
},
6819+
"nl" : {
6820+
"stringUnit" : {
6821+
"state" : "translated",
6822+
"value" : "Cachemap wissen"
6823+
}
6824+
},
6825+
"uk" : {
6826+
"stringUnit" : {
6827+
"state" : "translated",
6828+
"value" : "Очистити каталог кешу"
6829+
}
6830+
},
6831+
"zh-Hans" : {
6832+
"stringUnit" : {
6833+
"state" : "translated",
6834+
"value" : "清除缓存目录"
6835+
}
6836+
}
6837+
}
6838+
},
67476839
"Clear thumbnail cache" : {
67486840
"localizations" : {
67496841
"de" : {
@@ -17224,6 +17316,52 @@
1722417316
}
1722517317
}
1722617318
},
17319+
"Ignored discovered devices reset" : {
17320+
"localizations" : {
17321+
"de" : {
17322+
"stringUnit" : {
17323+
"state" : "translated",
17324+
"value" : "Ignorierte gefundene Geräte zurücksetzen"
17325+
}
17326+
},
17327+
"es" : {
17328+
"stringUnit" : {
17329+
"state" : "translated",
17330+
"value" : "Restablecer dispositivos descubiertos ignorados"
17331+
}
17332+
},
17333+
"it" : {
17334+
"stringUnit" : {
17335+
"state" : "translated",
17336+
"value" : "Reimposta dispositivi rilevati ignorati"
17337+
}
17338+
},
17339+
"ja" : {
17340+
"stringUnit" : {
17341+
"state" : "translated",
17342+
"value" : "無視された発見済みデバイスをリセット"
17343+
}
17344+
},
17345+
"nl" : {
17346+
"stringUnit" : {
17347+
"state" : "translated",
17348+
"value" : "Genegeerde ontdekte apparaten opnieuw instellen"
17349+
}
17350+
},
17351+
"uk" : {
17352+
"stringUnit" : {
17353+
"state" : "translated",
17354+
"value" : "Ігноровані виявлені пристрої скинуто"
17355+
}
17356+
},
17357+
"zh-Hans" : {
17358+
"stringUnit" : {
17359+
"state" : "translated",
17360+
"value" : "重置已忽略的发现设备"
17361+
}
17362+
}
17363+
}
17364+
},
1722717365
"IMG_2020.MOV" : {
1722817366
"localizations" : {
1722917367
"de" : {
@@ -24510,6 +24648,52 @@
2451024648
}
2451124649
}
2451224650
},
24651+
"Removed v1 database back-up" : {
24652+
"localizations" : {
24653+
"de" : {
24654+
"stringUnit" : {
24655+
"state" : "translated",
24656+
"value" : "v1-Datenbank-Backup entfernt"
24657+
}
24658+
},
24659+
"es" : {
24660+
"stringUnit" : {
24661+
"state" : "translated",
24662+
"value" : "Copia de seguridad de la base de datos v1 eliminada"
24663+
}
24664+
},
24665+
"it" : {
24666+
"stringUnit" : {
24667+
"state" : "translated",
24668+
"value" : "Backup del database v1 rimosso"
24669+
}
24670+
},
24671+
"ja" : {
24672+
"stringUnit" : {
24673+
"state" : "translated",
24674+
"value" : "v1データベースのバックアップを削除しました"
24675+
}
24676+
},
24677+
"nl" : {
24678+
"stringUnit" : {
24679+
"state" : "translated",
24680+
"value" : "v1-databaseback-up verwijderd"
24681+
}
24682+
},
24683+
"uk" : {
24684+
"stringUnit" : {
24685+
"state" : "translated",
24686+
"value" : "резервну копію бази даних v1 видалено"
24687+
}
24688+
},
24689+
"zh-Hans" : {
24690+
"stringUnit" : {
24691+
"state" : "translated",
24692+
"value" : "已删除 v1 数据库备份"
24693+
}
24694+
}
24695+
}
24696+
},
2451324697
"Removing originals" : {
2451424698
"localizations" : {
2451524699
"de" : {

Sushitrain/SupportView.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ struct TroubleshootingView: View {
306306
@State private var hasLegacyDatabase = false
307307
@State private var performingDatabaseMaintenance = false
308308
@State private var databaseSize: Int64? = nil
309+
@State private var showIgnoredDiscoveredReset = false
310+
@State private var showV1BackupRemoved = false
311+
@State private var showCacheCleared = false
309312

310313
private static let formatter = ByteCountFormatter()
311314

@@ -396,6 +399,9 @@ struct TroubleshootingView: View {
396399
#if os(macOS)
397400
.buttonStyle(.link)
398401
#endif
402+
.alert("Removed v1 database back-up", isPresented: $showV1BackupRemoved) {
403+
Button("OK") {}
404+
}
399405
} footer: {
400406
Text(
401407
"After a database upgrade, a copy of the old version is retained for a while. This copy may take up a significant amount of storage space. If everything is working as expected, it is safe to remove this back-up."
@@ -406,6 +412,19 @@ struct TroubleshootingView: View {
406412
Section {
407413
Button("Reset ignored discovered devices", role: .destructive) {
408414
appState.userSettings.ignoreDiscoveredDevices.removeAll()
415+
showIgnoredDiscoveredReset = true
416+
}
417+
.alert("Ignored discovered devices reset", isPresented: $showIgnoredDiscoveredReset) {
418+
Button("OK") {}
419+
}
420+
}
421+
422+
Section {
423+
Button("Clear cache directory", role: .destructive) {
424+
self.clearCacheDirectory()
425+
}
426+
.alert("Cache directory cleared", isPresented: $showCacheCleared) {
427+
Button("OK") {}
409428
}
410429
}
411430
}
@@ -461,6 +480,29 @@ struct TroubleshootingView: View {
461480
}
462481
await self.updateDatabaseInfo()
463482
self.performingDatabaseMaintenance = false
483+
self.showV1BackupRemoved = true
484+
}
485+
}
486+
487+
private func clearCacheDirectory() {
488+
let fileManager = FileManager.default
489+
if let cacheURL = fileManager.urls(for: .cachesDirectory, in: .userDomainMask).first {
490+
do {
491+
let directoryContents = try fileManager.contentsOfDirectory(
492+
at: cacheURL, includingPropertiesForKeys: nil, options: [])
493+
for file in directoryContents {
494+
do {
495+
try fileManager.removeItem(at: file)
496+
}
497+
catch {
498+
Log.warn("failed to remove cache file: \(error.localizedDescription)")
499+
}
500+
}
501+
}
502+
catch let error as NSError {
503+
print(error.localizedDescription)
504+
}
464505
}
506+
self.showCacheCleared = true
465507
}
466508
}

0 commit comments

Comments
 (0)