2
2
mirror of https://github.com/mastodon/mastodon-ios synced 2025-04-11 22:58:02 +02:00

Fully initialize AuthenticationServiceProvider from within init

contributes to iOS-319
This commit is contained in:
shannon 2024-11-19 11:30:01 -05:00
parent d96be97cf6
commit 082f5e6ce3
9 changed files with 12 additions and 19 deletions

View File

@ -250,8 +250,6 @@ extension SceneCoordinator {
func setup() {
let rootViewController: UIViewController
AuthenticationServiceProvider.shared.prepareForUse()
switch UIDevice.current.userInterfaceIdiom {
case .phone:
let viewController = MainTabBarController(context: appContext, coordinator: self, authenticationBox: authenticationBox)

View File

@ -17,7 +17,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var appContext: AppContext { return AppContext.shared }
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AuthenticationServiceProvider.shared.prepareForUse()
AppSecret.default.register()

View File

@ -12,7 +12,6 @@ class IntentHandler: INExtension {
@MainActor
override func handler(for intent: INIntent) -> Any {
AuthenticationServiceProvider.shared.prepareForUse()
switch intent {
case is SendPostIntent:

View File

@ -43,11 +43,7 @@ public class AuthenticationServiceProvider: ObservableObject {
$authentications
.map { authentications -> [MastodonAuthenticationBox] in
return authentications
.sorted(by: { $0.activedAt > $1.activedAt })
.compactMap { authentication -> MastodonAuthenticationBox? in
return MastodonAuthenticationBox(authentication: authentication)
}
return self.authenticationBoxes(authentications)
}
.assign(to: &$mastodonAuthenticationBoxes)
@ -60,6 +56,14 @@ public class AuthenticationServiceProvider: ObservableObject {
}
}
private func authenticationBoxes(_ authentications: [MastodonAuthentication]) -> [MastodonAuthenticationBox] {
return authentications
.sorted(by: { $0.activedAt > $1.activedAt })
.compactMap { authentication -> MastodonAuthenticationBox? in
return MastodonAuthenticationBox(authentication: authentication)
}
}
@Published private var authentications: [MastodonAuthentication] = [] {
didSet {
persist(authentications)
@ -156,10 +160,12 @@ public extension AuthenticationServiceProvider {
}
@MainActor
func prepareForUse() {
private func prepareForUse() {
if authentications.isEmpty {
restoreFromKeychain()
}
mastodonAuthenticationBoxes = authenticationBoxes(authentications)
currentActiveUser.send(mastodonAuthenticationBoxes.first)
}
@MainActor

View File

@ -160,7 +160,6 @@ extension ShareViewController {
extension ShareViewController {
private func setupAuthContext() throws -> MastodonAuthenticationBox? {
AuthenticationServiceProvider.shared.prepareForUse()
return AuthenticationServiceProvider.shared.currentActiveUser.value
}

View File

@ -73,8 +73,6 @@ private extension FollowersCountWidgetProvider {
func loadCurrentEntry(for configuration: FollowersCountIntent, in context: Context, completion: @escaping (FollowersCountEntry) -> Void) {
Task { @MainActor in
AuthenticationServiceProvider.shared.prepareForUse()
guard
let authBox = AuthenticationServiceProvider.shared.currentActiveUser.value
else {

View File

@ -28,8 +28,6 @@ extension HashtagWidgetProvider {
Task {
await MainActor.run {
AuthenticationServiceProvider.shared.prepareForUse()
guard
let authBox = AuthenticationServiceProvider.shared.currentActiveUser.value
else {

View File

@ -80,8 +80,6 @@ private extension LatestFollowersWidgetProvider {
func loadCurrentEntry(for configuration: LatestFollowersIntent, in context: Context, completion: @escaping (LatestFollowersEntry) -> Void) {
Task { @MainActor in
AuthenticationServiceProvider.shared.prepareForUse()
guard
let authBox = AuthenticationServiceProvider.shared.currentActiveUser.value
else {

View File

@ -72,8 +72,6 @@ struct MultiFollowersCountWidget: Widget {
private extension MultiFollowersCountWidgetProvider {
func loadCurrentEntry(for configuration: MultiFollowersCountIntent, in context: Context, completion: @escaping (MultiFollowersCountEntry) -> Void) {
Task { @MainActor in
AuthenticationServiceProvider.shared.prepareForUse()
guard
let authBox = AuthenticationServiceProvider.shared.currentActiveUser.value