Skip to content

Commit b72be1b

Browse files
fix: self-review dead code and alert binding fixes
- Remove unused @State currentSession in RetroAchievementsView - Simplify initializeClient: remove unnecessary nested Task inside MainActor.run - Remove dead moveTVOSBackup(from:) in BackupRestoreView (never called) - Fix .constant(errorMessage != nil) anti-pattern in BatchArtworkMatchingView with proper @State showErrorAlert so the alert can dismiss correctly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e9665a6 commit b72be1b

File tree

3 files changed

+14
-35
lines changed

3 files changed

+14
-35
lines changed

PVUI/Sources/PVSwiftUI/Settings/RetroAchievementsView.swift

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public struct RetroAchievementsView: View {
2121
@State private var loadingProgress: Double = 0
2222
@State private var errorMessage: String?
2323
@State private var showingError = false
24-
@State private var currentSession: RAUserSession?
2524
@State private var userProfile: RAUserProfile?
2625
@State private var isAuthenticated = false
2726

@@ -574,31 +573,21 @@ public struct RetroAchievementsView: View {
574573
}
575574
}
576575

576+
@MainActor
577577
private func initializeClient() async {
578578
// Create client and check for existing session
579579
client = PVCheevos.client()
580580

581-
await MainActor.run {
582-
// Check if already authenticated
583-
if let currentClient = client {
584-
Task {
585-
let authenticated = await currentClient.isAuthenticated
586-
587-
await MainActor.run {
588-
isAuthenticated = authenticated
589-
if authenticated {
590-
// Load stored profile or create basic one
591-
if let storedProfile = RetroCredentialsManager.shared.loadUserProfile() {
592-
userProfile = storedProfile
593-
}
594-
}
581+
guard let currentClient = client else { return }
595582

596-
// Load RetroArch settings
597-
loadRetroArchSettings()
598-
}
599-
}
583+
let authenticated = currentClient.isAuthenticated
584+
isAuthenticated = authenticated
585+
if authenticated {
586+
if let storedProfile = RetroCredentialsManager.shared.loadUserProfile() {
587+
userProfile = storedProfile
600588
}
601589
}
590+
loadRetroArchSettings()
602591
}
603592

604593
private func loadRetroArchSettings() {

PVUI/Sources/PVSwiftUI/Settings/Views/BackupRestoreView.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -358,21 +358,6 @@ struct BackupRestoreView: View {
358358
}
359359

360360
#if os(tvOS)
361-
private func moveTVOSBackup(from tempURL: URL) {
362-
let dest = URL.documentsPath.appendingPathComponent(tempURL.lastPathComponent)
363-
do {
364-
if FileManager.default.fileExists(atPath: dest.path) {
365-
try FileManager.default.removeItem(at: dest)
366-
}
367-
try FileManager.default.moveItem(at: tempURL, to: dest)
368-
alertMessage = "Backup saved to Documents: \(dest.lastPathComponent)"
369-
showAlert = true
370-
} catch {
371-
// State update handled via coordinator.backupState observer
372-
ELOG("BackupRestoreView: could not move tvOS backup: \(error)")
373-
}
374-
}
375-
376361
private func startTVOSRestore() {
377362
let docs = URL.documentsPath
378363
let fm = FileManager.default

PVUI/Sources/PVSwiftUI/Settings/Views/BatchArtworkMatchingView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public struct BatchArtworkMatchingView: View {
4949
@State private var searchProgress: Double = 0
5050
@State private var currentSearchTitle: String = ""
5151
@State private var errorMessage: String?
52+
@State private var showErrorAlert = false
5253

5354
// Game and artwork data
5455
@State private var gamesNeedingArtwork: [PVGame] = []
@@ -134,10 +135,11 @@ public struct BatchArtworkMatchingView: View {
134135
.uiKitAlert(
135136
"Error",
136137
message: errorMessage ?? "",
137-
isPresented: .constant(errorMessage != nil),
138+
isPresented: $showErrorAlert,
138139
preferredContentSize: CGSize(width: 500, height: 300)
139140
) {
140141
UIAlertAction(title: "OK", style: .default) { _ in
142+
showErrorAlert = false
141143
errorMessage = nil
142144
}
143145
}
@@ -513,6 +515,7 @@ public struct BatchArtworkMatchingView: View {
513515
} catch {
514516
ELOG("Error loading games: \(error)")
515517
errorMessage = "Error loading games: \(error.localizedDescription)"
518+
showErrorAlert = true
516519
}
517520
}
518521

@@ -582,6 +585,7 @@ public struct BatchArtworkMatchingView: View {
582585
} catch {
583586
ELOG("Error searching for artwork: \(error)")
584587
errorMessage = "Error searching for artwork: \(error.localizedDescription)"
588+
showErrorAlert = true
585589
if clearExisting {
586590
// Show partial failure info from an interrupted initial scan.
587591
failedGames = newFailures
@@ -671,6 +675,7 @@ public struct BatchArtworkMatchingView: View {
671675
} catch {
672676
ELOG("Error applying artwork: \(error)")
673677
errorMessage = "Error applying artwork: \(error.localizedDescription)"
678+
showErrorAlert = true
674679
}
675680
}
676681
}

0 commit comments

Comments
 (0)