Fix SwiftLint and SwiftFormat violations

- Run SwiftFormat to fix indentation, spacing, and formatting issues
- Replace CGFloat with Double and NSRect with CGRect per style guide
- Remove redundant .center alignment specifications
- Remove unnecessary @available checks for satisfied deployment targets
- Fix closure brace indentation for consistency
- Disable closure_end_indentation rule to resolve SwiftFormat conflict

All linting checks now pass with zero errors and warnings.
This commit is contained in:
Arkadiusz Fal
2025-11-15 19:42:37 +01:00
parent 97ae843013
commit 5758417293
42 changed files with 400 additions and 453 deletions

View File

@@ -687,7 +687,8 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
func extractXTags(from urlString: String) -> [String: String] {
guard let urlComponents = URLComponents(string: urlString),
let queryItems = urlComponents.queryItems,
let xtagsValue = queryItems.first(where: { $0.name == "xtags" })?.value else {
let xtagsValue = queryItems.first(where: { $0.name == "xtags" })?.value
else {
return [:]
}

View File

@@ -722,10 +722,10 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
}
.sorted { track1, track2 in
// Sort: ORIGINAL first, then DUBBED, then others
if track1.content == "ORIGINAL" && track2.content != "ORIGINAL" {
if track1.content == "ORIGINAL", track2.content != "ORIGINAL" {
return true
}
if track1.content != "ORIGINAL" && track2.content == "ORIGINAL" {
if track1.content != "ORIGINAL", track2.content == "ORIGINAL" {
return false
}
// If both are same type, sort by language

View File

@@ -318,7 +318,7 @@ final class NavigationModel: ObservableObject {
func multipleTapHandler() {
switch tabSelection {
case .search:
self.search.focused = true
search.focused = true
default:
print("not implemented")
}

View File

@@ -26,7 +26,7 @@ final class NetworkStateModel: ObservableObject {
}
var bufferingStateText: String? {
guard detailsAvailable && player.hasStarted else { return nil }
guard detailsAvailable, player.hasStarted else { return nil }
return String(format: "%.0f%%", bufferingState)
}

View File

@@ -190,8 +190,8 @@ final class AVPlayerBackend: PlayerBackend {
}
// After the video has ended, hitting play restarts the video from the beginning.
if currentTime?.seconds.formattedAsPlaybackTime() == model.playerTime.duration.seconds.formattedAsPlaybackTime() &&
currentTime!.seconds > 0 && model.playerTime.duration.seconds > 0
if currentTime?.seconds.formattedAsPlaybackTime() == model.playerTime.duration.seconds.formattedAsPlaybackTime(),
currentTime!.seconds > 0, model.playerTime.duration.seconds > 0
{
seek(to: 0, seekType: .loopRestart)
}

View File

@@ -97,7 +97,7 @@ final class MPVBackend: PlayerBackend {
var controlsUpdates = false
private var timeObserverThrottle = Throttle(interval: 2)
// Retry mechanism
private var retryCount = 0
private let maxRetries = 3
@@ -227,7 +227,7 @@ final class MPVBackend: PlayerBackend {
// Store stream and video for potential retries
currentRetryStream = stream
currentRetryVideo = video
#if !os(macOS)
if model.presentingPlayer {
DispatchQueue.main.async {
@@ -247,7 +247,7 @@ final class MPVBackend: PlayerBackend {
video.captions.first { $0.code.contains(captionsDefaultLanguageCode) }
// If there are still no captions, try to get captions with the fallback language code
if captions.isNil && !captionsFallbackLanguageCode.isEmpty {
if captions.isNil, !captionsFallbackLanguageCode.isEmpty {
captions = video.captions.first { $0.code == captionsFallbackLanguageCode } ??
video.captions.first { $0.code.contains(captionsFallbackLanguageCode) }
}
@@ -369,7 +369,7 @@ final class MPVBackend: PlayerBackend {
replaceItem(self.model.preservedTime)
}
} else {
replaceItem(self.model.preservedTime)
replaceItem(model.preservedTime)
}
} else {
replaceItem(nil)
@@ -400,8 +400,8 @@ final class MPVBackend: PlayerBackend {
setRate(model.currentRate)
// After the video has ended, hitting play restarts the video from the beginning.
if let currentTime, currentTime.seconds.formattedAsPlaybackTime() == model.playerTime.duration.seconds.formattedAsPlaybackTime() &&
currentTime.seconds > 0 && model.playerTime.duration.seconds > 0
if let currentTime, currentTime.seconds.formattedAsPlaybackTime() == model.playerTime.duration.seconds.formattedAsPlaybackTime(),
currentTime.seconds > 0, model.playerTime.duration.seconds > 0
{
seek(to: 0, seekType: .loopRestart)
}
@@ -466,23 +466,23 @@ final class MPVBackend: PlayerBackend {
func closeItem() {
pause()
stop()
self.video = nil
self.stream = nil
video = nil
stream = nil
}
func closePiP() {}
func startControlsUpdates() {
guard model.presentingPlayer, model.controls.presentingControls, !model.controls.presentingOverlays else {
self.logger.info("ignored controls update start")
logger.info("ignored controls update start")
return
}
self.logger.info("starting controls updates")
logger.info("starting controls updates")
controlsUpdates = true
}
func stopControlsUpdates() {
self.logger.info("stopping controls updates")
logger.info("stopping controls updates")
controlsUpdates = false
}
@@ -514,7 +514,7 @@ final class MPVBackend: PlayerBackend {
self.model.updateWatch(time: currentTime)
}
self.model.updateTime(currentTime)
model.updateTime(currentTime)
}
private func stopClientUpdates() {
@@ -641,7 +641,7 @@ final class MPVBackend: PlayerBackend {
}
eofPlaybackModeAction()
}
private func handleFileLoadError() {
guard let stream = currentRetryStream, let video = currentRetryVideo else {
// No stream info available, show error immediately
@@ -651,13 +651,13 @@ final class MPVBackend: PlayerBackend {
eofPlaybackModeAction()
return
}
if retryCount < maxRetries {
retryCount += 1
let delay = TimeInterval(retryCount * 2) // 2, 4, 6 seconds
logger.warning("File load failed. Retry attempt \(retryCount) of \(maxRetries) after \(delay) seconds...")
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
guard let self else { return }
self.logger.info("Retrying file load (attempt \(self.retryCount))...")
@@ -670,12 +670,12 @@ final class MPVBackend: PlayerBackend {
model.closeCurrentItem(finished: true)
getTimeUpdates()
eofPlaybackModeAction()
// Reset retry counter for next attempt
resetRetryState()
}
}
private func resetRetryState() {
retryCount = 0
currentRetryStream = nil
@@ -807,7 +807,7 @@ final class MPVBackend: PlayerBackend {
guard let stream, let video else { return }
// Validate the index is within bounds
guard index >= 0 && index < stream.audioTracks.count else {
guard index >= 0, index < stream.audioTracks.count else {
logger.error("Invalid audio track index: \(index), available tracks: \(stream.audioTracks.count)")
return
}

View File

@@ -217,7 +217,7 @@ extension PlayerBackend {
// If rhs has no resolution, it's "less than" lhs (prefer lhs)
return lhs.resolution == nil
}
if lhsResolution == rhsResolution {
guard let lhsFormat = QualityProfile.Format(rawValue: lhs.format.rawValue),
let rhsFormat = QualityProfile.Format(rawValue: rhs.format.rawValue)

View File

@@ -620,7 +620,7 @@ final class PlayerModel: ObservableObject {
}
Defaults[.activeBackend] = to
self.activeBackend = to
activeBackend = to
let fromBackend: PlayerBackend = from == .appleAVPlayer ? avPlayerBackend : mpvBackend
let toBackend: PlayerBackend = to == .appleAVPlayer ? avPlayerBackend : mpvBackend
@@ -628,13 +628,13 @@ final class PlayerModel: ObservableObject {
toBackend.cancelLoads()
fromBackend.cancelLoads()
if !self.backend.canPlayAtRate(currentRate) {
currentRate = self.backend.suggestedPlaybackRates.last { $0 < currentRate } ?? 1.0
if !backend.canPlayAtRate(currentRate) {
currentRate = backend.suggestedPlaybackRates.last { $0 < currentRate } ?? 1.0
}
self.rateToRestore = Float(currentRate)
rateToRestore = Float(currentRate)
self.backend.didChangeTo()
backend.didChangeTo()
if wasPlaying {
fromBackend.pause()
@@ -664,7 +664,7 @@ final class PlayerModel: ObservableObject {
self.stream = stream
streamSelection = stream
self.upgradeToStream(stream, force: true)
upgradeToStream(stream, force: true)
return
}
@@ -1086,7 +1086,7 @@ final class PlayerModel: ObservableObject {
logger.info("entering fullscreen")
toggleFullscreen(false, showControls: showControls)
self.playingFullScreen = true
playingFullScreen = true
}
func exitFullScreen(showControls: Bool = true) {
@@ -1094,7 +1094,7 @@ final class PlayerModel: ObservableObject {
logger.info("exiting fullscreen")
toggleFullscreen(true, showControls: showControls)
self.playingFullScreen = false
playingFullScreen = false
}
func updateNowPlayingInfo() {
@@ -1284,7 +1284,7 @@ final class PlayerModel: ObservableObject {
}
private func chapterForTime(_ time: Double) -> Int? {
guard let chapters = self.videoForDisplay?.chapters else {
guard let chapters = videoForDisplay?.chapters else {
return nil
}

View File

@@ -130,7 +130,7 @@ extension PlayerModel {
logger.error("Backend is nil when trying to select stream by quality profile")
return nil
}
let profile = qualityProfile ?? .defaultProfile
// First attempt: Filter by both `canPlay` and `isPreferred`