Merge pull request #796 from kiwix/795-clean-up-after-mac13-ios16-min-version-update

Clean  up after Mac 13 iOS 16 min version update
This commit is contained in:
Kelson 2024-06-09 14:19:13 +02:00 committed by GitHub
commit 4c6fc186a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 22 additions and 304 deletions

View File

@ -84,11 +84,7 @@ final class CompactViewController: UIHostingController<AnyView>, 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<AnyView>, 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) {

View File

@ -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()

View File

@ -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

View File

@ -72,8 +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(forLanguageCode: langCode) else { return nil }
guard let name = Locale.current.localizedString(forIdentifier: code) else { return nil }
self.code = code
self.name = name
self.count = count
@ -225,8 +224,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: ",")
}

View File

@ -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)
}
}

View File

@ -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"
]
}

View File

@ -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? {

View File

@ -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<String>([deviceLang].compactMap { $0 })
let validDefaults = LanguagesConverter.convert(codes: deviceLangSet, validCodes: validCodes)

View File

@ -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)
}
}

View File

@ -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()

View File

@ -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)

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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)
}
}

View File

@ -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
}
}