mirror of
https://github.com/yattee/yattee.git
synced 2025-10-11 01:48:12 +00:00
more responsive UI when Favorites are used.
- The reloading of items in the favorite widgets is now done async, so it does not block the UI when opening Home. - Tasks that check for changes of the widget and favorites are now terminated when another view e.g. Subscriptions is opened. - We only update the Favourites when the player is not in the foreground, to avoid unresponsiveness.
This commit is contained in:
@@ -5,9 +5,11 @@ import UniformTypeIdentifiers
|
||||
|
||||
struct HomeView: View {
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
@ObservedObject private var player = PlayerModel.shared
|
||||
|
||||
@State private var presentingHomeSettings = false
|
||||
@State private var favoritesChanged = false
|
||||
@State private var updateTask: Task<Void, Never>?
|
||||
|
||||
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
||||
var watches: FetchedResults<Watch>
|
||||
@@ -16,8 +18,6 @@ struct HomeView: View {
|
||||
@State private var recentDocumentsID = UUID()
|
||||
#endif
|
||||
|
||||
var favoritesObserver: Any?
|
||||
|
||||
#if !os(tvOS)
|
||||
@Default(.favorites) private var favorites
|
||||
@Default(.widgetsSettings) private var widgetsSettings
|
||||
@@ -124,6 +124,24 @@ struct HomeView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
updateTask?.cancel()
|
||||
}
|
||||
|
||||
.onChange(of: player.presentingPlayer) { _ in
|
||||
if player.presentingPlayer {
|
||||
updateTask?.cancel()
|
||||
} else {
|
||||
Task {
|
||||
for await _ in Defaults.updates(.favorites) {
|
||||
favoritesChanged.toggle()
|
||||
}
|
||||
for await _ in Defaults.updates(.widgetsSettings) {
|
||||
favoritesChanged.toggle()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.redrawOn(change: favoritesChanged)
|
||||
|
||||
|
Reference in New Issue
Block a user