From e827b97cd5b16dea306e1718cfc58a84662c2d0f Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sat, 17 Jun 2023 14:09:51 +0200 Subject: [PATCH] Fix lint issues --- .swiftlint.yml | 6 ---- Model/Accounts/InstancesModel.swift | 3 +- Model/Applications/InvidiousAPI.swift | 12 +++++--- Model/Applications/PeerTubeAPI.swift | 4 +-- Model/Channel.swift | 2 +- Model/ContentItem.swift | 10 +++---- Model/Favorites/FavoriteItem.swift | 2 +- Model/Favorites/FavoritesModel.swift | 6 +++- Model/HistoryModel.swift | 1 - Model/InstancesManifest.swift | 3 +- Model/OpenVideosModel.swift | 4 +-- Model/Player/Backends/AVPlayerBackend.swift | 9 ++++-- Model/Player/Backends/MPVBackend.swift | 6 +++- Model/Player/Backends/MPVClient.swift | 3 +- Model/Player/PlayerControlsModel.swift | 8 +++-- Model/Player/PlayerModel.swift | 10 +++++-- Model/Player/PlayerQueue.swift | 4 +-- Model/Playlist.swift | 2 +- Model/QualityProfile.swift | 3 +- Model/Store.swift | 2 +- Model/Stream.swift | 30 ++++++++++--------- Model/URLBookmarkModel.swift | 2 +- Model/Video.swift | 6 ++-- Shared/Channels/ChannelVideosView.swift | 6 ++-- Shared/Navigation/Sidebar.swift | 3 +- .../Player/Controls/OSD/OpeningStream.swift | 3 +- Shared/Player/Controls/PlayerControls.swift | 7 +++-- Shared/Player/Controls/TVControls.swift | 2 +- Shared/Player/PlayerBackendView.swift | 6 ++-- .../Video Details/VideoDescription.swift | 3 +- Shared/Player/VideoPlayerSizeModifier.swift | 6 ++-- Shared/Player/VideoPlayerView.swift | 6 +++- Shared/Settings/AccountValidationStatus.swift | 8 ++--- Shared/Subscriptions/FeedView.swift | 6 ++-- Shared/URLParser.swift | 6 ++-- Shared/Videos/ListView.swift | 1 - Shared/Videos/VideoBanner.swift | 8 ++--- Shared/Views/AccentButton.swift | 2 +- Shared/YatteeApp.swift | 2 +- iOS/OrientationTracker.swift | 18 ++++++----- 40 files changed, 130 insertions(+), 101 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 274d32a3..452cd357 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -6,15 +6,9 @@ disabled_rules: - opening_brace - number_separator - multiline_arguments -opt_in_rules: - implicit_return excluded: - Vendor - Tests Apple TV - Tests iOS - Tests macOS - -implicit_return: - included: - - function - - getter diff --git a/Model/Accounts/InstancesModel.swift b/Model/Accounts/InstancesModel.swift index 0a7d57aa..a4aaf2f0 100644 --- a/Model/Accounts/InstancesModel.swift +++ b/Model/Accounts/InstancesModel.swift @@ -76,8 +76,7 @@ final class InstancesModel: ObservableObject { func standardizedURL(_ url: String) -> String { if url.count > 7, url.last == "/" { return String(url.dropLast()) - } else { - return url } + return url } } diff --git a/Model/Applications/InvidiousAPI.swift b/Model/Applications/InvidiousAPI.swift index dfc1284a..0693386d 100644 --- a/Model/Applications/InvidiousAPI.swift +++ b/Model/Applications/InvidiousAPI.swift @@ -65,9 +65,11 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { if type == "channel" { return ContentItem(channel: self.extractChannel(from: json)) - } else if type == "playlist" { + } + if type == "playlist" { return ContentItem(playlist: self.extractChannelPlaylist(from: json)) - } else if type == "video" { + } + if type == "video" { return ContentItem(video: self.extractVideo(from: json)) } @@ -724,9 +726,11 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { if type == "channel" { return ContentItem(channel: extractChannel(from: json)) - } else if type == "playlist" { + } + if type == "playlist" { return ContentItem(playlist: extractChannelPlaylist(from: json)) - } else if type == "video" { + } + if type == "video" { return ContentItem(video: extractVideo(from: json)) } diff --git a/Model/Applications/PeerTubeAPI.swift b/Model/Applications/PeerTubeAPI.swift index 385c5de6..120602c5 100644 --- a/Model/Applications/PeerTubeAPI.swift +++ b/Model/Applications/PeerTubeAPI.swift @@ -392,7 +392,7 @@ final class PeerTubeAPI: Service, ObservableObject, VideosAPI { } func search(_ query: SearchQuery, page _: String?) -> Resource { - var resource = resource(baseURL: account.url, path: basePathAppending("search/videos")) + resource(baseURL: account.url, path: basePathAppending("search/videos")) .withParam("search", query.query) // .withParam("sort_by", query.sortBy.parameter) // .withParam("type", "all") @@ -409,7 +409,7 @@ final class PeerTubeAPI: Service, ObservableObject, VideosAPI { // resource = resource.withParam("page", page) // } - return resource +// return resource } func searchSuggestions(query: String) -> Resource { diff --git a/Model/Channel.swift b/Model/Channel.swift index ac15d7bb..3944a3d8 100644 --- a/Model/Channel.swift +++ b/Model/Channel.swift @@ -110,7 +110,7 @@ struct Channel: Identifiable, Hashable { } func hasData(for contentType: ContentType) -> Bool { - return tabs.contains { $0.contentType == contentType } + tabs.contains { $0.contentType == contentType } } var cacheKey: String { diff --git a/Model/ContentItem.swift b/Model/ContentItem.swift index e07982a1..23d17042 100644 --- a/Model/ContentItem.swift +++ b/Model/ContentItem.swift @@ -15,7 +15,7 @@ struct ContentItem: Identifiable { } } - static func < (lhs: ContentType, rhs: ContentType) -> Bool { + static func < (lhs: Self, rhs: Self) -> Bool { lhs.sortOrder < rhs.sortOrder } } @@ -30,19 +30,19 @@ struct ContentItem: Identifiable { var id: String = UUID().uuidString - static func array(of videos: [Video]) -> [ContentItem] { + static func array(of videos: [Video]) -> [Self] { videos.map { Self(video: $0) } } - static func array(of playlists: [ChannelPlaylist]) -> [ContentItem] { + static func array(of playlists: [ChannelPlaylist]) -> [Self] { playlists.map { Self(playlist: $0) } } - static func array(of channels: [Channel]) -> [ContentItem] { + static func array(of channels: [Channel]) -> [Self] { channels.map { Self(channel: $0) } } - static func < (lhs: ContentItem, rhs: ContentItem) -> Bool { + static func < (lhs: Self, rhs: Self) -> Bool { lhs.contentType < rhs.contentType } diff --git a/Model/Favorites/FavoriteItem.swift b/Model/Favorites/FavoriteItem.swift index 00aa7d58..de5da666 100644 --- a/Model/Favorites/FavoriteItem.swift +++ b/Model/Favorites/FavoriteItem.swift @@ -47,7 +47,7 @@ struct FavoriteItem: Codable, Equatable, Identifiable, Defaults.Serializable { } } - static func == (lhs: FavoriteItem, rhs: FavoriteItem) -> Bool { + static func == (lhs: Self, rhs: Self) -> Bool { lhs.section == rhs.section } diff --git a/Model/Favorites/FavoritesModel.swift b/Model/Favorites/FavoritesModel.swift index 350711eb..ee918976 100644 --- a/Model/Favorites/FavoritesModel.swift +++ b/Model/Favorites/FavoritesModel.swift @@ -17,7 +17,11 @@ struct FavoritesModel { } func toggle(_ item: FavoriteItem) { - contains(item) ? remove(item) : add(item) + if contains(item) { + remove(item) + } else { + add(item) + } } func add(_ item: FavoriteItem) { diff --git a/Model/HistoryModel.swift b/Model/HistoryModel.swift index 98a5d7fe..9568ba09 100644 --- a/Model/HistoryModel.swift +++ b/Model/HistoryModel.swift @@ -52,7 +52,6 @@ extension PlayerModel { let id = currentVideo.videoID let time = time ?? backend.currentTime let seconds = time?.seconds ?? 0 - let duration = playerTime.duration.seconds if seconds < 3 { return } diff --git a/Model/InstancesManifest.swift b/Model/InstancesManifest.swift index 0522c1ac..17e20e1e 100644 --- a/Model/InstancesManifest.swift +++ b/Model/InstancesManifest.swift @@ -45,7 +45,8 @@ final class InstancesManifest: Service, ObservableObject { instancesList?.load().onSuccess { response in if let instances: [ManifestedInstance] = response.typedContent() { - guard let instance = instances.filter { $0.country == country }.randomElement() else { return } + let countryInstances = instances.filter { $0.country == country } + guard let instance = countryInstances.randomElement() else { return } let account = instance.anonymousAccount AccountsModel.shared.publicAccount = account if asCurrent { diff --git a/Model/OpenVideosModel.swift b/Model/OpenVideosModel.swift index 55876fd1..2579baf8 100644 --- a/Model/OpenVideosModel.swift +++ b/Model/OpenVideosModel.swift @@ -63,7 +63,7 @@ struct OpenVideosModel { return [] } - func openURLsFromClipboard(removeQueueItems: Bool = false, playbackMode: OpenVideosModel.PlaybackMode = .playNow) { + func openURLsFromClipboard(removeQueueItems: Bool = false, playbackMode: Self.PlaybackMode = .playNow) { if urlsFromClipboard.isEmpty { NavigationModel.shared.alert = Alert(title: Text("Could not find any links to open in your clipboard".localized())) if NavigationModel.shared.presentingOpenVideos { @@ -76,7 +76,7 @@ struct OpenVideosModel { } } - func openURLs(_ urls: [URL], removeQueueItems: Bool = false, playbackMode: OpenVideosModel.PlaybackMode = .playNow) { + func openURLs(_ urls: [URL], removeQueueItems: Bool = false, playbackMode: Self.PlaybackMode = .playNow) { guard !urls.isEmpty else { return } diff --git a/Model/Player/Backends/AVPlayerBackend.swift b/Model/Player/Backends/AVPlayerBackend.swift index a848d59b..b08d699f 100644 --- a/Model/Player/Backends/AVPlayerBackend.swift +++ b/Model/Player/Backends/AVPlayerBackend.swift @@ -174,7 +174,11 @@ final class AVPlayerBackend: PlayerBackend { } func togglePlay() { - isPlaying ? pause() : play() + if isPlaying { + pause() + } else { + play() + } } func stop() { @@ -414,9 +418,8 @@ final class AVPlayerBackend: PlayerBackend { private func playerItem(_: Stream) -> AVPlayerItem? { if let asset { return AVPlayerItem(asset: asset) - } else { - return AVPlayerItem(asset: composition) } + return AVPlayerItem(asset: composition) } private func attachMetadata() { diff --git a/Model/Player/Backends/MPVBackend.swift b/Model/Player/Backends/MPVBackend.swift index e984ca1e..3c9ac130 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -356,7 +356,11 @@ final class MPVBackend: PlayerBackend { } func togglePlay() { - isPlaying ? pause() : play() + if isPlaying { + pause() + } else { + play() + } } func cancelLoads() { diff --git a/Model/Player/Backends/MPVClient.swift b/Model/Player/Backends/MPVClient.swift index 7d98b965..cc4a0ba6 100644 --- a/Model/Player/Backends/MPVClient.swift +++ b/Model/Player/Backends/MPVClient.swift @@ -471,9 +471,8 @@ final class MPVClient: ObservableObject { let data = Data(bufPtr) if let lastIndex = data.lastIndex(where: { $0 != 0 }) { return String(data: data[0 ... lastIndex], encoding: .isoLatin1)! - } else { - return String(data: data, encoding: .isoLatin1)! } + return String(data: data, encoding: .isoLatin1)! } } } diff --git a/Model/Player/PlayerControlsModel.swift b/Model/Player/PlayerControlsModel.swift index 7ac8e616..3fc309ef 100644 --- a/Model/Player/PlayerControlsModel.swift +++ b/Model/Player/PlayerControlsModel.swift @@ -14,7 +14,7 @@ final class PlayerControlsModel: ObservableObject { var timer: Timer? #if os(tvOS) - private(set) var reporter = PassthroughSubject() + private(set) var reporter = PassthroughSubject() // swiftlint:disable:this private_subject #endif var player: PlayerModel! { .shared } @@ -106,7 +106,11 @@ final class PlayerControlsModel: ObservableObject { } func toggle() { - presentingControls ? hide() : show() + if presentingControls { + hide() + } else { + show() + } } func resetTimer() { diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 4cba3b8d..d9835211 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -717,7 +717,11 @@ final class PlayerModel: ObservableObject { } func togglePiPAction() { - (pipController?.isPictureInPictureActive ?? false) ? closePiP() : startPiP() + if pipController?.isPictureInPictureActive ?? false { + closePiP() + } else { + startPiP() + } } #if os(iOS) @@ -812,12 +816,12 @@ final class PlayerModel: ObservableObject { DispatchQueue.main.asyncAfter(deadline: .now() + 3) { [weak self] in guard let self else { return } - self.playerAPI(item.video)?.loadDetails(item, completionHandler: { newItem in + self.playerAPI(item.video)?.loadDetails(item, failureHandler: nil) { newItem in guard newItem.videoID == self.autoplayItem?.videoID else { return } self.autoplayItem = newItem self.updateRemoteCommandCenter() self.controls.objectWillChange.send() - }) + } } } } diff --git a/Model/Player/PlayerQueue.swift b/Model/Player/PlayerQueue.swift index 968c5363..129e2cea 100644 --- a/Model/Player/PlayerQueue.swift +++ b/Model/Player/PlayerQueue.swift @@ -328,13 +328,13 @@ extension PlayerModel { } playerAPI(video)? - .loadDetails(item, completionHandler: { [weak self] newItem in + .loadDetails(item, failureHandler: nil) { [weak self] newItem in guard let self else { return } replaceQueueItem(newItem) self.logger.info("LOADED queue details: \(videoID)") - }) + } } private func videoLoadFailureHandler(_ error: RequestError, video: Video? = nil) { diff --git a/Model/Playlist.swift b/Model/Playlist.swift index 30829191..d1fce649 100644 --- a/Model/Playlist.swift +++ b/Model/Playlist.swift @@ -60,7 +60,7 @@ struct Playlist: Identifiable, Equatable, Hashable { ) } - static func == (lhs: Playlist, rhs: Playlist) -> Bool { + static func == (lhs: Self, rhs: Self) -> Bool { lhs.id == rhs.id && lhs.updated == rhs.updated } diff --git a/Model/QualityProfile.swift b/Model/QualityProfile.swift index 48161a6f..28775eb0 100644 --- a/Model/QualityProfile.swift +++ b/Model/QualityProfile.swift @@ -62,7 +62,8 @@ struct QualityProfile: Hashable, Identifiable, Defaults.Serializable { var formatsDescription: String { if formats.count == Format.allCases.count { return "Any format".localized() - } else if formats.count <= 3 { + } + if formats.count <= 3 { return formats.map(\.description).joined(separator: ", ") } diff --git a/Model/Store.swift b/Model/Store.swift index 479ad1c7..67e0eee8 100644 --- a/Model/Store.swift +++ b/Model/Store.swift @@ -4,7 +4,7 @@ import Siesta final class Store: ResourceObserver, ObservableObject { @Published private var all: Data? - var collection: Data { all ?? ([] as! Data) } + var collection: Data { all ?? ([item].compactMap { $0 } as! Data) } var item: Data? { all } init(_ data: Data? = nil) { diff --git a/Model/Stream.swift b/Model/Stream.swift index 621a17d6..4f58e637 100644 --- a/Model/Stream.swift +++ b/Model/Stream.swift @@ -54,11 +54,11 @@ class Stream: Equatable, Hashable, Identifiable { return Int(refreshRatePart.components(separatedBy: CharacterSet.decimalDigits.inverted).joined()) ?? -1 } - static func from(resolution: String, fps: Int? = nil) -> Resolution { + static func from(resolution: String, fps: Int? = nil) -> Self { allCases.first { $0.rawValue.contains(resolution) && $0.refreshRate == (fps ?? 30) } ?? .unknown } - static func < (lhs: Resolution, rhs: Resolution) -> Bool { + static func < (lhs: Self, rhs: Self) -> Bool { lhs.height == rhs.height ? (lhs.refreshRate < rhs.refreshRate) : (lhs.height < rhs.height) } } @@ -77,7 +77,7 @@ class Stream: Equatable, Hashable, Identifiable { } } - static func < (lhs: Kind, rhs: Kind) -> Bool { + static func < (lhs: Self, rhs: Self) -> Bool { lhs.sortOrder < rhs.sortOrder } } @@ -123,15 +123,17 @@ class Stream: Equatable, Hashable, Identifiable { if lowercased.contains("webm") { return .webm - } else if lowercased.contains("avc1") { - return .avc1 - } else if lowercased.contains("av01") { - return .av1 - } else if lowercased.contains("mpeg_4") || lowercased.contains("mp4") { - return .mp4 - } else { - return .unknown } + if lowercased.contains("avc1") { + return .avc1 + } + if lowercased.contains("av01") { + return .av1 + } + if lowercased.contains("mpeg_4") || lowercased.contains("mp4") { + return .mp4 + } + return .unknown } } @@ -190,9 +192,8 @@ class Stream: Equatable, Hashable, Identifiable { if kind == .hls { return "HLS" - } else { - return resolution?.name ?? "?" } + return resolution?.name ?? "?" } var description: String { @@ -221,7 +222,8 @@ class Stream: Equatable, Hashable, Identifiable { if kind == .hls { return hlsURL - } else if videoAssetContainsAudio { + } + if videoAssetContainsAudio { return videoAsset.url } diff --git a/Model/URLBookmarkModel.swift b/Model/URLBookmarkModel.swift index 557066ba..09b3d8f3 100644 --- a/Model/URLBookmarkModel.swift +++ b/Model/URLBookmarkModel.swift @@ -45,7 +45,7 @@ struct URLBookmarkModel { func saveBookmark(_ url: NSURL) { guard url.isFileURL else { logger.error("trying to save bookmark for something that is not a file") - logger.error("not a file: \(url.absoluteString)") + logger.error("not a file: \(url.absoluteString ?? "unknown")") return } diff --git a/Model/Video.swift b/Model/Video.swift index f9476c9f..3a16dec3 100644 --- a/Model/Video.swift +++ b/Model/Video.swift @@ -83,7 +83,7 @@ struct Video: Identifiable, Equatable, Hashable { dislikes: Int? = nil, keywords: [String] = [], streams: [Stream] = [], - related: [Video] = [], + related: [Self] = [], chapters: [Chapter] = [], captions: [Captions] = [] ) { @@ -116,7 +116,7 @@ struct Video: Identifiable, Equatable, Hashable { self.captions = captions } - static func local(_ url: URL) -> Video { + static func local(_ url: URL) -> Self { Self( app: .local, videoID: url.absoluteString, @@ -249,7 +249,7 @@ struct Video: Identifiable, Equatable, Hashable { thumbnails.first { $0.quality == quality }?.url } - static func == (lhs: Video, rhs: Video) -> Bool { + static func == (lhs: Self, rhs: Self) -> Bool { let videoIDIsEqual = lhs.videoID == rhs.videoID if !lhs.indexID.isNil, !rhs.indexID.isNil { diff --git a/Shared/Channels/ChannelVideosView.swift b/Shared/Channels/ChannelVideosView.swift index 107084f9..b9904084 100644 --- a/Shared/Channels/ChannelVideosView.swift +++ b/Shared/Channels/ChannelVideosView.swift @@ -338,7 +338,8 @@ struct ChannelVideosView: View { private var resource: Resource? { guard let channel = presentedChannel else { return nil } - let data = contentType != .videos ? channel.tabs.first(where: { $0.contentType == contentType })?.data : nil + let tabData = channel.tabs.first { $0.contentType == contentType }?.data + let data = contentType != .videos ? tabData : nil let resource = accounts.api.channel(channel.id, contentType: contentType, data: data) if contentType == .videos { @@ -451,7 +452,8 @@ struct ChannelVideosView: View { next = next ?? "" } - let data = contentType != .videos ? channel.tabs.first(where: { $0.contentType == contentType })?.data : nil + let tabData = channel.tabs.first { $0.contentType == contentType }?.data + let data = contentType != .videos ? tabData : nil accounts.api.channel(channel.id, contentType: contentType, data: data, page: next).load().onSuccess { response in if let page: ChannelPage = response.typedContent() { self.page = page diff --git a/Shared/Navigation/Sidebar.swift b/Shared/Navigation/Sidebar.swift index 63eb2c72..9e47cad2 100644 --- a/Shared/Navigation/Sidebar.swift +++ b/Shared/Navigation/Sidebar.swift @@ -152,7 +152,8 @@ struct Sidebar: View { if case .recentlyOpened = selection { scrollView.scrollTo("recentlyOpened") return - } else if case let .playlist(id) = selection { + } + if case let .playlist(id) = selection { scrollView.scrollTo(id) return } diff --git a/Shared/Player/Controls/OSD/OpeningStream.swift b/Shared/Player/Controls/OSD/OpeningStream.swift index 47ba04b5..d4caa727 100644 --- a/Shared/Player/Controls/OSD/OpeningStream.swift +++ b/Shared/Player/Controls/OSD/OpeningStream.swift @@ -25,9 +25,8 @@ struct OpeningStream: View { if let selection = player.streamSelection { if selection.isLocal { return "Opening file...".localized() - } else { - return String(format: "Opening %@ stream...".localized(), selection.shortQuality) } + return String(format: "Opening %@ stream...".localized(), selection.shortQuality) } return "Loading streams...".localized() diff --git a/Shared/Player/Controls/PlayerControls.swift b/Shared/Player/Controls/PlayerControls.swift index 6b0efccd..05d2c6e3 100644 --- a/Shared/Player/Controls/PlayerControls.swift +++ b/Shared/Player/Controls/PlayerControls.swift @@ -193,8 +193,11 @@ struct PlayerControls: View { .frame(maxWidth: .infinity) #if os(tvOS) .onChange(of: model.presentingControls) { newValue in - if newValue { focusedField = .play } - else { focusedField = nil } + if newValue { + focusedField = .play + } else { + focusedField = nil + } } .onChange(of: focusedField) { _ in model.resetTimer() } #else diff --git a/Shared/Player/Controls/TVControls.swift b/Shared/Player/Controls/TVControls.swift index 0934823a..1724700a 100644 --- a/Shared/Player/Controls/TVControls.swift +++ b/Shared/Player/Controls/TVControls.swift @@ -47,7 +47,7 @@ struct TVControls: UIViewRepresentable { func updateUIView(_: UIView, context _: Context) {} - func makeCoordinator() -> TVControls.Coordinator { + func makeCoordinator() -> Self.Coordinator { Coordinator(controlsArea) } diff --git a/Shared/Player/PlayerBackendView.swift b/Shared/Player/PlayerBackendView.swift index 7e41e42e..6c75f91d 100644 --- a/Shared/Player/PlayerBackendView.swift +++ b/Shared/Player/PlayerBackendView.swift @@ -70,17 +70,15 @@ struct PlayerBackendView: View { if UIDevice.current.userInterfaceIdiom != .pad { return verticalSizeClass == .compact ? safeAreaModel.safeArea.top : 0 - } else { - return safeAreaModel.safeArea.top.isZero ? safeAreaModel.safeArea.bottom : safeAreaModel.safeArea.top } + return safeAreaModel.safeArea.top.isZero ? safeAreaModel.safeArea.bottom : safeAreaModel.safeArea.top } var controlsBottomPadding: Double { if UIDevice.current.userInterfaceIdiom != .pad { return player.playingFullScreen || verticalSizeClass == .compact ? safeAreaModel.safeArea.bottom : 0 - } else { - return player.playingFullScreen ? safeAreaModel.safeArea.bottom : 0 } + return player.playingFullScreen ? safeAreaModel.safeArea.bottom : 0 } #endif diff --git a/Shared/Player/Video Details/VideoDescription.swift b/Shared/Player/Video Details/VideoDescription.swift index cd178c50..b704a26d 100644 --- a/Shared/Player/Video Details/VideoDescription.swift +++ b/Shared/Player/Video Details/VideoDescription.swift @@ -177,7 +177,8 @@ struct VideoDescription: View { { player.backend.seek(to: Double(time), seekType: .userInteracted) return - } else if destination != nil { + } + if destination != nil { urlToOpen = yatteeURL } } diff --git a/Shared/Player/VideoPlayerSizeModifier.swift b/Shared/Player/VideoPlayerSizeModifier.swift index 83394cb8..f1d07ed6 100644 --- a/Shared/Player/VideoPlayerSizeModifier.swift +++ b/Shared/Player/VideoPlayerSizeModifier.swift @@ -33,7 +33,7 @@ struct VideoPlayerSizeModifier: ViewModifier { #endif } - var ratio: CGFloat? { + var ratio: CGFloat? { // swiftlint:disable:this no_cgfloat fullScreen ? detailsHiddenInFullScreen ? nil : usedAspectRatio : usedAspectRatio } @@ -57,9 +57,9 @@ struct VideoPlayerSizeModifier: ViewModifier { guard !fullScreen else { if detailsHiddenInFullScreen { return geometry.size.height - } else { - return geometry.size.width / usedAspectRatio } + + return geometry.size.width / usedAspectRatio } return max(geometry.size.height - VideoPlayerView.defaultMinimumHeightLeft, 0) diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index c07448fe..3fc252d5 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -274,7 +274,11 @@ struct VideoPlayerView: View { ) .onHover { hovering in hoveringPlayer = hovering - hovering ? player.controls.show() : player.controls.hide() + if hovering { + player.controls.show() + } else { + player.controls.hide() + } } .gesture(player.controls.presentingOverlays ? nil : playerDragGesture) #if os(macOS) diff --git a/Shared/Settings/AccountValidationStatus.swift b/Shared/Settings/AccountValidationStatus.swift index 2e687d96..fb7e7a20 100644 --- a/Shared/Settings/AccountValidationStatus.swift +++ b/Shared/Settings/AccountValidationStatus.swift @@ -47,16 +47,16 @@ struct AccountValidationStatus: View { var validationStatusSystemImage: String { if isValidating { return "bolt.horizontal.fill" - } else { - return isValid ? "checkmark.circle.fill" : "xmark.circle.fill" } + + return isValid ? "checkmark.circle.fill" : "xmark.circle.fill" } var validationStatusColor: Color { if isValidating { return .accentColor - } else { - return isValid ? .green : .red } + + return isValid ? .green : .red } } diff --git a/Shared/Subscriptions/FeedView.swift b/Shared/Subscriptions/FeedView.swift index cb21a124..1cfae0c7 100644 --- a/Shared/Subscriptions/FeedView.swift +++ b/Shared/Subscriptions/FeedView.swift @@ -33,7 +33,7 @@ struct FeedView: View { } #endif #if !os(tvOS) - .background( + .background( Button("Refresh") { feed.loadResources(force: true) } @@ -42,8 +42,8 @@ struct FeedView: View { ) #endif #if !os(macOS) - .onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in - feed.loadResources() + .onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in + feed.loadResources() } #endif } diff --git a/Shared/URLParser.swift b/Shared/URLParser.swift index 8180ef4a..2f0597d4 100644 --- a/Shared/URLParser.swift +++ b/Shared/URLParser.swift @@ -41,9 +41,11 @@ struct URLParser { if hasAnyOfPrefixes(path, Self.prefixes[.playlist]!) || queryItemValue("v") == "playlist" { return .playlist - } else if hasAnyOfPrefixes(path, Self.prefixes[.channel]!) { + } + if hasAnyOfPrefixes(path, Self.prefixes[.channel]!) { return .channel - } else if hasAnyOfPrefixes(path, Self.prefixes[.search]!) { + } + if hasAnyOfPrefixes(path, Self.prefixes[.search]!) { return .search } diff --git a/Shared/Videos/ListView.swift b/Shared/Videos/ListView.swift index 21797e03..e3503f8a 100644 --- a/Shared/Videos/ListView.swift +++ b/Shared/Videos/ListView.swift @@ -1,4 +1,3 @@ - import SwiftUI struct ListView: View { diff --git a/Shared/Videos/VideoBanner.swift b/Shared/Videos/VideoBanner.swift index b6dd303d..fd7a4042 100644 --- a/Shared/Videos/VideoBanner.swift +++ b/Shared/Videos/VideoBanner.swift @@ -253,11 +253,11 @@ struct VideoBanner: View { private var timeLabel: String? { if let watch, let watchStoppedAtLabel, let videoDurationLabel, !watch.finished { return "\(watchStoppedAtLabel) / \(videoDurationLabel)" - } else if let videoDurationLabel { - return videoDurationLabel - } else { - return nil } + if let videoDurationLabel { + return videoDurationLabel + } + return nil } @ViewBuilder private var timeView: some View { diff --git a/Shared/Views/AccentButton.swift b/Shared/Views/AccentButton.swift index 5f4a0db7..b2ef22ef 100644 --- a/Shared/Views/AccentButton.swift +++ b/Shared/Views/AccentButton.swift @@ -3,7 +3,7 @@ import SwiftUI struct AccentButton: View { var text: String? var imageSystemName: String? - var maxWidth: CGFloat? = .infinity + var maxWidth: CGFloat? = .infinity // swiftlint:disable:this no_cgfloat var bold = true var verticalPadding = 10.0 var horizontalPadding = 10.0 diff --git a/Shared/YatteeApp.swift b/Shared/YatteeApp.swift index 31bf3ee1..26264048 100644 --- a/Shared/YatteeApp.swift +++ b/Shared/YatteeApp.swift @@ -98,7 +98,7 @@ struct YatteeApp: App { HostingWindowFinder { window in Windows.playerWindow = window - NotificationCenter.default.addObserver( + NotificationCenter.default.addObserver( // swiftlint:disable:this discarded_notification_center_observer forName: NSWindow.willExitFullScreenNotification, object: window, queue: OperationQueue.main diff --git a/iOS/OrientationTracker.swift b/iOS/OrientationTracker.swift index eb19d01f..d8a1fc28 100644 --- a/iOS/OrientationTracker.swift +++ b/iOS/OrientationTracker.swift @@ -79,14 +79,16 @@ public class OrientationTracker { let threshold = 0.55 if accelerometerData.acceleration.x >= threshold { return .landscapeLeft - } else if accelerometerData.acceleration.x <= -threshold { - return .landscapeRight - } else if accelerometerData.acceleration.y <= -threshold { - return .portrait - } else if accelerometerData.acceleration.y >= threshold { - return .portraitUpsideDown - } else { - return currentDeviceOrientation } + if accelerometerData.acceleration.x <= -threshold { + return .landscapeRight + } + if accelerometerData.acceleration.y <= -threshold { + return .portrait + } + if accelerometerData.acceleration.y >= threshold { + return .portraitUpsideDown + } + return currentDeviceOrientation } }