From 02617a7c42fda04059f3f24e3c78875db1cccae3 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Thu, 1 Sep 2022 19:00:56 +0200 Subject: [PATCH] Shared seek model --- Model/SeekModel.swift | 2 ++ Shared/Navigation/ContentView.swift | 3 ++- Shared/Player/Controls/OSD/Seek.swift | 2 +- Shared/Player/VideoPlayerView.swift | 1 - Shared/YatteeApp.swift | 4 +--- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Model/SeekModel.swift b/Model/SeekModel.swift index 852c81b7..7561f4cf 100644 --- a/Model/SeekModel.swift +++ b/Model/SeekModel.swift @@ -3,6 +3,8 @@ import Foundation import SwiftUI final class SeekModel: ObservableObject { + static let shared = SeekModel() + @Published var currentTime = CMTime.zero @Published var duration = CMTime.zero diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index 427ed7aa..37785054 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -12,7 +12,6 @@ struct ContentView: View { @EnvironmentObject private var comments @EnvironmentObject private var instances @EnvironmentObject private var navigation - @EnvironmentObject private var player @EnvironmentObject private var playerControls @EnvironmentObject private var playlists @EnvironmentObject private var recents @@ -29,6 +28,8 @@ struct ContentView: View { @State private var playerInitialized = false + private var player = PlayerModel.shared + let persistenceController = PersistenceController.shared var body: some View { diff --git a/Shared/Player/Controls/OSD/Seek.swift b/Shared/Player/Controls/OSD/Seek.swift index cbd16f7d..67333496 100644 --- a/Shared/Player/Controls/OSD/Seek.swift +++ b/Shared/Player/Controls/OSD/Seek.swift @@ -7,7 +7,7 @@ struct Seek: View { #endif @EnvironmentObject private var controls - @EnvironmentObject private var model + @StateObject private var model = SeekModel.shared private var updateThrottle = Throttle(interval: 2) diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index 99f30e04..c40dbd35 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -461,7 +461,6 @@ struct VideoPlayerView: View { struct VideoPlayerView_Previews: PreviewProvider { static var previews: some View { VideoPlayerView() - .environmentObject(SeekModel()) .injectFixtureEnvironmentObjects() } } diff --git a/Shared/YatteeApp.swift b/Shared/YatteeApp.swift index 52bffeb0..825d1c65 100644 --- a/Shared/YatteeApp.swift +++ b/Shared/YatteeApp.swift @@ -43,7 +43,6 @@ struct YatteeApp: App { @StateObject private var playlists = PlaylistsModel() @StateObject private var recents = RecentsModel() @StateObject private var search = SearchModel() - @StateObject private var seek = SeekModel() @StateObject private var settings = SettingsModel() @StateObject private var subscriptions = SubscriptionsModel() @StateObject private var thumbnails = ThumbnailsModel() @@ -64,7 +63,6 @@ struct YatteeApp: App { .environmentObject(playerControls) .environmentObject(playlists) .environmentObject(recents) - .environmentObject(seek) .environmentObject(settings) .environmentObject(subscriptions) .environmentObject(thumbnails) @@ -204,7 +202,7 @@ struct YatteeApp: App { player.controls = playerControls player.navigation = navigation player.networkState = networkState - player.seek = seek + player.seek = .shared PlayerTimeModel.shared.player = player