Remove unused code, minor style changes

This commit is contained in:
Arkadiusz Fal 2021-12-20 00:36:12 +01:00
parent 0a5cb5b542
commit ea90f650d8
27 changed files with 74 additions and 114 deletions

View File

@ -3,12 +3,10 @@ import SwiftUI
extension Color {
#if os(macOS)
static let background = Color(NSColor.windowBackgroundColor)
static let secondaryBackground = Color(NSColor.underPageBackgroundColor)
static let tertiaryBackground = Color(NSColor.controlBackgroundColor)
static let secondaryBackground = Color(NSColor.controlBackgroundColor)
#elseif os(iOS)
static let background = Color(UIColor.systemBackground)
static let secondaryBackground = Color(UIColor.secondarySystemBackground)
static let tertiaryBackground = Color(UIColor.tertiarySystemBackground)
#else
static func background(scheme: ColorScheme) -> Color {
scheme == .dark ? .black : .init(white: 0.8)

View File

@ -8,10 +8,6 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
@Published var account: Account!
var anonymousAccount: Account {
.init(instanceID: account.instance.id, name: "Anonymous", url: account.instance.apiURL)
}
init(account: Account? = nil) {
super.init()

View File

@ -16,7 +16,6 @@ final class CommentsModel: ObservableObject {
@Published var repliesPageID: String?
@Published var repliesLoaded = false
var accounts: AccountsModel!
var player: PlayerModel!
static var instance: Instance? {

View File

@ -74,7 +74,7 @@ final class NavigationModel: ObservableObject {
var tabSelectionBinding: Binding<TabSelection> {
Binding<TabSelection>(
get: {
self.tabSelection ?? .favorites
self.tabSelection ?? .search
},
set: { newValue in
self.tabSelection = newValue

View File

@ -685,46 +685,47 @@ final class PlayerModel: ObservableObject {
#if os(tvOS)
show()
closePipByReplacingItem(wasPlaying: wasPlaying)
#else
closePiPByNilingPlayer(wasPlaying: wasPlaying)
#endif
doClosePiP(wasPlaying: wasPlaying)
}
private func closePipByReplacingItem(wasPlaying: Bool) {
let item = player.currentItem
let time = player.currentTime()
#if os(tvOS)
private func doClosePiP(wasPlaying: Bool) {
let item = player.currentItem
let time = player.currentTime()
self.player.replaceCurrentItem(with: nil)
self.player.replaceCurrentItem(with: nil)
guard !item.isNil else {
return
guard !item.isNil else {
return
}
self.player.seek(to: time)
self.player.replaceCurrentItem(with: item)
guard wasPlaying else {
return
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
self?.play()
}
}
#else
private func doClosePiP(wasPlaying: Bool) {
controller?.playerView.player = nil
controller?.playerView.player = player
self.player.seek(to: time)
self.player.replaceCurrentItem(with: item)
guard wasPlaying else {
return
}
guard wasPlaying else {
return
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
self?.play()
}
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
self?.play()
}
}
private func closePiPByNilingPlayer(wasPlaying: Bool) {
controller?.playerView.player = nil
controller?.playerView.player = player
guard wasPlaying else {
return
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
self?.play()
}
}
#endif
#if os(macOS)
var windowTitle: String {

View File

@ -107,10 +107,6 @@ enum PlayerSidebarSetting: String, CaseIterable, Defaults.Serializable {
enum VisibleSection: String, CaseIterable, Comparable, Defaults.Serializable {
case favorites, subscriptions, popular, trending, playlists
static func from(_ string: String) -> VisibleSection {
allCases.first { $0.rawValue == string }!
}
var title: String {
rawValue.localizedCapitalized
}

View File

@ -51,7 +51,7 @@ struct FavoritesView: View {
.navigationTitle("Favorites")
#endif
#if os(macOS)
.background(Color.tertiaryBackground)
.background(Color.secondaryBackground)
.frame(minWidth: 360)
#endif
}

View File

@ -6,20 +6,19 @@ import SwiftUI
struct AppSidebarNavigation: View {
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<CommentsModel> private var comments
@EnvironmentObject<InstancesModel> private var instances
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<PlaylistsModel> private var playlists
@EnvironmentObject<RecentsModel> private var recents
@EnvironmentObject<SearchModel> private var search
@EnvironmentObject<SubscriptionsModel> private var subscriptions
@EnvironmentObject<ThumbnailsModel> private var thumbnailsModel
@Default(.visibleSections) private var visibleSections
#if os(iOS)
@State private var didApplyPrimaryViewWorkAround = false
@EnvironmentObject<CommentsModel> private var comments
@EnvironmentObject<InstancesModel> private var instances
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<PlaylistsModel> private var playlists
@EnvironmentObject<RecentsModel> private var recents
@EnvironmentObject<SearchModel> private var search
@EnvironmentObject<SubscriptionsModel> private var subscriptions
@EnvironmentObject<ThumbnailsModel> private var thumbnailsModel
#endif
var body: some View {
@ -66,26 +65,22 @@ struct AppSidebarNavigation: View {
#if os(iOS)
.background(
EmptyView().fullScreenCover(isPresented: $player.presentingPlayer) {
videoPlayer
VideoPlayerView()
.environmentObject(accounts)
.environmentObject(comments)
.environmentObject(instances)
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(playlists)
.environmentObject(recents)
.environmentObject(subscriptions)
.environmentObject(thumbnailsModel)
.environment(\.navigationStyle, .sidebar)
}
)
#endif
}
private var videoPlayer: some View {
VideoPlayerView()
.environmentObject(accounts)
.environmentObject(comments)
.environmentObject(instances)
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(playlists)
.environmentObject(recents)
.environmentObject(subscriptions)
.environmentObject(thumbnailsModel)
}
var toolbarContent: some ToolbarContent {
Group {
#if os(iOS)

View File

@ -123,7 +123,6 @@ struct ContentView: View {
search.accounts = accounts
subscriptions.accounts = accounts
comments.accounts = accounts
comments.player = player
menu.accounts = accounts

View File

@ -4,8 +4,6 @@ import SwiftUI
struct Sidebar: View {
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<PlaylistsModel> private var playlists
@EnvironmentObject<SubscriptionsModel> private var subscriptions
@Default(.visibleSections) private var visibleSections

View File

@ -4,7 +4,6 @@ struct CommentsView: View {
@State private var repliesID: Comment.ID?
@EnvironmentObject<CommentsModel> private var comments
@EnvironmentObject<PlayerModel> private var player
var body: some View {
Group {

View File

@ -14,7 +14,7 @@ struct VideoPlayerView: View {
}
@State private var playerSize: CGSize = .zero
@State private var fullScreen = false
@State private var fullScreenDetails = false
@Environment(\.colorScheme) private var colorScheme
@ -95,15 +95,15 @@ struct VideoPlayerView: View {
Group {
#if os(iOS)
if verticalSizeClass == .regular {
VideoDetails(sidebarQueue: sidebarQueueBinding, fullScreen: $fullScreen)
VideoDetails(sidebarQueue: sidebarQueueBinding, fullScreen: $fullScreenDetails)
}
#else
VideoDetails(sidebarQueue: sidebarQueueBinding, fullScreen: $fullScreen)
VideoDetails(sidebarQueue: sidebarQueueBinding, fullScreen: $fullScreenDetails)
#endif
}
.background(colorScheme == .dark ? Color.black : Color.white)
.modifier(VideoDetailsPaddingModifier(geometry: geometry, aspectRatio: player.controller?.aspectRatio, fullScreen: fullScreen))
.modifier(VideoDetailsPaddingModifier(geometry: geometry, aspectRatio: player.controller?.aspectRatio, fullScreen: fullScreenDetails))
}
#endif
}
@ -113,12 +113,12 @@ struct VideoPlayerView: View {
#endif
#if os(iOS)
if sidebarQueue {
PlayerQueueView(sidebarQueue: .constant(true), fullScreen: $fullScreen)
PlayerQueueView(sidebarQueue: .constant(true), fullScreen: $fullScreenDetails)
.frame(maxWidth: 350)
}
#elseif os(macOS)
if Defaults[.playerSidebar] != .never {
PlayerQueueView(sidebarQueue: sidebarQueueBinding, fullScreen: $fullScreen)
PlayerQueueView(sidebarQueue: sidebarQueueBinding, fullScreen: $fullScreenDetails)
.frame(minWidth: 300)
}
#endif

View File

@ -179,7 +179,7 @@ struct PlaylistsView: View {
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
#if os(macOS)
.background(Color.tertiaryBackground)
.background(Color.secondaryBackground)
#endif
}

View File

@ -8,9 +8,6 @@ struct InstanceSettings: View {
@State private var frontendURL = ""
@EnvironmentObject<AccountsModel> private var model
@EnvironmentObject<InstancesModel> private var instances
var instance: Instance! {
InstancesModel.find(instanceID)
}

View File

@ -8,7 +8,6 @@ struct PlaybackSettings: View {
@Default(.playerSidebar) private var playerSidebar
@Default(.showKeywords) private var showKeywords
@Default(.showChannelSubscribers) private var channelSubscribers
@Default(.saveHistory) private var saveHistory
@Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer
@Default(.closePiPOnNavigation) private var closePiPOnNavigation
@Default(.closePiPOnOpeningPlayer) private var closePiPOnOpeningPlayer

View File

@ -19,7 +19,7 @@ struct VerticalCells: View {
}
.edgesIgnoringSafeArea(.horizontal)
#if os(macOS)
.background(Color.tertiaryBackground)
.background(Color.secondaryBackground)
.frame(minWidth: 360)
#endif
}

View File

@ -62,7 +62,7 @@ struct VideoCell: View {
#endif
}
#if os(macOS)
.background(Color.tertiaryBackground)
.background(Color.secondaryBackground)
#endif
}

View File

@ -13,10 +13,10 @@ struct ChannelPlaylistView: View {
#if os(iOS)
@Environment(\.inNavigationView) private var inNavigationView
@EnvironmentObject<PlayerModel> private var player
#endif
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<PlayerModel> private var player
var items: [ContentItem] {
ContentItem.array(of: store.item?.videos ?? [])

View File

@ -10,16 +10,15 @@ struct ChannelVideosView: View {
@StateObject private var store = Store<Channel>()
@Environment(\.colorScheme) private var colorScheme
@Environment(\.presentationMode) private var presentationMode
@Environment(\.inNavigationView) private var inNavigationView
#if os(iOS)
@Environment(\.inNavigationView) private var inNavigationView
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
@EnvironmentObject<PlayerModel> private var player
#endif
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<SubscriptionsModel> private var subscriptions
@Namespace private var focusNamespace

View File

@ -3,6 +3,7 @@ import SwiftUI
struct LazyView<Content: View>: View {
let build: () -> Content
init(_ build: @autoclosure @escaping () -> Content) {
self.build = build
}

View File

@ -116,7 +116,7 @@ struct PlayerControlsView<Content: View>: View {
} else {
controls
#if !os(tvOS)
.background(Color.tertiaryBackground)
.background(Color.secondaryBackground)
#endif
}
}

View File

@ -80,14 +80,6 @@ struct VideoContextMenuView: View {
}
}
private var isShowingChannelButton: Bool {
if case .channel = navigation.tabSelection {
return false
}
return !inChannelView
}
private var addToQueueButton: some View {
Button {
player.enqueueVideo(video)

View File

@ -22,7 +22,7 @@
isa = PBXAggregateTarget;
buildConfigurationList = 37FD43E72704A2240073EE42 /* Build configuration list for PBXAggregateTarget "Periphery (macOS)" */;
buildPhases = (
37FD43EA2704A2350073EE42 /* ShellScript */,
37FD43EA2704A2350073EE42 /* Run Script */,
);
dependencies = (
);
@ -369,7 +369,6 @@
37B81B0326D2CAE700675966 /* PlaybackBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37B81B0126D2CAE700675966 /* PlaybackBar.swift */; };
37BA793B26DB8EE4002A0235 /* PlaylistVideosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BA793A26DB8EE4002A0235 /* PlaylistVideosView.swift */; };
37BA793C26DB8EE4002A0235 /* PlaylistVideosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BA793A26DB8EE4002A0235 /* PlaylistVideosView.swift */; };
37BA793D26DB8EE4002A0235 /* PlaylistVideosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BA793A26DB8EE4002A0235 /* PlaylistVideosView.swift */; };
37BA793F26DB8F97002A0235 /* ChannelVideosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BA793E26DB8F97002A0235 /* ChannelVideosView.swift */; };
37BA794026DB8F97002A0235 /* ChannelVideosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BA793E26DB8F97002A0235 /* ChannelVideosView.swift */; };
37BA794126DB8F97002A0235 /* ChannelVideosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BA793E26DB8F97002A0235 /* ChannelVideosView.swift */; };
@ -1668,7 +1667,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if test -d \"/opt/homebrew/bin/\"; then\n PATH=\"/opt/homebrew/bin/:${PATH}\"\nfi\n\nperiphery scan \\\n --project \"Yattee.xcodeproj\" \\\n --schemes \"Yattee (iOS)\" \\\n --targets \"Yattee (iOS)\" \\\n --retain-objc-accessible \\\n --retain-public \\\n -- -destination \"platform=iOS\\ Simulator,name=iPhone\\ 8,OS=15.0\"\n";
shellScript = "if test -d \"/opt/homebrew/bin/\"; then\n PATH=\"/opt/homebrew/bin/:${PATH}\"\nfi\n\nperiphery scan \\\n --project \"Yattee.xcodeproj\" \\\n --schemes \"Yattee (iOS)\" \\\n --targets \"Yattee (iOS)\" \\\n --retain-objc-accessible \\\n --retain-public \\\n -- -destination \"platform=iOS\\ Simulator,name=iPhone\\ 8,OS=14.5\"\n";
};
37CC3F48270CE89B00608308 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
@ -1721,7 +1720,7 @@
shellPath = /bin/sh;
shellScript = "if test -d \"/opt/homebrew/bin/\"; then\n PATH=\"/opt/homebrew/bin/:${PATH}\"\nfi\n\nexport PATH\n\nif which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
37FD43EA2704A2350073EE42 /* ShellScript */ = {
37FD43EA2704A2350073EE42 /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
@ -1730,6 +1729,7 @@
);
inputPaths = (
);
name = "Run Script";
outputFileListPaths = (
);
outputPaths = (
@ -2231,7 +2231,6 @@
37FB2860272225E800A57617 /* ContentItemView.swift in Sources */,
374C053727242D9F009BDDBE /* ServicesSettings.swift in Sources */,
37C069802725C8D400F7F6CB /* CMTime+DefaultTimescale.swift in Sources */,
37BA793D26DB8EE4002A0235 /* PlaylistVideosView.swift in Sources */,
3711404126B206A6005B3555 /* SearchModel.swift in Sources */,
37FD43F02704A9C00073EE42 /* RecentsModel.swift in Sources */,
379775952689365600DD52A8 /* Array+Next.swift in Sources */,

View File

@ -32,7 +32,7 @@ enum OpenWindow: String, CaseIterable {
func open() {
switch self {
case .player:
NSWorkspace.shared.open(URL(string: "yattee://player")!)
NSWorkspace.shared.open(URL(string: "yattee://\(location)")!)
case .main:
Self.main.focus()
}

View File

@ -5,7 +5,6 @@ import SwiftUI
struct AccountSelectionView: View {
var showHeader = true
@EnvironmentObject<InstancesModel> private var instancesModel
@EnvironmentObject<AccountsModel> private var accountsModel
@Default(.accounts) private var accounts

View File

@ -141,12 +141,6 @@ struct NowPlayingView: View {
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 560, maxHeight: .infinity, alignment: .leading)
}
func header(_ text: String) -> some View {
Text(text)
.font((inInfoViewController ? Font.system(size: 40) : .title3).bold())
.foregroundColor(.secondary)
}
private var progressView: some View {
VStack {
Spacer()

View File

@ -6,7 +6,6 @@ struct TVNavigationView: View {
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<RecentsModel> private var recents
@EnvironmentObject<SearchModel> private var search
@Default(.visibleSections) private var visibleSections
var body: some View {