From bfd4fe0ba31755c59bae7d630a60866dd07b2344 Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Sat, 8 Jun 2024 14:50:54 +0200 Subject: [PATCH 1/2] Remove if available, and deprecated APIs --- App/CompactViewController.swift | 14 +- App/SidebarViewController.swift | 12 +- App/SplitViewController.swift | 15 -- Model/Entities/Entities.swift | 8 +- Model/LanguagesConverter.swift | 7 +- Model/Utilities/AlphaCodesLookUpTable.swift | 196 ------------------- Model/Utilities/URL.swift | 6 +- ViewModel/LibraryViewModel.swift | 7 +- Views/BuildingBlocks/SearchResultRow.swift | 6 +- Views/BuildingBlocks/WebView.swift | 4 +- Views/BuildingBlocks/ZimFileCell.swift | 8 +- Views/BuildingBlocks/ZimFileRow.swift | 8 +- Views/Buttons/TabsManagerButton.swift | 9 +- Views/Library/ZimFileDetail.swift | 6 +- Views/ViewModifiers/SaveContentHandler.swift | 6 +- Views/ViewModifiers/ViewModifiers.swift | 16 +- 16 files changed, 24 insertions(+), 304 deletions(-) delete mode 100644 Model/Utilities/AlphaCodesLookUpTable.swift diff --git a/App/CompactViewController.swift b/App/CompactViewController.swift index 1b3a6d5f..5894850a 100644 --- a/App/CompactViewController.swift +++ b/App/CompactViewController.swift @@ -84,11 +84,7 @@ final class CompactViewController: UIHostingController, UISearchControl func willPresentSearchController(_ searchController: UISearchController) { navigationController?.setToolbarHidden(true, animated: true) - if #available(iOS 16.0, *) { - trailingNavItemGroups = navigationItem.trailingItemGroups - } else { - rightNavItem = navigationItem.rightBarButtonItem - } + trailingNavItemGroups = navigationItem.trailingItemGroups navigationItem.setRightBarButton( UIBarButtonItem( title: "common.button.cancel".localized, @@ -101,12 +97,8 @@ final class CompactViewController: UIHostingController, UISearchControl } @objc func onSearchCancelled() { searchController.isActive = false - if #available(iOS 16.0, *) { - navigationItem.setRightBarButtonItems(nil, animated: false) - navigationItem.trailingItemGroups = trailingNavItemGroups - } else { - navigationItem.setRightBarButtonItems([rightNavItem].compactMap { $0 }, animated: true) - } + navigationItem.setRightBarButtonItems(nil, animated: false) + navigationItem.trailingItemGroups = trailingNavItemGroups } func willDismissSearchController(_ searchController: UISearchController) { diff --git a/App/SidebarViewController.swift b/App/SidebarViewController.swift index 58084bef..c75f4874 100644 --- a/App/SidebarViewController.swift +++ b/App/SidebarViewController.swift @@ -190,16 +190,8 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl private func configureCell(cell: UICollectionViewListCell, indexPath: IndexPath, item: NavigationItem) { if case let .tab(objectID) = item, let tab = try? Database.viewContext.existingObject(with: objectID) as? Tab { - if #available(iOS 16.0, *) { - cell.contentConfiguration = UIHostingConfiguration { - TabLabel(tab: tab) - } - } else { - var config = cell.defaultContentConfiguration() - config.text = tab.title ?? item.name - config.textProperties.numberOfLines = 1 - config.image = UIImage(systemName: item.icon) - cell.contentConfiguration = config + cell.contentConfiguration = UIHostingConfiguration { + TabLabel(tab: tab) } } else { var config = cell.defaultContentConfiguration() diff --git a/App/SplitViewController.swift b/App/SplitViewController.swift index 9f44df15..68f921d3 100644 --- a/App/SplitViewController.swift +++ b/App/SplitViewController.swift @@ -22,7 +22,6 @@ final class SplitViewController: UISplitViewController { let navigationViewModel: NavigationViewModel private var navigationItemObserver: AnyCancellable? private var openURLObserver: NSObjectProtocol? - private var toggleSidebarObserver: NSObjectProtocol? init(navigationViewModel: NavigationViewModel) { self.navigationViewModel = navigationViewModel @@ -41,9 +40,6 @@ final class SplitViewController: UISplitViewController { override func viewDidLoad() { super.viewDidLoad() - if #available(iOS 16.0, *) {} else { - presentsWithGesture = false - } // setup controllers setViewController(UINavigationController(rootViewController: CompactViewController()), for: .compact) @@ -74,17 +70,6 @@ final class SplitViewController: UISplitViewController { BrowserViewModel.getCached(tabID: tabID).load(url: url) } } - toggleSidebarObserver = NotificationCenter.default.addObserver( - forName: .toggleSidebar, object: nil, queue: nil - ) { [weak self] _ in - if #available(iOS 16.0, *) {} else { - if self?.displayMode == .secondaryOnly { - self?.show(.primary) - } else { - self?.hide(.primary) - } - } - } } /// Dismiss any controller that is already presented when horizontal size class is about to change diff --git a/Model/Entities/Entities.swift b/Model/Entities/Entities.swift index 7e16f40a..7bfe1c92 100644 --- a/Model/Entities/Entities.swift +++ b/Model/Entities/Entities.swift @@ -72,8 +72,9 @@ struct Language: Identifiable, Comparable { let count: Int init?(code: String, count: Int) { - let langCode = Locale.canonicalIdentifier(from: code) - guard let name = Locale.current.localizedString(forLanguageCode: langCode) else { return nil } +// let langCode = Locale.canonicalIdentifier(from: code) + guard let name = Locale.current.localizedString(forIdentifier: code) else { return nil } + debugPrint("Language.code: \(code) => name: \(name)") self.code = code self.name = name self.count = count @@ -225,8 +226,7 @@ final class ZimFile: NSManagedObject, Identifiable { var languageCodesListed: String { return languageCode.split(separator: ",").compactMap { code -> String? in - let langCode = Locale.canonicalIdentifier(from: String(code)) - return Locale.current.localizedString(forLanguageCode: langCode) + return Locale.current.localizedString(forIdentifier: String(code)) }.joined(separator: ",") } diff --git a/Model/LanguagesConverter.swift b/Model/LanguagesConverter.swift index 47bbc0b2..ad28fa1a 100644 --- a/Model/LanguagesConverter.swift +++ b/Model/LanguagesConverter.swift @@ -30,11 +30,6 @@ enum LanguagesConverter { } static func convertToAlpha3(from alpha2: String) -> String? { - if #available(iOS 16, macOS 13, *) { - return Locale.LanguageCode(alpha2).identifier(.alpha3) - } else { - // Fallback on earlier versions - return AlphaCodesLookUpTable.alpha2ToAlpha3[alpha2] - } + Locale.LanguageCode(alpha2).identifier(.alpha3) } } diff --git a/Model/Utilities/AlphaCodesLookUpTable.swift b/Model/Utilities/AlphaCodesLookUpTable.swift deleted file mode 100644 index 9aa59b05..00000000 --- a/Model/Utilities/AlphaCodesLookUpTable.swift +++ /dev/null @@ -1,196 +0,0 @@ -// This file is part of Kiwix for iOS & macOS. -// -// Kiwix is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// any later version. -// -// Kiwix is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Kiwix; If not, see https://www.gnu.org/licenses/. - -// -// AlphaCodesLookUpTable.swift -// Kiwix - -import Foundation - -// it's only needed for iOS 15 and macOS 12 -// should be removed once the min target gets to iOS 16 & macOS 13 -enum AlphaCodesLookUpTable { - static let alpha2ToAlpha3: [String: String] = [ - "ab": "abk", - "af": "afr", - "am": "amh", - "an": "arg", - "ar": "ara", - "as": "asm", - "av": "ava", - "ay": "aym", - "az": "aze", - "ba": "bak", - "be": "bel", - "bg": "bul", - "bi": "bis", - "bm": "bam", - "bn": "ben", - "bo": "bod", - "br": "bre", - "bs": "bos", - "ca": "cat", - "ce": "che", - "ch": "cha", - "co": "cos", - "cr": "cre", - "cs": "ces", - "cu": "chu", - "cv": "chv", - "cy": "cym", - "da": "dan", - "de": "deu", - "dv": "div", - "dz": "dzo", - "ee": "ewe", - "el": "ell", - "en": "eng", - "eo": "epo", - "es": "spa", - "et": "est", - "eu": "eus", - "fa": "fas", - "ff": "ful", - "fi": "fin", - "fj": "fij", - "fo": "fao", - "fr": "fra", - "fy": "fry", - "ga": "gle", - "gd": "gla", - "gl": "glg", - "gn": "grn", - "gu": "guj", - "gv": "glv", - "ha": "hau", - "he": "heb", - "hi": "hin", - "hr": "hrv", - "ht": "hat", - "hu": "hun", - "hy": "hye", - "ia": "ina", - "id": "ind", - "ie": "ile", - "ig": "ibo", - "ik": "ipk", - "io": "ido", - "is": "isl", - "it": "ita", - "iu": "iku", - "ja": "jpn", - "jv": "jav", - "ka": "kat", - "kg": "kon", - "ki": "kik", - "kk": "kaz", - "kl": "kal", - "km": "khm", - "kn": "kan", - "ko": "kor", - "ks": "kas", - "ku": "kur", - "kv": "kom", - "kw": "cor", - "ky": "kir", - "la": "lat", - "lb": "ltz", - "lg": "lug", - "li": "lim", - "ln": "lin", - "lo": "lao", - "lt": "lit", - "lv": "lav", - "mg": "mlg", - "mi": "mri", - "mk": "mkd", - "ml": "mal", - "mn": "mon", - "mr": "mar", - "ms": "msa", - "mt": "mlt", - "my": "mya", - "na": "nau", - "nb": "nob", - "ne": "nep", - "nl": "nld", - "nn": "nno", - "no": "nor", - "nv": "nav", - "ny": "nya", - "oc": "oci", - "oj": "oji", - "om": "orm", - "or": "ori", - "os": "oss", - "pa": "pan", - "pi": "pli", - "pl": "pol", - "ps": "pus", - "pt": "por", - "qu": "que", - "rm": "roh", - "rn": "run", - "ro": "ron", - "ru": "rus", - "rw": "kin", - "sa": "san", - "sc": "srd", - "sd": "snd", - "se": "sme", - "sg": "sag", - "si": "sin", - "sk": "slk", - "sl": "slv", - "sm": "smo", - "sn": "sna", - "so": "som", - "sq": "sqi", - "sr": "srp", - "ss": "ssw", - "st": "sot", - "su": "sun", - "sv": "swe", - "sw": "swa", - "ta": "tam", - "te": "tel", - "tg": "tgk", - "th": "tha", - "ti": "tir", - "tk": "tuk", - "tn": "tsn", - "to": "ton", - "tr": "tur", - "ts": "tso", - "tt": "tat", - "tw": "twi", - "ty": "tah", - "ug": "uig", - "uk": "ukr", - "ur": "urd", - "uz": "uzb", - "ve": "ven", - "vi": "vie", - "vo": "vol", - "wa": "wln", - "wo": "wol", - "xh": "xho", - "yi": "yid", - "yo": "yor", - "za": "zha", - "zh": "zho", - "zu": "zul" - ] -} diff --git a/Model/Utilities/URL.swift b/Model/Utilities/URL.swift index 6e5041dd..d087f250 100644 --- a/Model/Utilities/URL.swift +++ b/Model/Utilities/URL.swift @@ -69,11 +69,7 @@ extension URL { init(temporaryFileWithName fileName: String) { let directory = FileManager.default.temporaryDirectory - if #available(macOS 13.0, iOS 16.0, *) { - self = directory.appending(path: fileName) - } else { - self = directory.appendingPathComponent(fileName) - } + self = directory.appending(path: fileName) } func toTemporaryFileURL() -> URL? { diff --git a/ViewModel/LibraryViewModel.swift b/ViewModel/LibraryViewModel.swift index 6fa23cd6..3c384d67 100644 --- a/ViewModel/LibraryViewModel.swift +++ b/ViewModel/LibraryViewModel.swift @@ -140,12 +140,7 @@ public class LibraryViewModel: ObservableObject { // the device language is on the list of languages from the feed // If all that fails: fallback to English, where most of the content is let fallbackToEnglish = "eng" - let deviceLang: String? - if #available(iOS 16, macOS 13, *) { - deviceLang = Locale.current.language.languageCode?.identifier(.alpha3) - } else { - deviceLang = Locale.current.languageCode - } + let deviceLang = Locale.current.language.languageCode?.identifier(.alpha3) // convert it to a set, so we can use the same validation function let deviceLangSet = Set([deviceLang].compactMap { $0 }) let validDefaults = LanguagesConverter.convert(codes: deviceLangSet, validCodes: validCodes) diff --git a/Views/BuildingBlocks/SearchResultRow.swift b/Views/BuildingBlocks/SearchResultRow.swift index 0f91117e..c3b0cb9f 100644 --- a/Views/BuildingBlocks/SearchResultRow.swift +++ b/Views/BuildingBlocks/SearchResultRow.swift @@ -25,11 +25,7 @@ struct SearchResultRow: View { Text(result.title).fontWeight(.medium) if let snippet = result.snippet { Group { - if #available(iOS 15, *) { - Text(AttributedString(snippet)) - } else { - Text(snippet.string) - } + Text(AttributedString(snippet)) }.font(.caption).lineLimit(4).multilineTextAlignment(.leading) } } diff --git a/Views/BuildingBlocks/WebView.swift b/Views/BuildingBlocks/WebView.swift index 4bbf1ab2..1818a2ad 100644 --- a/Views/BuildingBlocks/WebView.swift +++ b/Views/BuildingBlocks/WebView.swift @@ -171,9 +171,7 @@ final class WebViewConfiguration: WKWebViewConfiguration { super.init() setURLSchemeHandler(KiwixURLSchemeHandler(), forURLScheme: KiwixURLSchemeHandler.KiwixScheme) #if os(macOS) - if #available(macOS 12.3, *) { - preferences.isElementFullscreenEnabled = true - } + preferences.isElementFullscreenEnabled = true #endif userContentController = { let controller = WKUserContentController() diff --git a/Views/BuildingBlocks/ZimFileCell.swift b/Views/BuildingBlocks/ZimFileCell.swift index 4ea31b29..07e767d0 100644 --- a/Views/BuildingBlocks/ZimFileCell.swift +++ b/Views/BuildingBlocks/ZimFileCell.swift @@ -67,11 +67,9 @@ struct ZimFileCell: View { } HStack(alignment: .bottom) { VStack(alignment: .leading) { - if #available(iOS 15.0, *) { - Text("\(zimFile.articleCount.formatted(.number.notation(.compactName))) " + - "zim_file_cell_article_count_suffix".localized) - .font(.caption) - } + Text("\(zimFile.articleCount.formatted(.number.notation(.compactName))) " + + "zim_file_cell_article_count_suffix".localized) + .font(.caption) Text(ZimFileCell.dateFormatter.string(from: zimFile.created)) .font(.caption) }.foregroundColor(.secondary) diff --git a/Views/BuildingBlocks/ZimFileRow.swift b/Views/BuildingBlocks/ZimFileRow.swift index 63b26eb4..70b54312 100644 --- a/Views/BuildingBlocks/ZimFileRow.swift +++ b/Views/BuildingBlocks/ZimFileRow.swift @@ -36,12 +36,8 @@ struct ZimFileRow: View { Formatter.dateShort.string(from: zimFile.created), Formatter.size.string(fromByteCount: zimFile.size), { - if #available(iOS 15.0, *) { - return "\(zimFile.articleCount.formatted(.number.notation(.compactName)))" + - "zim_file_cell_article_count_suffix".localized - } else { - return Formatter.largeNumber(zimFile.articleCount) - } + "\(zimFile.articleCount.formatted(.number.notation(.compactName)))" + + "zim_file_cell_article_count_suffix".localized }() ].joined(separator: ", ")).font(.caption) } diff --git a/Views/Buttons/TabsManagerButton.swift b/Views/Buttons/TabsManagerButton.swift index c3c16003..2b2588cd 100644 --- a/Views/Buttons/TabsManagerButton.swift +++ b/Views/Buttons/TabsManagerButton.swift @@ -85,14 +85,7 @@ struct TabManager: View { var body: some View { List(tabs) { tab in Button { - if #available(iOS 16.0, *) { - navigation.currentItem = NavigationItem.tab(objectID: tab.objectID) - } else { - dismiss() - DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { - navigation.currentItem = NavigationItem.tab(objectID: tab.objectID) - } - } + navigation.currentItem = NavigationItem.tab(objectID: tab.objectID) } label: { TabLabel(tab: tab) } diff --git a/Views/Library/ZimFileDetail.swift b/Views/Library/ZimFileDetail.swift index 6007010b..a57f35e8 100644 --- a/Views/Library/ZimFileDetail.swift +++ b/Views/Library/ZimFileDetail.swift @@ -67,11 +67,7 @@ struct ZimFileDetail: View { Text(zimFile.fileDescription).lineLimit(nil) } Section { - if #available(iOS 16.0, *) { - actions.alignmentGuide(.listRowSeparatorLeading) { $0[.leading] } - } else { - actions - } + actions.alignmentGuide(.listRowSeparatorLeading) { $0[.leading] } } Section { basicInfo } Section { diff --git a/Views/ViewModifiers/SaveContentHandler.swift b/Views/ViewModifiers/SaveContentHandler.swift index bbaab048..bace7db7 100644 --- a/Views/ViewModifiers/SaveContentHandler.swift +++ b/Views/ViewModifiers/SaveContentHandler.swift @@ -96,10 +96,6 @@ struct SaveContentHandler: ViewModifier { extension URL { fileprivate func tempFileURL() -> URL? { let directory = FileManager.default.temporaryDirectory - if #available(macOS 13.0, iOS 16.0, *) { - return directory.appending(path: lastPathComponent) - } else { - return directory.appendingPathComponent(lastPathComponent) - } + return directory.appending(path: lastPathComponent) } } diff --git a/Views/ViewModifiers/ViewModifiers.swift b/Views/ViewModifiers/ViewModifiers.swift index 13e0e448..f9aa8d4c 100644 --- a/Views/ViewModifiers/ViewModifiers.swift +++ b/Views/ViewModifiers/ViewModifiers.swift @@ -17,15 +17,7 @@ import SwiftUI struct MarkAsHalfSheet: ViewModifier { func body(content: Content) -> some View { - if #available(macOS 13.0, iOS 16.0, *) { - content.presentationDetents([.medium, .large]) - } else { - /* - HACK: Use medium as selection so that half sized sheets are consistently shown - when tab manager button is pressed, user can still freely adjust sheet size. - */ - content.backport.presentationDetents([.medium, .large], selection: .constant(.medium)) - } + content.presentationDetents([.medium, .large]) } } @@ -34,11 +26,7 @@ struct ToolbarRoleBrowser: ViewModifier { #if os(macOS) content #elseif os(iOS) - if #available(iOS 16.0, *) { - content.toolbarRole(.browser) - } else { - content - } + content.toolbarRole(.browser) #endif } } From f41d6a092f30be3e003762c8d39ade7e4d03823b Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Sat, 8 Jun 2024 14:52:59 +0200 Subject: [PATCH 2/2] Clean up --- Model/Entities/Entities.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Model/Entities/Entities.swift b/Model/Entities/Entities.swift index 7bfe1c92..4f15970b 100644 --- a/Model/Entities/Entities.swift +++ b/Model/Entities/Entities.swift @@ -72,9 +72,7 @@ struct Language: Identifiable, Comparable { let count: Int init?(code: String, count: Int) { -// let langCode = Locale.canonicalIdentifier(from: code) guard let name = Locale.current.localizedString(forIdentifier: code) else { return nil } - debugPrint("Language.code: \(code) => name: \(name)") self.code = code self.name = name self.count = count