1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-11 15:53:59 +00:00

refactor: improve sudo error handling to distinguish authentication failures and adjust scene view rotation speed.

This commit is contained in:
Tw93
2025-12-15 15:09:40 +08:00
parent 4547f5819e
commit 4c18957aae
4 changed files with 55 additions and 11 deletions

View File

@@ -24,11 +24,30 @@ class OptimizerService: ObservableObject {
_ = try await ShellRunner.shared.runSudo(command, password: pw)
return
} catch {
await MainActor.run { AuthContext.shared.clear() }
print("Optimizer privilege error: \(error)")
// Only clear password if it's an authentication failure
if case ShellError.authenticationFailed = error {
await MainActor.run { AuthContext.shared.clear() }
await MainActor.run {
AuthContext.shared.needsPassword = true
self.statusMessage = "Password Incorrect"
}
struct AuthRequired: Error, LocalizedError {
var errorDescription: String? { "Authentication Failed" }
}
throw AuthRequired()
} else {
// Command failed but password likely correct.
// Do NOT clear password. Propagate error.
print("Non-auth error in optimizer: \(error)")
throw error
}
}
}
// If no password or failed, prompt via Custom Sheet
// If no password, prompt via Custom Sheet
await MainActor.run {
AuthContext.shared.needsPassword = true
self.statusMessage = "Waiting for Password..."