From eaa019caa305cfc6eb6a25b1d2c9c5a5ab9646ce Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 20 Mar 2022 21:31:19 +0100 Subject: [PATCH] Add toggle for dislikes --- Model/Player/PlayerModel.swift | 4 ++++ Shared/Defaults.swift | 2 ++ Shared/Settings/PlayerSettings.swift | 7 +++++++ Shared/Settings/SettingsView.swift | 2 +- Shared/Views/MPVPlayerView.swift | 4 ++-- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 6b0bb320..1579257d 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -226,6 +226,10 @@ final class PlayerModel: ObservableObject { } } + guard Defaults[.enableReturnYouTubeDislike] else { + return + } + self?.returnYouTubeDislike.loadDislikes(videoID: video.videoID) { [weak self] dislikes in self?.currentItem?.video?.dislikes = dislikes } diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index 6c312459..7ca9eb85 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -23,6 +23,8 @@ extension Defaults.Keys { static let sponsorBlockInstance = Key("sponsorBlockInstance", default: "https://sponsor.ajay.app") static let sponsorBlockCategories = Key>("sponsorBlockCategories", default: Set(SponsorBlockAPI.categories)) + static let enableReturnYouTubeDislike = Key("enableReturnYouTubeDislike", default: false) + static let favorites = Key<[FavoriteItem]>("favorites", default: [ .init(section: .trending("US", "default")), .init(section: .trending("GB", "default")), diff --git a/Shared/Settings/PlayerSettings.swift b/Shared/Settings/PlayerSettings.swift index 54faaf90..89cf5f19 100644 --- a/Shared/Settings/PlayerSettings.swift +++ b/Shared/Settings/PlayerSettings.swift @@ -27,6 +27,8 @@ struct PlayerSettings: View { @Default(.closePiPAndOpenPlayerOnEnteringForeground) private var closePiPAndOpenPlayerOnEnteringForeground #endif + @Default(.enableReturnYouTubeDislike) private var enableReturnYouTubeDislike + #if os(iOS) private var idiom: UIUserInterfaceIdiom { UIDevice.current.userInterfaceIdiom @@ -82,6 +84,7 @@ struct PlayerSettings: View { keywordsToggle showHistoryToggle + returnYouTubeDislikeToggle } Section(header: SettingsHeader(text: "Picture in Picture")) { @@ -194,6 +197,10 @@ struct PlayerSettings: View { Toggle("Show history", isOn: $showHistory) } + private var returnYouTubeDislikeToggle: some View { + Toggle("Enable Return YouTube Dislike", isOn: $enableReturnYouTubeDislike) + } + private var pauseOnHidingPlayerToggle: some View { Toggle("Pause when player is closed", isOn: $pauseOnHidingPlayer) } diff --git a/Shared/Settings/SettingsView.swift b/Shared/Settings/SettingsView.swift index 5a792192..c6f2fd97 100644 --- a/Shared/Settings/SettingsView.swift +++ b/Shared/Settings/SettingsView.swift @@ -179,7 +179,7 @@ struct SettingsView: View { case .browsing: return 350 case .player: - return 450 + return 470 case .history: return 480 case .sponsorBlock: diff --git a/Shared/Views/MPVPlayerView.swift b/Shared/Views/MPVPlayerView.swift index 521fe47b..fd5cdab5 100644 --- a/Shared/Views/MPVPlayerView.swift +++ b/Shared/Views/MPVPlayerView.swift @@ -23,6 +23,8 @@ import SwiftUI @EnvironmentObject private var player func makeNSView(context _: Context) -> some NSView { + player.mpvBackend.client = client + client.layer = layer layer.client = client @@ -31,8 +33,6 @@ import SwiftUI view.layer = client.layer view.wantsLayer = true - player.mpvBackend.client = client - return view }