From 7741e531f4be5384c7e69fa3e61b27b1427fba81 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Thu, 16 May 2024 18:28:32 +0200 Subject: [PATCH] Swiftformat fixes --- Extensions/String+Format.swift | 6 ++-- Model/Applications/VideosAPI.swift | 5 +-- .../BrowsingSettingsGroupImporter.swift | 4 +-- .../LocationsSettingsGroupImporter.swift | 2 +- .../QualitySettingsGroupImporter.swift | 2 +- .../Importers/RecentlyOpenedImporter.swift | 2 +- Model/OpenVideosModel.swift | 2 +- Model/Stream.swift | 16 ++++----- Model/URLBookmarkModel.swift | 2 +- Shared Tests/URLParserTests.swift | 16 ++++----- Shared/Channels/ChannelPlaylistCell.swift | 1 - Shared/Home/FavoriteItemView.swift | 3 +- Shared/Player/PlaybackSettings.swift | 3 -- Shared/Player/Video Details/ChapterView.swift | 1 - .../Player/Video Details/ChaptersView.swift | 2 +- .../Video Details/VideoDescription.swift | 2 +- Shared/Player/VideoPlayerView.swift | 1 - Shared/Playlists/PlaylistFormView.swift | 2 +- Shared/Settings/HistorySettings.swift | 34 +++++++++---------- Shared/Settings/HomeSettings.swift | 2 +- Shared/Settings/PlayerControlsSettings.swift | 1 - Shared/Settings/QualityProfileForm.swift | 1 - Shared/Settings/SettingsView.swift | 1 + Shared/URLParser.swift | 2 +- .../Extensions/UIView+Extensions.swift | 2 +- iOS/AppDelegate.swift | 4 +-- macOS/InstancesSettings.swift | 1 - macOS/VerticalScrollingFix.swift | 2 +- 28 files changed, 57 insertions(+), 65 deletions(-) diff --git a/Extensions/String+Format.swift b/Extensions/String+Format.swift index 1ba2142e..73ea515a 100644 --- a/Extensions/String+Format.swift +++ b/Extensions/String+Format.swift @@ -17,13 +17,13 @@ extension String { var outputText = self - results.reversed().forEach { match in - (1 ..< match.numberOfRanges).reversed().forEach { rangeIndex in + for match in results.reversed() { + for rangeIndex in (1 ..< match.numberOfRanges).reversed() { let matchingGroup: String = (self as NSString).substring(with: match.range(at: rangeIndex)) let rangeBounds = match.range(at: rangeIndex) guard let range = Range(rangeBounds, in: self) else { - return + continue } let replacement = replacementStringClosure(matchingGroup) ?? matchingGroup diff --git a/Model/Applications/VideosAPI.swift b/Model/Applications/VideosAPI.swift index e4856b47..bf8fbc7b 100644 --- a/Model/Applications/VideosAPI.swift +++ b/Model/Applications/VideosAPI.swift @@ -111,12 +111,13 @@ extension VideosAPI { func shareURL(_ item: ContentItem, frontendURLString: String? = nil, time: CMTime? = nil) -> URL? { var urlComponents: URLComponents? if let frontendURLString, - let frontendURL = URL(string: frontendURLString) { + let frontendURL = URL(string: frontendURLString) + { urlComponents = URLComponents(URL: frontendURL, resolvingAgainstBaseURL: false) } else if let instanceComponents = account?.instance?.urlComponents { urlComponents = instanceComponents } - + guard var urlComponents else { return nil } diff --git a/Model/Import Export Settings/Importers/BrowsingSettingsGroupImporter.swift b/Model/Import Export Settings/Importers/BrowsingSettingsGroupImporter.swift index aff8f654..95c575b9 100644 --- a/Model/Import Export Settings/Importers/BrowsingSettingsGroupImporter.swift +++ b/Model/Import Export Settings/Importers/BrowsingSettingsGroupImporter.swift @@ -22,7 +22,7 @@ struct BrowsingSettingsGroupImporter { } if let favorites = json["favorites"].array { - favorites.forEach { favoriteJSON in + for favoriteJSON in favorites { if let jsonString = favoriteJSON.rawString(options: []), let item = FavoriteItem.bridge.deserialize(jsonString) { @@ -32,7 +32,7 @@ struct BrowsingSettingsGroupImporter { } if let widgetsFavorites = json["widgetsSettings"].array { - widgetsFavorites.forEach { widgetJSON in + for widgetJSON in widgetsFavorites { let dict = widgetJSON.dictionaryValue.mapValues { json in json.stringValue } if let item = WidgetSettingsBridge().deserialize(dict) { FavoritesModel.shared.updateWidgetSettings(item) diff --git a/Model/Import Export Settings/Importers/LocationsSettingsGroupImporter.swift b/Model/Import Export Settings/Importers/LocationsSettingsGroupImporter.swift index 9c2e0c9c..d7d5fe37 100644 --- a/Model/Import Export Settings/Importers/LocationsSettingsGroupImporter.swift +++ b/Model/Import Export Settings/Importers/LocationsSettingsGroupImporter.swift @@ -56,7 +56,7 @@ struct LocationsSettingsGroupImporter { } if let accounts = json["accounts"].array { - accounts.forEach { accountJSON in + for accountJSON in accounts { let dict = accountJSON.dictionaryValue.mapValues { json in json.stringValue } if let account = AccountsBridge().deserialize(dict), includedAccountsIDs.contains(account.id) diff --git a/Model/Import Export Settings/Importers/QualitySettingsGroupImporter.swift b/Model/Import Export Settings/Importers/QualitySettingsGroupImporter.swift index 27403ce2..4c192dbc 100644 --- a/Model/Import Export Settings/Importers/QualitySettingsGroupImporter.swift +++ b/Model/Import Export Settings/Importers/QualitySettingsGroupImporter.swift @@ -26,7 +26,7 @@ struct QualitySettingsGroupImporter { } if let qualityProfiles = json["qualityProfiles"].array { - qualityProfiles.forEach { qualityProfileJSON in + for qualityProfileJSON in qualityProfiles { let dict = qualityProfileJSON.dictionaryValue.mapValues { json in json.stringValue } if let item = QualityProfileBridge().deserialize(dict) { QualityProfilesModel.shared.update(item, item) diff --git a/Model/Import Export Settings/Importers/RecentlyOpenedImporter.swift b/Model/Import Export Settings/Importers/RecentlyOpenedImporter.swift index b3bf2535..fddd1f02 100644 --- a/Model/Import Export Settings/Importers/RecentlyOpenedImporter.swift +++ b/Model/Import Export Settings/Importers/RecentlyOpenedImporter.swift @@ -6,7 +6,7 @@ struct RecentlyOpenedImporter { func performImport() { if let recentlyOpened = json["recentlyOpened"].array { - recentlyOpened.forEach { recentlyOpenedJSON in + for recentlyOpenedJSON in recentlyOpened { let dict = recentlyOpenedJSON.dictionaryValue.mapValues { json in json.stringValue } if let item = RecentItemBridge().deserialize(dict) { RecentsModel.shared.add(item) diff --git a/Model/OpenVideosModel.swift b/Model/OpenVideosModel.swift index 2579baf8..90dc91c1 100644 --- a/Model/OpenVideosModel.swift +++ b/Model/OpenVideosModel.swift @@ -147,7 +147,7 @@ struct OpenVideosModel { if prepending { videos.reverse() } - videos.forEach { video in + for video in videos { player.enqueueVideo(video, play: false, prepending: prepending, loadDetails: false) } } diff --git a/Model/Stream.swift b/Model/Stream.swift index 2d82d2ea..2c76c00c 100644 --- a/Model/Stream.swift +++ b/Model/Stream.swift @@ -60,21 +60,21 @@ class Stream: Equatable, Hashable, Identifiable { var bitrate: Int { switch self { case .hd2160p60, .hd2160p50, .hd2160p48, .hd2160p30: - return 56000000 // 56 Mbit/s + return 56_000_000 // 56 Mbit/s case .hd1440p60, .hd1440p50, .hd1440p48, .hd1440p30: - return 24000000 // 24 Mbit/s + return 24_000_000 // 24 Mbit/s case .hd1080p60, .hd1080p50, .hd1080p48, .hd1080p30: - return 12000000 // 12 Mbit/s + return 12_000_000 // 12 Mbit/s case .hd720p60, .hd720p50, .hd720p48, .hd720p30: - return 9500000 // 9.5 Mbit/s + return 9_500_000 // 9.5 Mbit/s case .sd480p30: - return 4000000 // 4 Mbit/s + return 4_000_000 // 4 Mbit/s case .sd360p30: - return 1500000 // 1.5 Mbit/s + return 1_500_000 // 1.5 Mbit/s case .sd240p30: - return 1000000 // 1 Mbit/s + return 1_000_000 // 1 Mbit/s case .sd144p30: - return 600000 // 0.6 Mbit/s + return 600_000 // 0.6 Mbit/s case .unknown: return 0 } diff --git a/Model/URLBookmarkModel.swift b/Model/URLBookmarkModel.swift index 09b3d8f3..47a9be59 100644 --- a/Model/URLBookmarkModel.swift +++ b/Model/URLBookmarkModel.swift @@ -114,7 +114,7 @@ struct URLBookmarkModel { func refreshAll() { logger.info("refreshing all bookmarks") - allURLs.forEach { url in + for url in allURLs { if loadBookmark(url) != nil { logger.info("bookmark for \(url) exists") } else { diff --git a/Shared Tests/URLParserTests.swift b/Shared Tests/URLParserTests.swift index c7f3e6a3..6dea202b 100644 --- a/Shared Tests/URLParserTests.swift +++ b/Shared Tests/URLParserTests.swift @@ -57,7 +57,7 @@ final class URLParserTests: XCTestCase { ] func testUrlsParsing() throws { - Self.urls.forEach { urlString in + for urlString in Self.urls { let url = URL(string: urlString)! let parser = URLParser(url: url) XCTAssertEqual(parser.destination, .fileURL) @@ -66,7 +66,7 @@ final class URLParserTests: XCTestCase { } func testVideosParsing() throws { - Self.videos.forEach { url, id in + for (url, id) in Self.videos { let parser = URLParser(url: URL(string: url)!) XCTAssertEqual(parser.destination, .video) XCTAssertEqual(parser.videoID, id) @@ -74,7 +74,7 @@ final class URLParserTests: XCTestCase { } func testChannelsByNameParsing() throws { - Self.channelsByName.forEach { url, name in + for (url, name) in Self.channelsByName { let parser = URLParser(url: URL(string: url)!) XCTAssertEqual(parser.destination, .channel) XCTAssertEqual(parser.channelName, name) @@ -83,7 +83,7 @@ final class URLParserTests: XCTestCase { } func testChannelsByIdParsing() throws { - Self.channelsByID.forEach { url, id in + for (url, id) in Self.channelsByID { let parser = URLParser(url: URL(string: url)!) XCTAssertEqual(parser.destination, .channel) XCTAssertEqual(parser.channelID, id) @@ -92,7 +92,7 @@ final class URLParserTests: XCTestCase { } func testUsersParsing() throws { - Self.users.forEach { url, user in + for (url, user) in Self.users { let parser = URLParser(url: URL(string: url)!) XCTAssertEqual(parser.destination, .channel) XCTAssertNil(parser.channelID) @@ -102,7 +102,7 @@ final class URLParserTests: XCTestCase { } func testPlaylistsParsing() throws { - Self.playlists.forEach { url, id in + for (url, id) in Self.playlists { let parser = URLParser(url: URL(string: url)!) XCTAssertEqual(parser.destination, .playlist) XCTAssertEqual(parser.playlistID, id) @@ -110,7 +110,7 @@ final class URLParserTests: XCTestCase { } func testSearchesParsing() throws { - Self.searches.forEach { url, query in + for (url, query) in Self.searches { let parser = URLParser(url: URL(string: url)!) XCTAssertEqual(parser.destination, .search) XCTAssertEqual(parser.searchQuery, query) @@ -127,7 +127,7 @@ final class URLParserTests: XCTestCase { "watch?v=IUTGFQpKaPU&t=30s": 30 ] - samples.forEach { url, time in + for (url, time) in samples { XCTAssertEqual( URLParser(url: URL(string: url)!).time, time diff --git a/Shared/Channels/ChannelPlaylistCell.swift b/Shared/Channels/ChannelPlaylistCell.swift index 01f58aae..27ff9a08 100644 --- a/Shared/Channels/ChannelPlaylistCell.swift +++ b/Shared/Channels/ChannelPlaylistCell.swift @@ -53,7 +53,6 @@ struct ChannelPlaylistCell: View { Text("\(playlist.videosCount ?? playlist.videos.count) videos") .foregroundColor(.secondary) - .frame(height: 20) } } diff --git a/Shared/Home/FavoriteItemView.swift b/Shared/Home/FavoriteItemView.swift index 6f99c0a3..0154854b 100644 --- a/Shared/Home/FavoriteItemView.swift +++ b/Shared/Home/FavoriteItemView.swift @@ -81,7 +81,6 @@ struct FavoriteItemView: View { } } .contentShape(Rectangle()) - .onAppear { if item.section == .history { reloadVisibleWatches() @@ -165,7 +164,7 @@ struct FavoriteItemView: View { .prefix(favoritesModel.limit(item)) ) let last = watches.last - watches.forEach { watch in + for watch in watches { player.loadHistoryVideoDetails(watch) { guard let video = player.historyVideo(watch.videoID), itemVisible(.init(video: video)) else { return } visibleWatches.append(watch) diff --git a/Shared/Player/PlaybackSettings.swift b/Shared/Player/PlaybackSettings.swift index 5ae0da17..66638b11 100644 --- a/Shared/Player/PlaybackSettings.swift +++ b/Shared/Player/PlaybackSettings.swift @@ -142,7 +142,6 @@ struct PlaybackSettings: View { } .animation(nil, value: player.activeBackend) .frame(alignment: .topLeading) - .ignoresSafeArea(.all, edges: .bottom) .backport .playbackSettingsPresentationDetents() @@ -235,7 +234,6 @@ struct PlaybackSettings: View { #if os(iOS) .padding(12) .frame(width: 40, height: 40) - .background(RoundedRectangle(cornerRadius: 4).strokeBorder(Color.accentColor, lineWidth: 1)) .contentShape(Rectangle()) #endif @@ -261,7 +259,6 @@ struct PlaybackSettings: View { #if os(iOS) .padding(12) .frame(width: 40, height: 40) - .background(RoundedRectangle(cornerRadius: 4).strokeBorder(Color.accentColor, lineWidth: 1)) .contentShape(Rectangle()) #endif diff --git a/Shared/Player/Video Details/ChapterView.swift b/Shared/Player/Video Details/ChapterView.swift index 54362637..695807d4 100644 --- a/Shared/Player/Video Details/ChapterView.swift +++ b/Shared/Player/Video Details/ChapterView.swift @@ -57,7 +57,6 @@ import SwiftUI } .indicator(.activity) .frame(width: Self.thumbnailWidth, height: Self.thumbnailHeight) - .mask(RoundedRectangle(cornerRadius: 6)) } diff --git a/Shared/Player/Video Details/ChaptersView.swift b/Shared/Player/Video Details/ChaptersView.swift index f43a4503..470eb902 100644 --- a/Shared/Player/Video Details/ChaptersView.swift +++ b/Shared/Player/Video Details/ChaptersView.swift @@ -80,7 +80,7 @@ struct ChaptersView: View { } #if !os(tvOS) - private func chapterViews(for chaptersToShow: ArraySlice, opacity: Double = 1.0, clickable: Bool = true, scrollViewProxy: ScrollViewProxy? = nil) -> some View { + private func chapterViews(for chaptersToShow: ArraySlice, opacity: Double = 1.0, clickable: Bool = true, scrollViewProxy _: ScrollViewProxy? = nil) -> some View { ForEach(Array(chaptersToShow.indices), id: \.self) { index in let chapter = chaptersToShow[index] ChapterView(chapter: chapter, chapterIndex: index, showThumbnail: showThumbnails) diff --git a/Shared/Player/Video Details/VideoDescription.swift b/Shared/Player/Video Details/VideoDescription.swift index 9ba9b29a..c0d5945b 100644 --- a/Shared/Player/Video Details/VideoDescription.swift +++ b/Shared/Player/Video Details/VideoDescription.swift @@ -88,7 +88,7 @@ struct VideoDescription: View { var formattedString: AttributedString { var attrString = AttributedString(description) let words = description.unicodeScalars.split(whereSeparator: separators.contains).map(String.init) - words.forEach { word in + for word in words { if word.hasPrefix("https://") || word.hasPrefix("http://"), let url = URL(string: String(word)) { if let range = attrString.range(of: word) { attrString[range].link = url diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index f9463d6a..a08294f2 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -263,7 +263,6 @@ struct VideoPlayerView: View { #else GeometryReader { geometry in player.playerBackendView - .modifier( VideoPlayerSizeModifier( geometry: geometry, diff --git a/Shared/Playlists/PlaylistFormView.swift b/Shared/Playlists/PlaylistFormView.swift index 02e34012..eefbb934 100644 --- a/Shared/Playlists/PlaylistFormView.swift +++ b/Shared/Playlists/PlaylistFormView.swift @@ -198,7 +198,7 @@ struct PlaylistFormView: View { } } #else - Button(self.visibility.name) { + Button(visibility.name) { self.visibility = self.visibility.next() } .contextMenu { diff --git a/Shared/Settings/HistorySettings.swift b/Shared/Settings/HistorySettings.swift index 082cf267..c572fcf8 100644 --- a/Shared/Settings/HistorySettings.swift +++ b/Shared/Settings/HistorySettings.swift @@ -61,23 +61,23 @@ struct HistorySettings: View { Toggle("Save history of played videos", isOn: $saveHistory) Toggle("Show recents in sidebar", isOn: $showRecents) #if os(macOS) - HStack { - Toggle("Limit recents shown", isOn: $limitRecents) - .frame(minWidth: 140, alignment: .leading) - .disabled(!showRecents) - Spacer() - counterButtons(for: $limitRecentsAmount) - .disabled(!limitRecents) - } + HStack { + Toggle("Limit recents shown", isOn: $limitRecents) + .frame(minWidth: 140, alignment: .leading) + .disabled(!showRecents) + Spacer() + counterButtons(for: $limitRecentsAmount) + .disabled(!limitRecents) + } #else - Toggle("Limit recents shown", isOn: $limitRecents) - .disabled(!showRecents) - HStack { - Text("Recents shown") - Spacer() - counterButtons(for: $limitRecentsAmount) - .disabled(!limitRecents) - } + Toggle("Limit recents shown", isOn: $limitRecents) + .disabled(!showRecents) + HStack { + Text("Recents shown") + Spacer() + counterButtons(for: $limitRecentsAmount) + .disabled(!limitRecents) + } #endif Toggle("Show progress of watching on thumbnails", isOn: $showWatchingProgress) .disabled(!saveHistory) @@ -196,7 +196,7 @@ struct HistorySettings: View { private func counterButtons(for _value: Binding) -> some View { var value: Binding { Binding( - get: { return _value.wrappedValue }, + get: { _value.wrappedValue }, set: { if $0 < 1 { _value.wrappedValue = 1 diff --git a/Shared/Settings/HomeSettings.swift b/Shared/Settings/HomeSettings.swift index 1265815e..5472ee6c 100644 --- a/Shared/Settings/HomeSettings.swift +++ b/Shared/Settings/HomeSettings.swift @@ -68,7 +68,7 @@ struct HomeSettings: View { } .help("Add to Favorites") #if !os(tvOS) - .buttonStyle(.borderless) + .buttonStyle(.borderless) #endif } } diff --git a/Shared/Settings/PlayerControlsSettings.swift b/Shared/Settings/PlayerControlsSettings.swift index 9fb421a3..9d14edb5 100644 --- a/Shared/Settings/PlayerControlsSettings.swift +++ b/Shared/Settings/PlayerControlsSettings.swift @@ -261,7 +261,6 @@ struct PlayerControlsSettings: View { TextField("Duration", text: value) .frame(width: textFieldWidth, alignment: .trailing) .multilineTextAlignment(.center) - .labelsHidden() #if !os(macOS) .keyboardType(.numberPad) diff --git a/Shared/Settings/QualityProfileForm.swift b/Shared/Settings/QualityProfileForm.swift index 2607cbfa..7e5150e7 100644 --- a/Shared/Settings/QualityProfileForm.swift +++ b/Shared/Settings/QualityProfileForm.swift @@ -48,7 +48,6 @@ struct QualityProfileForm: View { .onAppear(perform: initializeForm) .onChange(of: backend, perform: { _ in backendChanged(self.backend); updateActiveFormats(); validate() }) - .onChange(of: name, perform: { _ in validate() }) .onChange(of: resolution, perform: { _ in validate() }) .onChange(of: orderedFormats, perform: { _ in validate() }) diff --git a/Shared/Settings/SettingsView.swift b/Shared/Settings/SettingsView.swift index 3695c86a..b906b674 100644 --- a/Shared/Settings/SettingsView.swift +++ b/Shared/Settings/SettingsView.swift @@ -1,6 +1,7 @@ import Defaults import Foundation import SwiftUI + struct SettingsView: View { static let matrixURL = URL(string: "https://tinyurl.com/matrix-yattee")! static let discordURL = URL(string: "https://yattee.stream/discord")! diff --git a/Shared/URLParser.swift b/Shared/URLParser.swift index 5472269b..1741d700 100644 --- a/Shared/URLParser.swift +++ b/Shared/URLParser.swift @@ -176,7 +176,7 @@ struct URLParser { private func removePrefixes(_ value: String, _ prefixes: [String]) -> String { var value = value - prefixes.forEach { prefix in + for prefix in prefixes { if value.hasPrefix(prefix) { value.removeFirst(prefix.count) } diff --git a/Vendor/RefreshControl/Extensions/UIView+Extensions.swift b/Vendor/RefreshControl/Extensions/UIView+Extensions.swift index c924d1a1..d14f6464 100644 --- a/Vendor/RefreshControl/Extensions/UIView+Extensions.swift +++ b/Vendor/RefreshControl/Extensions/UIView+Extensions.swift @@ -26,7 +26,7 @@ extension UIView { } private func viewsInHierarchy(views: inout [ViewType]) { - subviews.forEach { eachSubView in + for eachSubView in subviews { if let matchingView = eachSubView as? ViewType { views.append(matchingView) } diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 8cabe404..cae4c934 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -19,8 +19,8 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { #endif return true } - - func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { + + func application(_: UIApplication, open url: URL, options _: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { if url.scheme == "yattee" { OpenURLHandler.handle(url) return true diff --git a/macOS/InstancesSettings.swift b/macOS/InstancesSettings.swift index 9aecb948..c813b58a 100644 --- a/macOS/InstancesSettings.swift +++ b/macOS/InstancesSettings.swift @@ -153,7 +153,6 @@ struct InstancesSettings: View { } } .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) - .onAppear { selectedInstanceID = instances.first?.id frontendURL = selectedInstanceFrontendURL diff --git a/macOS/VerticalScrollingFix.swift b/macOS/VerticalScrollingFix.swift index 49e0b9eb..3279d197 100644 --- a/macOS/VerticalScrollingFix.swift +++ b/macOS/VerticalScrollingFix.swift @@ -31,7 +31,7 @@ struct VerticalScrollingFixWrapper: View where Content: View { } var body: some View { - VerticalScrollingFixViewRepresentable(content: self.content()) + VerticalScrollingFixViewRepresentable(content: content()) } }