diff --git a/Backports/VisualEffectBlur-iOS.swift b/Backports/VisualEffectBlur-iOS.swift index e86d2405..60c3afd2 100644 --- a/Backports/VisualEffectBlur-iOS.swift +++ b/Backports/VisualEffectBlur-iOS.swift @@ -76,7 +76,7 @@ import SwiftUI let blurEffect = UIBlurEffect(style: blurStyle) blurView.effect = blurEffect - if let vibrancyStyle = vibrancyStyle { + if let vibrancyStyle { vibrancyView.effect = UIVibrancyEffect(blurEffect: blurEffect, style: vibrancyStyle) } else { vibrancyView.effect = nil diff --git a/Model/Accounts/Account.swift b/Model/Accounts/Account.swift index 3a83805a..1c1156ef 100644 --- a/Model/Accounts/Account.swift +++ b/Model/Accounts/Account.swift @@ -59,7 +59,7 @@ struct Account: Defaults.Serializable, Hashable, Identifiable { var shortUsername: String { let (username, _) = credentials - guard let username = username, + guard let username, username.count > 10 else { return username ?? "" @@ -70,7 +70,7 @@ struct Account: Defaults.Serializable, Hashable, Identifiable { } var description: String { - guard let name = name, !name.isEmpty else { + guard let name, !name.isEmpty else { return shortUsername } diff --git a/Model/Accounts/AccountsBridge.swift b/Model/Accounts/AccountsBridge.swift index 22bfb597..f2d84414 100644 --- a/Model/Accounts/AccountsBridge.swift +++ b/Model/Accounts/AccountsBridge.swift @@ -6,7 +6,7 @@ struct AccountsBridge: Defaults.Bridge { typealias Serializable = [String: String] func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -22,7 +22,7 @@ struct AccountsBridge: Defaults.Bridge { func deserialize(_ object: Serializable?) -> Value? { guard - let object = object, + let object, let id = object["id"], let instanceID = object["instanceID"], let url = object["apiURL"], diff --git a/Model/Accounts/InstancesBridge.swift b/Model/Accounts/InstancesBridge.swift index 7403e9e7..ba4d77c3 100644 --- a/Model/Accounts/InstancesBridge.swift +++ b/Model/Accounts/InstancesBridge.swift @@ -6,7 +6,7 @@ struct InstancesBridge: Defaults.Bridge { typealias Serializable = [String: String] func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -22,7 +22,7 @@ struct InstancesBridge: Defaults.Bridge { func deserialize(_ object: Serializable?) -> Value? { guard - let object = object, + let object, let app = VideosApp(rawValue: object["app"] ?? ""), let id = object["id"], let apiURL = object["apiURL"] diff --git a/Model/Applications/InvidiousAPI.swift b/Model/Applications/InvidiousAPI.swift index ed88d225..852e85ac 100644 --- a/Model/Applications/InvidiousAPI.swift +++ b/Model/Applications/InvidiousAPI.swift @@ -13,7 +13,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { @Published var validInstance = true var signedIn: Bool { - guard let account = account else { return false } + guard let account else { return false } return !account.anonymous && !(account.token?.isEmpty ?? true) } @@ -182,8 +182,8 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { return } - guard let username = username, - let password = password, + guard let username, + let password, !username.isEmpty, !password.isEmpty else { @@ -406,7 +406,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { resource = resource.withParam("duration", duration.rawValue) } - if let page = page { + if let page { resource = resource.withParam("page", page) } @@ -420,7 +420,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { func comments(_ id: Video.ID, page: String?) -> Resource? { let resource = resource(baseURL: account.url, path: basePathAppending("comments/\(id)")) - guard let page = page else { return resource } + guard let page else { return resource } return resource.withParam("continuation", page) } diff --git a/Model/Applications/PipedAPI.swift b/Model/Applications/PipedAPI.swift index 1dd3b1b5..1ff35b6b 100644 --- a/Model/Applications/PipedAPI.swift +++ b/Model/Applications/PipedAPI.swift @@ -112,8 +112,8 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { let (username, password) = AccountsModel.getCredentials(account) guard !account.anonymous, - let username = username, - let password = password + let username, + let password else { return } @@ -196,7 +196,7 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { } var signedIn: Bool { - guard let account = account else { + guard let account else { return false } diff --git a/Model/Applications/VideosAPI.swift b/Model/Applications/VideosAPI.swift index f093c346..c46bf07d 100644 --- a/Model/Applications/VideosAPI.swift +++ b/Model/Applications/VideosAPI.swift @@ -167,11 +167,11 @@ extension VideosAPI { guard var startSeconds = seconds else { return nil } - if let minutes = minutes { + if let minutes { startSeconds += 60 * minutes } - if let hours = hours { + if let hours { startSeconds += 60 * 60 * hours } diff --git a/Model/HistoryModel.swift b/Model/HistoryModel.swift index f015d3a2..9be2a36d 100644 --- a/Model/HistoryModel.swift +++ b/Model/HistoryModel.swift @@ -38,7 +38,7 @@ extension PlayerModel { let results = try? backgroundContext.fetch(watchFetchRequest) backgroundContext.perform { [weak self] in - guard let self = self else { + guard let self else { return } diff --git a/Model/InstancesManifest.swift b/Model/InstancesManifest.swift index a60e0da1..1776e99c 100644 --- a/Model/InstancesManifest.swift +++ b/Model/InstancesManifest.swift @@ -28,7 +28,7 @@ final class InstancesManifest: Service, ObservableObject { } func setPublicAccount(_ country: String?, accounts: AccountsModel, asCurrent: Bool = true) { - guard let country = country else { + guard let country else { accounts.publicAccount = nil if asCurrent { accounts.configureAccount() @@ -68,7 +68,7 @@ final class InstancesManifest: Service, ObservableObject { instance = countryInstances.randomElement() ?? regionInstances.randomElement() } - guard let instance = instance else { + guard let instance else { settings.presentAlert(title: "Could not change location", message: "No locations available at the moment") return } diff --git a/Model/NavigationModel.swift b/Model/NavigationModel.swift index f11b5d4c..1d870313 100644 --- a/Model/NavigationModel.swift +++ b/Model/NavigationModel.swift @@ -180,7 +180,7 @@ final class NavigationModel: ObservableObject { let presentingPlayer = player.presentingPlayer player.hide() - if let searchQuery = searchQuery { + if let searchQuery { let recent = RecentItem(from: searchQuery) recents.add(recent) diff --git a/Model/NetworkStateModel.swift b/Model/NetworkStateModel.swift index 4ba811f2..1f46fc94 100644 --- a/Model/NetworkStateModel.swift +++ b/Model/NetworkStateModel.swift @@ -11,13 +11,13 @@ final class NetworkStateModel: ObservableObject { private let controlsOverlayModel = ControlOverlaysModel.shared var osdVisible: Bool { - guard let player = player else { return false } + guard let player else { return false } return player.isPlaying && ((player.activeBackend == .mpv && pausedForCache) || player.isSeeking) && bufferingState < 100.0 } var fullStateText: String? { - guard let bufferingStateText = bufferingStateText, - let cacheDurationText = cacheDurationText + guard let bufferingStateText, + let cacheDurationText else { return nil } @@ -36,12 +36,12 @@ final class NetworkStateModel: ObservableObject { } var detailsAvailable: Bool { - guard let player = player else { return false } + guard let player else { return false } return player.activeBackend.supportsNetworkStateBufferingDetails } var needsUpdates: Bool { - if let player = player { + if let player { return !player.currentItem.isNil && (pausedForCache || player.isSeeking || player.isLoadingVideo || controlsOverlayModel.presenting) } diff --git a/Model/Player/Backends/AVPlayerBackend.swift b/Model/Player/Backends/AVPlayerBackend.swift index 84ac1f1c..280684e2 100644 --- a/Model/Player/Backends/AVPlayerBackend.swift +++ b/Model/Player/Backends/AVPlayerBackend.swift @@ -211,7 +211,7 @@ final class AVPlayerBackend: PlayerBackend { model: PlayerModel ) { asset.loadValuesAsynchronously(forKeys: Self.assetKeysToLoad) { [weak self] in - guard let self = self else { + guard let self else { return } model.logger.info("loading \(type.rawValue) track") @@ -285,7 +285,7 @@ final class AVPlayerBackend: PlayerBackend { guard let item = self.model.playerItem, self.isAutoplaying(item) else { return } DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in - guard let self = self else { + guard let self else { return } @@ -361,7 +361,7 @@ final class AVPlayerBackend: PlayerBackend { } private func playerItem(_: Stream) -> AVPlayerItem? { - if let asset = asset { + if let asset { return AVPlayerItem(asset: asset) } else { return AVPlayerItem(asset: composition) @@ -380,7 +380,7 @@ final class AVPlayerBackend: PlayerBackend { if let thumbnailURL = video.thumbnailURL(quality: .medium) { let task = URLSession.shared.dataTask(with: thumbnailURL) { [weak self] thumbnailData, _, _ in - guard let thumbnailData = thumbnailData else { return } + guard let thumbnailData else { return } let image = UIImage(data: thumbnailData) if let pngData = image?.pngData() { @@ -425,7 +425,7 @@ final class AVPlayerBackend: PlayerBackend { private func observePlayerItemStatus(_ item: AVPlayerItem) { statusObservation?.invalidate() statusObservation = item.observe(\.status, options: [.old, .new]) { [weak self] playerItem, _ in - guard let self = self else { + guard let self else { return } @@ -507,7 +507,7 @@ final class AVPlayerBackend: PlayerBackend { forInterval: interval, queue: .main ) { [weak self] _ in - guard let self = self, self.model.activeBackend == .appleAVPlayer else { + guard let self, self.model.activeBackend == .appleAVPlayer else { return } @@ -551,7 +551,7 @@ final class AVPlayerBackend: PlayerBackend { forInterval: interval, queue: .main ) { [weak self] _ in - guard let self = self else { + guard let self else { return } @@ -567,7 +567,7 @@ final class AVPlayerBackend: PlayerBackend { private func addPlayerTimeControlStatusObserver() { playerTimeControlStatusObserver = avPlayer.observe(\.timeControlStatus) { [weak self] player, _ in - guard let self = self, + guard let self, self.avPlayer == player, self.model.activeBackend == .appleAVPlayer else { diff --git a/Model/Player/Backends/MPVBackend.swift b/Model/Player/Backends/MPVBackend.swift index 1f12fe47..659c3674 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -22,7 +22,7 @@ final class MPVBackend: PlayerBackend { var stream: Stream? var video: Video? var captions: Captions? { didSet { - guard let captions = captions else { + guard let captions else { client.removeSubs() return } @@ -33,7 +33,7 @@ final class MPVBackend: PlayerBackend { var loadedVideo = false var isLoadingVideo = true { didSet { DispatchQueue.main.async { [weak self] in - guard let self = self else { + guard let self else { return } @@ -71,7 +71,7 @@ final class MPVBackend: PlayerBackend { var isSeeking = false { didSet { DispatchQueue.main.async { [weak self] in - guard let self = self else { return } + guard let self else { return } self.model.isSeeking = self.isSeeking } } @@ -187,7 +187,7 @@ final class MPVBackend: PlayerBackend { #endif DispatchQueue.main.async { [weak self] in - guard let self = self else { + guard let self else { return } @@ -213,14 +213,14 @@ final class MPVBackend: PlayerBackend { } let replaceItem: (CMTime?) -> Void = { [weak self] time in - guard let self = self else { + guard let self else { return } self.stop() DispatchQueue.main.async { [weak self] in - guard let self = self else { + guard let self else { return } @@ -345,7 +345,7 @@ final class MPVBackend: PlayerBackend { model.updateNowPlayingInfo() handleSegmentsThrottle.execute { - if let currentTime = currentTime { + if let currentTime { model.handleSegments(at: currentTime) } } @@ -453,7 +453,7 @@ final class MPVBackend: PlayerBackend { } func updateNetworkState() { - guard let client = client, let networkState = networkState else { + guard let client, let networkState else { return } diff --git a/Model/Player/Backends/MPVClient.swift b/Model/Player/Backends/MPVClient.swift index e33629ec..87036116 100644 --- a/Model/Player/Backends/MPVClient.swift +++ b/Model/Player/Backends/MPVClient.swift @@ -29,7 +29,7 @@ final class MPVClient: ObservableObject { func create(frame: CGRect? = nil) { #if !os(macOS) - if let frame = frame { + if let frame { glView = MPVOGLView(frame: frame) } #endif @@ -134,7 +134,7 @@ final class MPVClient: ObservableObject { var args = [url.absoluteString] var options = [String]() - if let time = time { + if let time { args.append("replace") options.append("start=\(Int(time.seconds))") } @@ -268,7 +268,7 @@ final class MPVClient: ObservableObject { } DispatchQueue.main.async { [weak self] in - guard let self = self, let model = self.backend.model else { return } + guard let self, let model = self.backend.model else { return } UIView.animate(withDuration: 0.2, animations: { let aspectRatio = self.aspectRatio > 0 && self.aspectRatio < VideoPlayerView.defaultAspectRatio ? self.aspectRatio : VideoPlayerView.defaultAspectRatio let height = [model.playerSize.height, model.playerSize.width / aspectRatio].min()! diff --git a/Model/Player/Backends/PlayerBackend.swift b/Model/Player/Backends/PlayerBackend.swift index 1f34b6d8..6134c5f4 100644 --- a/Model/Player/Backends/PlayerBackend.swift +++ b/Model/Player/Backends/PlayerBackend.swift @@ -79,7 +79,7 @@ extension PlayerBackend { } func seek(relative time: CMTime, seekType: SeekType, completionHandler: ((Bool) -> Void)? = nil) { - if let currentTime = currentTime, let duration = playerItemDuration { + if let currentTime, let duration = playerItemDuration { let seekTime = min(max(0, currentTime.seconds + time.seconds), duration.seconds) model.seek.registerSeek(at: .secondsInDefaultTimescale(seekTime), type: seekType, restore: currentTime) seek(to: seekTime, seekType: seekType, completionHandler: completionHandler) diff --git a/Model/Player/ControlsOverlayModel.swift b/Model/Player/ControlsOverlayModel.swift index dc5dc4f5..ec0777bd 100644 --- a/Model/Player/ControlsOverlayModel.swift +++ b/Model/Player/ControlsOverlayModel.swift @@ -15,7 +15,7 @@ final class ControlOverlaysModel: ObservableObject { } private func handlePresentationChange() { - guard let player = player else { return } + guard let player else { return } player.backend.setNeedsNetworkStateUpdates(presenting && Defaults[.showMPVPlaybackStats]) } } diff --git a/Model/Player/PiPDelegate.swift b/Model/Player/PiPDelegate.swift index f549132a..77922c0d 100644 --- a/Model/Player/PiPDelegate.swift +++ b/Model/Player/PiPDelegate.swift @@ -16,7 +16,7 @@ final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate { func pictureInPictureControllerWillStartPictureInPicture(_: AVPictureInPictureController) {} func pictureInPictureControllerDidStartPictureInPicture(_: AVPictureInPictureController) { - guard let player = player else { return } + guard let player else { return } player.playingInPictureInPicture = true player.avPlayerBackend.startPictureInPictureOnPlay = false @@ -27,7 +27,7 @@ final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate { } func pictureInPictureControllerDidStopPictureInPicture(_: AVPictureInPictureController) { - guard let player = player else { return } + guard let player else { return } player.playingInPictureInPicture = false player.controls.objectWillChange.send() diff --git a/Model/Player/PlayerControlsModel.swift b/Model/Player/PlayerControlsModel.swift index 3720dfc5..39fc22c9 100644 --- a/Model/Player/PlayerControlsModel.swift +++ b/Model/Player/PlayerControlsModel.swift @@ -35,7 +35,7 @@ final class PlayerControlsModel: ObservableObject { } func handlePresentationChange() { - guard let player = player else { return } + guard let player else { return } if presentingControls { DispatchQueue.main.async(qos: .userInteractive) { [weak self] in player.backend.startControlsUpdates() @@ -82,7 +82,7 @@ final class PlayerControlsModel: ObservableObject { } func hide() { - guard let player = player, + guard let player, !player.musicMode else { return @@ -109,7 +109,7 @@ final class PlayerControlsModel: ObservableObject { func resetTimer() { removeTimer() - guard let player = player, !player.musicMode else { + guard let player, !player.musicMode else { return } diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 86d9bc97..db612ce5 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -304,7 +304,7 @@ final class PlayerModel: ObservableObject { var playingLive: Bool { guard live, - let videoDuration = videoDuration, + let videoDuration, let time = backend.currentTime?.seconds else { return false } return videoDuration - time < 30 @@ -337,7 +337,7 @@ final class PlayerModel: ObservableObject { backend == .appleAVPlayer || !avPlayerBackend.startPictureInPictureOnPlay { changeBackendHandler = { [weak self] in - guard let self = self else { return } + guard let self else { return } self.changeActiveBackend(from: self.activeBackend, to: backend) } } @@ -499,7 +499,7 @@ final class PlayerModel: ObservableObject { fromBackend.pause() } - guard var stream = stream, changingStream else { + guard var stream, changingStream else { return } @@ -529,7 +529,7 @@ final class PlayerModel: ObservableObject { } DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in - guard let self = self else { + guard let self else { return } self.upgradeToStream(stream, force: true) @@ -610,7 +610,7 @@ final class PlayerModel: ObservableObject { var pipPossible: Bool { guard activeBackend == .appleAVPlayer else { return !transitioningToPiP } - guard let pipController = pipController else { return false } + guard let pipController else { return false } guard !pipController.isPictureInPictureActive else { return true } return pipController.isPictureInPicturePossible && !transitioningToPiP @@ -644,7 +644,7 @@ final class PlayerModel: ObservableObject { #endif DispatchQueue.main.async(qos: .background) { [weak self] in - guard let self = self else { return } + guard let self else { return } if self.saveLastPlayed { self.lastPlayed = self.currentItem } @@ -680,8 +680,8 @@ final class PlayerModel: ObservableObject { let results = try? context.fetch(watchFetchRequest) context.perform { [weak self] in - guard let self = self, - let results = results else { return } + guard let self, + let results else { return } let resultsIds = results.map(\.videoID) guard let autoplayVideo = related.filter({ !resultsIds.contains($0.videoID) }).randomElement() else { @@ -693,7 +693,7 @@ final class PlayerModel: ObservableObject { self.autoplayItemSource = video DispatchQueue.main.asyncAfter(deadline: .now() + 3) { [weak self] in - guard let self = self else { return } + guard let self else { return } self.playerAPI.loadDetails(item, completionHandler: { newItem in guard newItem.videoID == self.autoplayItem?.videoID else { return } self.autoplayItem = newItem @@ -875,7 +875,7 @@ final class PlayerModel: ObservableObject { } let task = URLSession.shared.dataTask(with: thumbnailURL) { [weak self] thumbnailData, _, _ in - guard let thumbnailData = thumbnailData else { + guard let thumbnailData else { return } @@ -947,7 +947,7 @@ final class PlayerModel: ObservableObject { guard aspectRatio != backend.aspectRatio else { return } DispatchQueue.main.async { [weak self] in - guard let self = self else { return } + guard let self else { return } self.aspectRatio = self.backend.aspectRatio } #endif diff --git a/Model/Player/PlayerQueue.swift b/Model/Player/PlayerQueue.swift index 66099f00..133cb723 100644 --- a/Model/Player/PlayerQueue.swift +++ b/Model/Player/PlayerQueue.swift @@ -58,7 +58,7 @@ extension PlayerModel { preservedTime = currentItem.playbackTime DispatchQueue.main.async { [weak self] in - guard let self = self else { return } + guard let self else { return } guard let video = self.currentVideo else { return } @@ -122,7 +122,7 @@ extension PlayerModel { resetAutoplay() - if let nextItem = nextItem { + if let nextItem { advanceToItem(nextItem) } else { advancing = false @@ -164,7 +164,7 @@ extension PlayerModel { func resetQueue() { DispatchQueue.main.async { [weak self] in - guard let self = self else { + guard let self else { return } @@ -193,7 +193,7 @@ extension PlayerModel { if loadDetails { playerAPI.loadDetails(item, failureHandler: videoLoadFailureHandler) { [weak self] newItem in - guard let self = self else { return } + guard let self else { return } videoDetailsLoadHandler(newItem.video, newItem) if play { @@ -239,7 +239,7 @@ extension PlayerModel { func restoreQueue() { var restoredQueue = [PlayerQueueItem?]() - if let lastPlayed = lastPlayed, + if let lastPlayed, !Defaults[.queue].contains(where: { $0.videoID == lastPlayed.videoID }) { restoredQueue.append(lastPlayed) diff --git a/Model/Player/PlayerQueueItemBridge.swift b/Model/Player/PlayerQueueItemBridge.swift index 3f89d05a..c66a1b92 100644 --- a/Model/Player/PlayerQueueItemBridge.swift +++ b/Model/Player/PlayerQueueItemBridge.swift @@ -7,7 +7,7 @@ struct PlayerQueueItemBridge: Defaults.Bridge { typealias Serializable = [String: String] func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -34,7 +34,7 @@ struct PlayerQueueItemBridge: Defaults.Bridge { func deserialize(_ object: Serializable?) -> Value? { guard - let object = object, + let object, let videoID = object["videoID"] else { return nil diff --git a/Model/Player/PlayerSponsorBlock.swift b/Model/Player/PlayerSponsorBlock.swift index f0ec0e7a..c92c6ff8 100644 --- a/Model/Player/PlayerSponsorBlock.swift +++ b/Model/Player/PlayerSponsorBlock.swift @@ -37,7 +37,7 @@ extension PlayerModel { logger.error("segment end time is: \(segment.end) when player item duration is: \(duration.seconds)") DispatchQueue.main.async { [weak self] in - guard let self = self else { + guard let self else { return } diff --git a/Model/Player/PlayerStreams.swift b/Model/Player/PlayerStreams.swift index 37a83f7a..e8d82e49 100644 --- a/Model/Player/PlayerStreams.swift +++ b/Model/Player/PlayerStreams.swift @@ -18,7 +18,7 @@ extension PlayerModel { func loadAvailableStreams(_ video: Video) { availableStreams = [] - guard let playerInstance = playerInstance else { return } + guard let playerInstance else { return } logger.info("loading streams from \(playerInstance.description)") fetchStreams(playerAPI.video(video.videoID), instance: playerInstance, video: video) diff --git a/Model/QualityProfile.swift b/Model/QualityProfile.swift index 1eab9589..48161a6f 100644 --- a/Model/QualityProfile.swift +++ b/Model/QualityProfile.swift @@ -55,7 +55,7 @@ struct QualityProfile: Hashable, Identifiable, Defaults.Serializable { var formats: [Format] var description: String { - if let name = name, !name.isEmpty { return name } + if let name, !name.isEmpty { return name } return "\(backend.label) - \(resolution.description) - \(formatsDescription)" } @@ -93,7 +93,7 @@ struct QualityProfileBridge: Defaults.Bridge { typealias Serializable = [String: String] func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { return nil } + guard let value else { return nil } return [ "id": value.id, @@ -105,7 +105,7 @@ struct QualityProfileBridge: Defaults.Bridge { } func deserialize(_ object: Serializable?) -> Value? { - guard let object = object, + guard let object, let id = object["id"], let backend = PlayerBackendType(rawValue: object["backend"] ?? ""), let resolution = ResolutionSetting(rawValue: object["resolution"] ?? "") diff --git a/Model/QualityProfilesModel.swift b/Model/QualityProfilesModel.swift index aa8b4f1d..ee0db821 100644 --- a/Model/QualityProfilesModel.swift +++ b/Model/QualityProfilesModel.swift @@ -99,7 +99,7 @@ struct QualityProfilesModel { id = Defaults[.chargingNonCellularProfile] #endif - guard let id = id else { return nil } + guard let id else { return nil } return find(id) } diff --git a/Model/RecentsModel.swift b/Model/RecentsModel.swift index b54915fa..9f525ecb 100644 --- a/Model/RecentsModel.swift +++ b/Model/RecentsModel.swift @@ -137,7 +137,7 @@ struct RecentItemBridge: Defaults.Bridge { typealias Serializable = [String: String] func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -150,7 +150,7 @@ struct RecentItemBridge: Defaults.Bridge { func deserialize(_ object: Serializable?) -> Value? { guard - let object = object, + let object, let type = object["type"], let identifier = object["identifier"], let title = object["title"] diff --git a/Model/ReturnYouTubeDislike/ReturnYouTubeDislikeAPI.swift b/Model/ReturnYouTubeDislike/ReturnYouTubeDislikeAPI.swift index 819cfb8a..da18440c 100644 --- a/Model/ReturnYouTubeDislike/ReturnYouTubeDislikeAPI.swift +++ b/Model/ReturnYouTubeDislike/ReturnYouTubeDislikeAPI.swift @@ -25,7 +25,7 @@ final class ReturnYouTubeDislikeAPI: ObservableObject { private func requestDislikes(completionHandler: @escaping (Int) -> Void = { _ in }) { AF.request(votesURL).responseDecodable(of: JSON.self) { [weak self] response in - guard let self = self else { + guard let self else { return } diff --git a/Model/SeekModel.swift b/Model/SeekModel.swift index 44b7e817..888cff0b 100644 --- a/Model/SeekModel.swift +++ b/Model/SeekModel.swift @@ -51,7 +51,7 @@ final class SeekModel: ObservableObject { } var gestureSeekDestinationTime: Double { - guard let gestureSeek = gestureSeek, let gestureStart = gestureStart else { return -1 } + guard let gestureSeek, let gestureStart else { return -1 } return min(duration.seconds, max(0, gestureStart + gestureSeek)) } diff --git a/Model/SponsorBlock/SponsorBlockAPI.swift b/Model/SponsorBlock/SponsorBlockAPI.swift index 395eb59e..d3a7c45d 100644 --- a/Model/SponsorBlock/SponsorBlockAPI.swift +++ b/Model/SponsorBlock/SponsorBlockAPI.swift @@ -86,7 +86,7 @@ final class SponsorBlockAPI: ObservableObject { } AF.request(url, parameters: parameters(categories: categories)).responseDecodable(of: JSON.self) { [weak self] response in - guard let self = self else { + guard let self else { return } diff --git a/Model/Watch.swift b/Model/Watch.swift index 2864a057..7bf967a0 100644 --- a/Model/Watch.swift +++ b/Model/Watch.swift @@ -30,7 +30,7 @@ extension Watch { watch = results?.first } - guard let watch = watch else { return } + guard let watch else { return } watch.videoDuration = duration watch.stoppedAt = duration @@ -65,7 +65,7 @@ extension Watch { } var watchedAtString: String? { - guard let watchedAt = watchedAt else { + guard let watchedAt else { return nil } diff --git a/Shared/Favorites/DropFavorite.swift b/Shared/Favorites/DropFavorite.swift index 31b237ba..87f03f36 100644 --- a/Shared/Favorites/DropFavorite.swift +++ b/Shared/Favorites/DropFavorite.swift @@ -11,14 +11,14 @@ struct DropFavorite: DropDelegate { return } - guard let current = current else { + guard let current else { return } let from = favorites.firstIndex(of: current) let to = favorites.firstIndex(of: item) - guard let from = from, let to = to else { + guard let from, let to else { return } diff --git a/Shared/Player/Controls/OSD/Buffering.swift b/Shared/Player/Controls/OSD/Buffering.swift index 69dee23f..6e0ef19e 100644 --- a/Shared/Player/Controls/OSD/Buffering.swift +++ b/Shared/Player/Controls/OSD/Buffering.swift @@ -32,7 +32,7 @@ struct Buffering: View { Text(reason) .font(.system(size: playerControlsLayout.timeFontSize)) - if let state = state { + if let state { Text(state) .font(.system(size: playerControlsLayout.bufferingStateFontSize).monospacedDigit()) } diff --git a/Shared/Player/Controls/PlayerControls.swift b/Shared/Player/Controls/PlayerControls.swift index 5caeec5d..cfda6583 100644 --- a/Shared/Player/Controls/PlayerControls.swift +++ b/Shared/Player/Controls/PlayerControls.swift @@ -206,12 +206,12 @@ struct PlayerControls: View { } var detailsWidth: Double { - guard let player = player, player.playerSize.width.isFinite else { return 200 } + guard let player, player.playerSize.width.isFinite else { return 200 } return [player.playerSize.width, 600].min()! } var detailsHeight: Double { - guard let player = player, player.playerSize.height.isFinite else { return 200 } + guard let player, player.playerSize.height.isFinite else { return 200 } return [player.playerSize.height, 500].min()! } diff --git a/Shared/Player/MPV/MPVOGLView.swift b/Shared/Player/MPV/MPVOGLView.swift index 61cc7c39..4a13d3b2 100644 --- a/Shared/Player/MPV/MPVOGLView.swift +++ b/Shared/Player/MPV/MPVOGLView.swift @@ -36,7 +36,7 @@ final class MPVOGLView: GLKView { } override func draw(_: CGRect) { - guard needsDrawing, let mpvGL = mpvGL else { + guard needsDrawing, let mpvGL else { return } diff --git a/Shared/Player/StreamControl.swift b/Shared/Player/StreamControl.swift index 59b0a540..e1a400ff 100644 --- a/Shared/Player/StreamControl.swift +++ b/Shared/Player/StreamControl.swift @@ -53,7 +53,7 @@ struct StreamControl: View { } .transaction { t in t.animation = .none } .onChange(of: player.streamSelection) { selection in - guard let selection = selection else { return } + guard let selection else { return } player.upgradeToStream(selection) player.controls.hideOverlays() } diff --git a/Shared/Player/VideoDetails.swift b/Shared/Player/VideoDetails.swift index 4a03fa77..df790c14 100644 --- a/Shared/Player/VideoDetails.swift +++ b/Shared/Player/VideoDetails.swift @@ -143,7 +143,7 @@ struct VideoDetails: View { var publishedDateSection: some View { Group { - if let video = video { + if let video { HStack(spacing: 4) { if let published = video.publishedDate { Text(published) @@ -227,7 +227,7 @@ struct VideoDetails: View { var detailsPage: some View { VStack(alignment: .leading, spacing: 0) { - if let video = video { + if let video { VStack(spacing: 6) { videoProperties diff --git a/Shared/Player/VideoPlayerSizeModifier.swift b/Shared/Player/VideoPlayerSizeModifier.swift index f951604e..ab5d330a 100644 --- a/Shared/Player/VideoPlayerSizeModifier.swift +++ b/Shared/Player/VideoPlayerSizeModifier.swift @@ -33,7 +33,7 @@ struct VideoPlayerSizeModifier: ViewModifier { } var usedAspectRatio: Double { - guard let aspectRatio = aspectRatio, aspectRatio > 0, aspectRatio < VideoPlayerView.defaultAspectRatio else { + guard let aspectRatio, aspectRatio > 0, aspectRatio < VideoPlayerView.defaultAspectRatio else { return VideoPlayerView.defaultAspectRatio } diff --git a/Shared/Search/SearchField.swift b/Shared/Search/SearchField.swift index f0aca5d3..4a3622fd 100644 --- a/Shared/Search/SearchField.swift +++ b/Shared/Search/SearchField.swift @@ -46,7 +46,7 @@ struct SearchTextField: View { .padding(.trailing, 15) #endif - if let favoriteItem = favoriteItem { + if let favoriteItem { #if os(iOS) FavoriteButton(item: favoriteItem) .id(favoriteItem.id) diff --git a/Shared/Search/SearchView.swift b/Shared/Search/SearchView.swift index 626d7bd9..d603bc4c 100644 --- a/Shared/Search/SearchView.swift +++ b/Shared/Search/SearchView.swift @@ -117,7 +117,7 @@ struct SearchView: View { #endif } .onAppear { - if let query = query { + if let query { state.queryText = query.query state.resetQuery(query) updateFavoriteItem() diff --git a/Shared/Settings/AccountValidationStatus.swift b/Shared/Settings/AccountValidationStatus.swift index 7928686d..f96d15b6 100644 --- a/Shared/Settings/AccountValidationStatus.swift +++ b/Shared/Settings/AccountValidationStatus.swift @@ -18,7 +18,7 @@ struct AccountValidationStatus: View { VStack(alignment: .leading) { Text(isValid ? "Connected successfully (\(app?.name ?? "Unknown"))" : "Connection failed") - if let error = error, !isValid { + if let error, !isValid { Text(error) .font(.caption2) .foregroundColor(.secondary) diff --git a/Shared/Settings/InstanceForm.swift b/Shared/Settings/InstanceForm.swift index 05f2540d..56d06283 100644 --- a/Shared/Settings/InstanceForm.swift +++ b/Shared/Settings/InstanceForm.swift @@ -134,7 +134,7 @@ struct InstanceForm: View { } func submitForm() { - guard isValid, let app = app else { + guard isValid, let app else { return } diff --git a/Shared/Trending/TrendingView.swift b/Shared/Trending/TrendingView.swift index c1a660cc..b3e7d077 100644 --- a/Shared/Trending/TrendingView.swift +++ b/Shared/Trending/TrendingView.swift @@ -49,7 +49,7 @@ struct TrendingView: View { Spacer() } - if let favoriteItem = favoriteItem { + if let favoriteItem { FavoriteButton(item: favoriteItem, labelPadding: true) .id(favoriteItem.id) .labelStyle(.iconOnly) @@ -85,7 +85,7 @@ struct TrendingView: View { .toolbar { #if os(macOS) ToolbarItemGroup { - if let favoriteItem = favoriteItem { + if let favoriteItem { FavoriteButton(item: favoriteItem) .id(favoriteItem.id) } @@ -179,7 +179,7 @@ struct TrendingView: View { } #if os(tvOS) - if let favoriteItem = favoriteItem { + if let favoriteItem { FavoriteButton(item: favoriteItem) .id(favoriteItem.id) .labelStyle(.iconOnly) diff --git a/Shared/URLParser.swift b/Shared/URLParser.swift index 0c17202c..ee16a6c4 100644 --- a/Shared/URLParser.swift +++ b/Shared/URLParser.swift @@ -55,7 +55,7 @@ struct URLParser { } var isYoutubeHost: Bool { - guard let urlComponents = urlComponents else { return false } + guard let urlComponents else { return false } return urlComponents.host == "youtube.com" || urlComponents.host == "www.youtube.com" } @@ -132,7 +132,7 @@ struct URLParser { } private var pathWithoutForwardSlash: String { - guard let urlComponents = urlComponents else { return "" } + guard let urlComponents else { return "" } return String(urlComponents.path.dropFirst()) } diff --git a/Shared/Videos/VideoCell.swift b/Shared/Videos/VideoCell.swift index 8b015486..a6521212 100644 --- a/Shared/Videos/VideoCell.swift +++ b/Shared/Videos/VideoCell.swift @@ -280,7 +280,7 @@ struct VideoCell: View { } } - if let time = time, !timeOnThumbnail { + if let time, !timeOnThumbnail { Spacer() HStack(spacing: 2) { @@ -403,7 +403,7 @@ struct VideoCell: View { if timeOnThumbnail, !video.live, - let time = time + let time { DetailBadge(text: time, style: .prominent) } @@ -429,7 +429,7 @@ struct VideoCell: View { } .retryOnAppear(true) .onFailure { _ in - guard let url = url else { return } + guard let url else { return } thumbnails.insertUnloadable(url) } diff --git a/Shared/Views/ControlsBar.swift b/Shared/Views/ControlsBar.swift index 337bb3a3..faf24ccc 100644 --- a/Shared/Views/ControlsBar.swift +++ b/Shared/Views/ControlsBar.swift @@ -48,7 +48,7 @@ struct ControlsBar: View { #if os(iOS) .background( EmptyView().sheet(isPresented: $presentingShareSheet) { - if let shareURL = shareURL { + if let shareURL { ShareSheet(activityItems: [shareURL]) } } diff --git a/Shared/Views/VideoContextMenuView.swift b/Shared/Views/VideoContextMenuView.swift index 6edac0ad..23812292 100644 --- a/Shared/Views/VideoContextMenuView.swift +++ b/Shared/Views/VideoContextMenuView.swift @@ -39,7 +39,7 @@ struct VideoContextMenuView: View { @ViewBuilder var contextMenu: some View { if saveHistory { Section { - if let watchedAtString = watchedAtString { + if let watchedAtString { Text(watchedAtString) } @@ -115,7 +115,7 @@ struct VideoContextMenuView: View { return "Watching now".localized() } - if let watch = watch, let watchedAtString = watch.watchedAtString { + if let watch, let watchedAtString = watch.watchedAtString { if watchedAtString == "in 0 seconds" { return "Just watched".localized() } @@ -144,7 +144,7 @@ struct VideoContextMenuView: View { var removeFromHistoryButton: some View { Button { - guard let watch = watch else { + guard let watch else { return } diff --git a/Vendor/RefreshControl/Extensions/UIView+Extensions.swift b/Vendor/RefreshControl/Extensions/UIView+Extensions.swift index dcd8bb34..c924d1a1 100644 --- a/Vendor/RefreshControl/Extensions/UIView+Extensions.swift +++ b/Vendor/RefreshControl/Extensions/UIView+Extensions.swift @@ -11,7 +11,7 @@ import UIKit extension UIView { /// Returs frame in screen coordinates. var globalFrame: CGRect { - if let window = window { + if let window { return convert(bounds, to: window.screen.coordinateSpace) } else { return .zero diff --git a/Vendor/RefreshControl/ScrollViewMatcher/ScrollViewMatcher.swift b/Vendor/RefreshControl/ScrollViewMatcher/ScrollViewMatcher.swift index d2e3d0b5..f5fbd4df 100644 --- a/Vendor/RefreshControl/ScrollViewMatcher/ScrollViewMatcher.swift +++ b/Vendor/RefreshControl/ScrollViewMatcher/ScrollViewMatcher.swift @@ -31,7 +31,7 @@ final class ScrollViewMatcherViewController: UIViewController { private var scrollView: UIScrollView? { didSet { if oldValue != scrollView, - let scrollView = scrollView + let scrollView { onMatch(scrollView) } @@ -70,7 +70,7 @@ final class ScrollViewMatcherViewController: UIViewController { } func matchUsingGeometry() { - if let parent = parent { + if let parent { if let scrollViewsInHierarchy: [UIScrollView] = parent.view.viewsInHierarchy() { // Return first match if only a single scroll view is found in the hierarchy. if scrollViewsInHierarchy.count == 1, diff --git a/iOS/Orientation.swift b/iOS/Orientation.swift index 466672bd..9854272f 100644 --- a/iOS/Orientation.swift +++ b/iOS/Orientation.swift @@ -21,7 +21,7 @@ struct Orientation { static func lockOrientation(_ orientation: UIInterfaceOrientationMask, andRotateTo rotateOrientation: UIInterfaceOrientation? = nil) { lockOrientation(orientation) - guard let rotateOrientation = rotateOrientation else { + guard let rotateOrientation else { return } diff --git a/iOS/OrientationTracker.swift b/iOS/OrientationTracker.swift index 0fc718da..eb19d01f 100644 --- a/iOS/OrientationTracker.swift +++ b/iOS/OrientationTracker.swift @@ -59,7 +59,7 @@ public class OrientationTracker { public func startDeviceOrientationTracking() { motionManager.startAccelerometerUpdates(to: queue) { accelerometerData, error in guard error == nil else { return } - guard let accelerometerData = accelerometerData else { return } + guard let accelerometerData else { return } let newDeviceOrientation = self.deviceOrientation(forAccelerometerData: accelerometerData) guard newDeviceOrientation != self.currentDeviceOrientation else { return }