mirror of
				https://github.com/yattee/yattee.git
				synced 2025-10-31 12:41:57 +00:00 
			
		
		
		
	fix some potential crashes
Signed-off-by: Toni Förster <toni.foerster@gmail.com>
This commit is contained in:
		| @@ -3,7 +3,7 @@ import Foundation | |||||||
|  |  | ||||||
| final class MenuModel: ObservableObject { | final class MenuModel: ObservableObject { | ||||||
|     static let shared = MenuModel() |     static let shared = MenuModel() | ||||||
|     private var cancellables = [AnyCancellable]() |     private var cancellables = Set<AnyCancellable>() | ||||||
|  |  | ||||||
|     init() { |     init() { | ||||||
|         registerChildModel(AccountsModel.shared) |         registerChildModel(AccountsModel.shared) | ||||||
| @@ -12,10 +12,16 @@ final class MenuModel: ObservableObject { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     func registerChildModel<T: ObservableObject>(_ model: T?) { |     func registerChildModel<T: ObservableObject>(_ model: T?) { | ||||||
|         guard !model.isNil else { |         guard let model else { | ||||||
|             return |             return | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         cancellables.append(model!.objectWillChange.sink { [weak self] _ in self?.objectWillChange.send() }) |         model.objectWillChange | ||||||
|  |             .receive(on: DispatchQueue.main) // Ensure the update occurs on the main thread | ||||||
|  |             .debounce(for: .milliseconds(10), scheduler: DispatchQueue.main) // Debounce to avoid immediate feedback loops | ||||||
|  |             .sink { [weak self] _ in | ||||||
|  |                 self?.objectWillChange.send() | ||||||
|  |             } | ||||||
|  |             .store(in: &cancellables) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -191,7 +191,7 @@ struct YatteeApp: App { | |||||||
|  |  | ||||||
|             NavigationModel.shared.tabSelection = section ?? .search |             NavigationModel.shared.tabSelection = section ?? .search | ||||||
|  |  | ||||||
|             DispatchQueue.global(qos: .userInitiated).async { |             DispatchQueue.main.async { | ||||||
|                 playlists.load() |                 playlists.load() | ||||||
|             } |             } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Toni Förster
					Toni Förster