diff --git a/Xcodes/Backend/AppState+Update.swift b/Xcodes/Backend/AppState+Update.swift index cd2952c9..c5588690 100644 --- a/Xcodes/Backend/AppState+Update.swift +++ b/Xcodes/Backend/AppState+Update.swift @@ -58,8 +58,12 @@ extension AppState { Current.defaults.setDate(Current.date(), forKey: "lastUpdated") } catch is CancellationError { } catch { - // Prevent setting the app state error if it is an invalid session, we will present the sign in view instead - if error as? AuthenticationError != .invalidSession { + if self.dataSource == .apple, Self.isUnauthorizedInstallError(error) || error as? AuthenticationError == .invalidSession { + // The Apple data source needs a developer session; ask the user to sign in rather than + // showing a raw 401. + self.presentedAlert = .unauthenticatedDataSource + } else if error as? AuthenticationError != .invalidSession { + // Prevent setting the app state error if it is an invalid session, we will present the sign in view instead self.error = error self.presentedAlert = .generic(title: localizeString("Alert.Update.Error.Title"), message: error.legibleLocalizedDescription) } diff --git a/Xcodes/Frontend/Common/XcodesAlert.swift b/Xcodes/Frontend/Common/XcodesAlert.swift index 710668f9..4a98c665 100644 --- a/Xcodes/Frontend/Common/XcodesAlert.swift +++ b/Xcodes/Frontend/Common/XcodesAlert.swift @@ -8,6 +8,7 @@ enum XcodesAlert: Identifiable { case generic(title: String, message: String) case checkMinSupportedVersion(xcode: AvailableXcode, macOS: String) case unauthenticated + case unauthenticatedDataSource var id: Int { switch self { @@ -17,6 +18,7 @@ enum XcodesAlert: Identifiable { case .checkMinSupportedVersion: return 4 case .cancelRuntimeInstall: return 5 case .unauthenticated: return 6 + case .unauthenticatedDataSource: return 7 } } } diff --git a/Xcodes/Frontend/MainWindow.swift b/Xcodes/Frontend/MainWindow.swift index b108f053..ece8fe81 100644 --- a/Xcodes/Frontend/MainWindow.swift +++ b/Xcodes/Frontend/MainWindow.swift @@ -204,6 +204,20 @@ struct MainWindow: View { Text("Cancel") ) ) + case .unauthenticatedDataSource: + return Alert( + title: Text("Alert.Update.AuthError.Title"), + message: Text("Alert.Update.AuthError.Message"), + primaryButton: .default( + Text("Login"), + action: { + appState.presentedSheet = .signIn + } + ), + secondaryButton: .cancel( + Text("Cancel") + ) + ) case let .checkMinSupportedVersion(xcode, deviceVersion): return Alert( title: Text("Alert.MinSupported.Title"), diff --git a/Xcodes/Resources/Localizable.xcstrings b/Xcodes/Resources/Localizable.xcstrings index 6608a149..fd4cbda1 100644 --- a/Xcodes/Resources/Localizable.xcstrings +++ b/Xcodes/Resources/Localizable.xcstrings @@ -4414,6 +4414,26 @@ } } }, + "Alert.Update.AuthError.Message" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "The Apple data source lists Xcode releases from your Apple Developer account, so it needs you to be signed in. Sign in to refresh the list, or switch the data source to Xcode Releases in Settings." + } + } + } + }, + "Alert.Update.AuthError.Title" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Sign in to refresh from Apple" + } + } + } + }, "Alert.Update.Error.Title" : { "comment" : "Update", "extractionState" : "manual",