Update SoraApp.swift

This commit is contained in:
cranci1 2025-07-12 17:16:11 +02:00
parent fe0750078e
commit e443296ec4

View file

@ -19,13 +19,16 @@ struct SoraApp: App {
if let userAccentColor = UserDefaults.standard.color(forKey: "accentColor") { if let userAccentColor = UserDefaults.standard.color(forKey: "accentColor") {
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = userAccentColor UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = userAccentColor
} }
clearTmpFolder()
TraktToken.checkAuthenticationStatus { isAuthenticated in Task { @MainActor in
if isAuthenticated { await Self.clearTmpFolder()
Logger.shared.log("Trakt authentication is valid", type: "Debug")
} else { TraktToken.checkAuthenticationStatus { isAuthenticated in
Logger.shared.log("Trakt authentication required", type: "Debug") if isAuthenticated {
Logger.shared.log("Trakt authentication is valid", type: "Debug")
} else {
Logger.shared.log("Trakt authentication required", type: "Debug")
}
} }
} }
} }
@ -105,7 +108,7 @@ struct SoraApp: App {
} }
} }
private func clearTmpFolder() { private static func clearTmpFolder() async {
let fileManager = FileManager.default let fileManager = FileManager.default
let tmpDirectory = NSTemporaryDirectory() let tmpDirectory = NSTemporaryDirectory()
@ -113,19 +116,13 @@ struct SoraApp: App {
let tmpURL = URL(fileURLWithPath: tmpDirectory) let tmpURL = URL(fileURLWithPath: tmpDirectory)
let tmpContents = try fileManager.contentsOfDirectory(at: tmpURL, includingPropertiesForKeys: nil) let tmpContents = try fileManager.contentsOfDirectory(at: tmpURL, includingPropertiesForKeys: nil)
for url in tmpContents { try await withThrowingTaskGroup(of: Void.self) { group in
try fileManager.removeItem(at: url) for url in tmpContents {
} group.addTask {
try FileManager.default.removeItem(at: url)
let parentURL = tmpURL.deletingLastPathComponent()
let parentContents = try fileManager.contentsOfDirectory(at: parentURL, includingPropertiesForKeys: [.isDirectoryKey])
for url in parentContents {
if url.lastPathComponent.hasPrefix("com.apple.UserManagedAssets") {
var isDir: ObjCBool = false
if fileManager.fileExists(atPath: url.path, isDirectory: &isDir), isDir.boolValue {
try fileManager.removeItem(at: url)
} }
} }
try await group.waitForAll()
} }
} catch { } catch {
Logger.shared.log("Failed to clear tmp folder: \(error.localizedDescription)", type: "Error") Logger.shared.log("Failed to clear tmp folder: \(error.localizedDescription)", type: "Error")