diff --git a/Extensions/Notification+Names.swift b/Extensions/Notification+Names.swift new file mode 100644 index 00000000..35a4945b --- /dev/null +++ b/Extensions/Notification+Names.swift @@ -0,0 +1,5 @@ +import Foundation + +extension Notification.Name { + static let accountConfigurationComplete = Notification.Name("accountConfigurationComplete") +} diff --git a/Model/Applications/InvidiousAPI.swift b/Model/Applications/InvidiousAPI.swift index f8922275..710123b6 100644 --- a/Model/Applications/InvidiousAPI.swift +++ b/Model/Applications/InvidiousAPI.swift @@ -152,6 +152,10 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { FeedModel.shared.onAccountChange() SubscribedChannelsModel.shared.onAccountChange() PlaylistsModel.shared.onAccountChange() + + DispatchQueue.main.async { + NotificationCenter.default.post(name: .accountConfigurationComplete, object: nil) + } } } @@ -160,6 +164,9 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { guard !account.anonymous, (account.token?.isEmpty ?? true) || force else { + DispatchQueue.main.async { + NotificationCenter.default.post(name: .accountConfigurationComplete, object: nil) + } return } @@ -172,6 +179,9 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { title: "Account Error", message: "Remove and add your account again in Settings." ) + DispatchQueue.main.async { + NotificationCenter.default.post(name: .accountConfigurationComplete, object: nil) + } return } @@ -212,6 +222,8 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { } self.configure() + + NotificationCenter.default.post(name: .accountConfigurationComplete, object: nil) } } diff --git a/Model/Applications/PeerTubeAPI.swift b/Model/Applications/PeerTubeAPI.swift index e45085f7..831f05d6 100644 --- a/Model/Applications/PeerTubeAPI.swift +++ b/Model/Applications/PeerTubeAPI.swift @@ -174,6 +174,9 @@ final class PeerTubeAPI: Service, ObservableObject, VideosAPI { guard !account.anonymous, (account.token?.isEmpty ?? true) || force else { + DispatchQueue.main.async { + NotificationCenter.default.post(name: .accountConfigurationComplete, object: nil) + } return } @@ -186,6 +189,9 @@ final class PeerTubeAPI: Service, ObservableObject, VideosAPI { title: "Account Error", message: "Remove and add your account again in Settings." ) + DispatchQueue.main.async { + NotificationCenter.default.post(name: .accountConfigurationComplete, object: nil) + } return } @@ -194,6 +200,7 @@ final class PeerTubeAPI: Service, ObservableObject, VideosAPI { title: "Account Error", message: message ?? "\(response?.response?.statusCode ?? -1) - \(response?.error?.errorDescription ?? "unknown")\nIf this issue persists, try removing and adding your account again in Settings." ) + NotificationCenter.default.post(name: .accountConfigurationComplete, object: nil) } AF @@ -226,6 +233,8 @@ final class PeerTubeAPI: Service, ObservableObject, VideosAPI { } self.configure() + + NotificationCenter.default.post(name: .accountConfigurationComplete, object: nil) } } diff --git a/Model/Applications/PipedAPI.swift b/Model/Applications/PipedAPI.swift index 61cc3612..d9f8cd52 100644 --- a/Model/Applications/PipedAPI.swift +++ b/Model/Applications/PipedAPI.swift @@ -135,6 +135,10 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { FeedModel.shared.onAccountChange() SubscribedChannelsModel.shared.onAccountChange() PlaylistsModel.shared.onAccountChange() + + DispatchQueue.main.async { + NotificationCenter.default.post(name: .accountConfigurationComplete, object: nil) + } } } @@ -149,6 +153,9 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { let username, let password else { + DispatchQueue.main.async { + NotificationCenter.default.post(name: .accountConfigurationComplete, object: nil) + } return } @@ -184,11 +191,14 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { self.configure() + NotificationCenter.default.post(name: .accountConfigurationComplete, object: nil) + case let .failure(error): NavigationModel.shared.presentAlert( title: "Account Error", message: error.localizedDescription ) + NotificationCenter.default.post(name: .accountConfigurationComplete, object: nil) } } } diff --git a/Shared/YatteeApp.swift b/Shared/YatteeApp.swift index a072d909..7cf23dbf 100644 --- a/Shared/YatteeApp.swift +++ b/Shared/YatteeApp.swift @@ -162,6 +162,23 @@ struct YatteeApp: App { SDWebImageManager.defaultImageCache = PINCache(name: "stream.yattee.app") + NotificationCenter.default.addObserver( + forName: .accountConfigurationComplete, + object: nil, + queue: .main + ) { _ in + let startupSection = Defaults[.startupSection] + var section: TabSelection? = startupSection.tabSelection + + #if os(macOS) + if section == .playlists { + section = .search + } + #endif + + NavigationModel.shared.tabSelection = section ?? .search + } + if !Defaults[.lastAccountIsPublic] { AccountsModel.shared.configureAccount() } @@ -180,17 +197,6 @@ struct YatteeApp: App { } } - let startupSection = Defaults[.startupSection] - var section: TabSelection? = startupSection.tabSelection - - #if os(macOS) - if section == .playlists { - section = .search - } - #endif - - NavigationModel.shared.tabSelection = section ?? .search - DispatchQueue.main.async { playlists.load() } diff --git a/Yattee.xcodeproj/project.pbxproj b/Yattee.xcodeproj/project.pbxproj index 6cd65abb..0bca0ab2 100644 --- a/Yattee.xcodeproj/project.pbxproj +++ b/Yattee.xcodeproj/project.pbxproj @@ -207,6 +207,9 @@ 37319F0627103F94004ECCD0 /* PlayerQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37319F0427103F94004ECCD0 /* PlayerQueue.swift */; }; 37319F0727103F94004ECCD0 /* PlayerQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37319F0427103F94004ECCD0 /* PlayerQueue.swift */; }; 3732BFD028B83763009F3F4D /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = 3732BFCF28B83763009F3F4D /* KeychainAccess */; }; + 3736882B2ECE7947006B1D1F /* Notification+Names.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3736882A2ECE7947006B1D1F /* Notification+Names.swift */; }; + 3736882C2ECE7947006B1D1F /* Notification+Names.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3736882A2ECE7947006B1D1F /* Notification+Names.swift */; }; + 3736882D2ECE7947006B1D1F /* Notification+Names.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3736882A2ECE7947006B1D1F /* Notification+Names.swift */; }; 3738535429451DC800D2D0CB /* BookmarksCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3738535329451DC800D2D0CB /* BookmarksCacheModel.swift */; }; 3738535529451DC800D2D0CB /* BookmarksCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3738535329451DC800D2D0CB /* BookmarksCacheModel.swift */; }; 3738535629451DC800D2D0CB /* BookmarksCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3738535329451DC800D2D0CB /* BookmarksCacheModel.swift */; }; @@ -1215,6 +1218,7 @@ 373197D82732015300EF734F /* RelatedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelatedView.swift; sourceTree = ""; }; 37319F0427103F94004ECCD0 /* PlayerQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerQueue.swift; sourceTree = ""; }; 37367E582B8F63C200436163 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = ""; }; + 3736882A2ECE7947006B1D1F /* Notification+Names.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Notification+Names.swift"; sourceTree = ""; }; 3738535329451DC800D2D0CB /* BookmarksCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksCacheModel.swift; sourceTree = ""; }; 373C8FE3275B955100CB5936 /* CommentsPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentsPage.swift; sourceTree = ""; }; 373CFACA26966264003CB2C6 /* SearchQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchQuery.swift; sourceTree = ""; }; @@ -2240,6 +2244,7 @@ 37C7A9022679058300E721B4 /* Extensions */ = { isa = PBXGroup; children = ( + 3736882A2ECE7947006B1D1F /* Notification+Names.swift */, 379775922689365600DD52A8 /* Array+Next.swift */, 37DCD3162A191A180059A470 /* AVPlayerViewController+FullScreen.swift */, 376578842685429C00D4EA09 /* CaseIterable+Next.swift */, @@ -3297,6 +3302,7 @@ 37BA794F26DC3E0E002A0235 /* Int+Format.swift in Sources */, 378E9C3C2945565500B2D696 /* SubscriptionsView.swift in Sources */, 37D6025928C17375009E8D98 /* PlaybackStatsView.swift in Sources */, + 3736882D2ECE7947006B1D1F /* Notification+Names.swift in Sources */, 37F49BA326CAA59B00304AC0 /* Playlist+Fixtures.swift in Sources */, 374C053B2724614F009BDDBE /* PlayerTVMenu.swift in Sources */, 37A9965A26D6F8CA006E3224 /* HorizontalCells.swift in Sources */, @@ -3644,6 +3650,7 @@ 37A81BFA294BD1440081D322 /* WatchView.swift in Sources */, 3700155C271B0D4D0049C794 /* PipedAPI.swift in Sources */, 376BE50C27349108009AD608 /* BrowsingSettings.swift in Sources */, + 3736882C2ECE7947006B1D1F /* Notification+Names.swift in Sources */, 3710A55629488C7D006F8025 /* PlaceholderListItem.swift in Sources */, 37EBD8CB27AF26C200F1C24B /* MPVBackend.swift in Sources */, 37D4B19826717E1500C925CA /* Video.swift in Sources */, @@ -3942,6 +3949,7 @@ 37C7A1D7267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */, 3756C2A82861131100E4B059 /* NetworkState.swift in Sources */, 376578932685490700D4EA09 /* PlaylistsView.swift in Sources */, + 3736882B2ECE7947006B1D1F /* Notification+Names.swift in Sources */, 37E75CCD2B6AEB01003A6237 /* RecentlyOpenedExporter.swift in Sources */, 377FF891291A99580028EB0B /* HistoryView.swift in Sources */, 37CC3F47270CE30600608308 /* PlayerQueueItem.swift in Sources */,