mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-22 11:03:21 -04:00
Merge pull request #1111 from kiwix/1104-update-defaults-dependency
Update defaults dependency to 8.2
This commit is contained in:
commit
0ef04dc554
@ -37,7 +37,7 @@ final class CompactViewController: UIHostingController<AnyView>, UISearchControl
|
||||
|
||||
init(navigation: NavigationViewModel) {
|
||||
self.navigation = navigation
|
||||
searchViewModel = SearchViewModel()
|
||||
searchViewModel = SearchViewModel.shared
|
||||
let searchResult = SearchResults().environmentObject(searchViewModel)
|
||||
searchController = UISearchController(searchResultsController: UIHostingController(rootView: searchResult))
|
||||
super.init(rootView: AnyView(CompactView()))
|
||||
|
@ -21,7 +21,7 @@ public protocol Defaulting: NSObjectProtocol {
|
||||
}
|
||||
|
||||
final class UDefaults: NSObject, Defaulting {
|
||||
subscript<Value>(key: Defaults.Key<Value>) -> Value where Value: DefaultsSerializable {
|
||||
subscript<Value>(key: Defaults.Key<Value>) -> Value {
|
||||
get {
|
||||
Defaults[key]
|
||||
}
|
||||
|
@ -52,38 +52,3 @@ extension Defaults.Keys {
|
||||
static let windowURLs = Key<[URL]>("windowURLs", default: [])
|
||||
#endif
|
||||
}
|
||||
|
||||
extension Defaults.Serializable where Self: Codable {
|
||||
public static var bridge: Defaults.TopLevelCodableBridge<Self> { Defaults.TopLevelCodableBridge() }
|
||||
}
|
||||
|
||||
extension Defaults.Serializable where Self: Codable & NSSecureCoding {
|
||||
public static var bridge: Defaults.CodableNSSecureCodingBridge<Self> { Defaults.CodableNSSecureCodingBridge() }
|
||||
}
|
||||
|
||||
extension Defaults.Serializable where Self: Codable & NSSecureCoding & Defaults.PreferNSSecureCoding {
|
||||
public static var bridge: Defaults.NSSecureCodingBridge<Self> { Defaults.NSSecureCodingBridge() }
|
||||
}
|
||||
|
||||
extension Defaults.Serializable where Self: Codable & RawRepresentable {
|
||||
public static var bridge: Defaults.RawRepresentableCodableBridge<Self> { Defaults.RawRepresentableCodableBridge() }
|
||||
}
|
||||
|
||||
extension Defaults.Serializable where Self: Codable & RawRepresentable & Defaults.PreferRawRepresentable {
|
||||
public static var bridge: Defaults.RawRepresentableBridge<Self> { Defaults.RawRepresentableBridge() }
|
||||
}
|
||||
|
||||
extension Defaults.Serializable where Self: RawRepresentable {
|
||||
public static var bridge: Defaults.RawRepresentableBridge<Self> { Defaults.RawRepresentableBridge() }
|
||||
}
|
||||
extension Defaults.Serializable where Self: NSSecureCoding {
|
||||
public static var bridge: Defaults.NSSecureCodingBridge<Self> { Defaults.NSSecureCodingBridge() }
|
||||
}
|
||||
|
||||
extension Defaults.CollectionSerializable where Element: Defaults.Serializable {
|
||||
public static var bridge: Defaults.CollectionBridge<Self> { Defaults.CollectionBridge() }
|
||||
}
|
||||
|
||||
extension Defaults.SetAlgebraSerializable where Element: Defaults.Serializable & Hashable {
|
||||
public static var bridge: Defaults.SetAlgebraBridge<Self> { Defaults.SetAlgebraBridge() }
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import Defaults
|
||||
|
||||
final class TestDefaults: NSObject, Defaulting {
|
||||
|
||||
var dict: [Defaults.AnyKey: any DefaultsSerializable] = [:]
|
||||
var dict: [Defaults._AnyKey: AnyObject] = [:]
|
||||
|
||||
func setup() {
|
||||
self[.categoriesToLanguages] = [:]
|
||||
@ -29,13 +29,13 @@ final class TestDefaults: NSObject, Defaulting {
|
||||
self[.libraryLanguageCodes] = Set<String>()
|
||||
}
|
||||
|
||||
subscript<Value>(key: Defaults.Key<Value>) -> Value where Value: DefaultsSerializable {
|
||||
subscript<Value>(key: Defaults.Key<Value>) -> Value {
|
||||
get {
|
||||
// swiftlint:disable:next force_cast
|
||||
dict[key] as! Value
|
||||
}
|
||||
set {
|
||||
dict[key] = newValue
|
||||
dict[key] = newValue as AnyObject
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -259,17 +259,33 @@ final class BrowserViewModel: NSObject, ObservableObject,
|
||||
|
||||
@MainActor
|
||||
func updateLastOpened() {
|
||||
guard let tab = try? Database.shared.viewContext.existingObject(with: tabID) as? Tab else { return }
|
||||
tab.lastOpened = Date()
|
||||
let currentTabID = tabID
|
||||
Task {
|
||||
Database.shared.performBackgroundTask { context in
|
||||
guard let tab = try? context.existingObject(with: currentTabID) as? Tab else {
|
||||
return
|
||||
}
|
||||
tab.lastOpened = Date()
|
||||
try? context.save()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func persistState() {
|
||||
guard let tab = try? Database.shared.viewContext.existingObject(with: tabID) as? Tab else {
|
||||
return
|
||||
let webData = webView.interactionState as? Data
|
||||
let currentTabID = tabID
|
||||
Task {
|
||||
Database.shared.performBackgroundTask { context in
|
||||
guard let tab = try? context.existingObject(with: currentTabID) as? Tab else {
|
||||
return
|
||||
}
|
||||
tab.interactionState = webData
|
||||
if context.hasChanges {
|
||||
try? context.save()
|
||||
}
|
||||
}
|
||||
}
|
||||
tab.interactionState = webView.interactionState as? Data
|
||||
try? Database.shared.viewContext.save()
|
||||
}
|
||||
|
||||
// MARK: - Content Loading
|
||||
|
@ -97,6 +97,7 @@ final class NavigationViewModel: ObservableObject {
|
||||
/// Delete a single tab, and select another tab
|
||||
/// - Parameter tabID: ID of the tab to delete
|
||||
func deleteTab(tabID: NSManagedObjectID) {
|
||||
let currentItemValue = currentItem
|
||||
Database.shared.performBackgroundTask { context in
|
||||
let sortByCreation = [NSSortDescriptor(key: "created", ascending: false)]
|
||||
guard let tabs: [Tab] = try? context.fetch(Tab.fetchRequest(predicate: nil,
|
||||
@ -105,7 +106,7 @@ final class NavigationViewModel: ObservableObject {
|
||||
return
|
||||
}
|
||||
let newlySelectedTab: Tab?
|
||||
if case let .tab(selectedTabID) = self.currentItem, selectedTabID == tabID {
|
||||
if case let .tab(selectedTabID) = currentItemValue, selectedTabID == tabID {
|
||||
// select a closeBy tab if the currently selected tab is to be deleted
|
||||
newlySelectedTab = tabs.closeBy(toWhere: { $0.objectID == tabID }) ?? Self.makeTab(context: context)
|
||||
} else if tabs.count == 1 {
|
||||
|
@ -23,13 +23,15 @@ final class SearchViewModel: NSObject, ObservableObject, NSFetchedResultsControl
|
||||
@Published private(set) var zimFiles: [UUID: ZimFile] // ID of zim files that are included in search
|
||||
@Published private(set) var inProgress = false
|
||||
@Published private(set) var results = [SearchResult]()
|
||||
|
||||
static let shared = SearchViewModel()
|
||||
|
||||
private let fetchedResultsController: NSFetchedResultsController<ZimFile>
|
||||
private var searchSubscriber: AnyCancellable?
|
||||
@ZimActor
|
||||
private let queue = OperationQueue()
|
||||
|
||||
override init() {
|
||||
override private init() {
|
||||
// initialize fetched results controller
|
||||
let predicate = NSPredicate(format: "includedInSearch == true AND fileURLBookmark != nil")
|
||||
fetchedResultsController = NSFetchedResultsController(
|
||||
@ -39,7 +41,7 @@ final class SearchViewModel: NSObject, ObservableObject, NSFetchedResultsControl
|
||||
cacheName: nil
|
||||
)
|
||||
|
||||
// initilze zim file IDs
|
||||
// initialize zim file IDs
|
||||
try? fetchedResultsController.performFetch()
|
||||
zimFiles = fetchedResultsController.fetchedObjects?.reduce(into: [:]) { result, zimFile in
|
||||
result?[zimFile.fileID] = zimFile
|
||||
|
@ -29,7 +29,7 @@ struct Bookmarks: View {
|
||||
|
||||
var body: some View {
|
||||
LazyVGrid(columns: ([gridItem]), spacing: 12) {
|
||||
ForEach(bookmarks) { bookmark in
|
||||
ForEach(bookmarks, id: \.self) { bookmark in
|
||||
Button {
|
||||
NotificationCenter.openURL(bookmark.articleURL)
|
||||
if horizontalSizeClass == .compact {
|
||||
@ -54,8 +54,8 @@ struct Bookmarks: View {
|
||||
Message(text: LocalString.bookmark_overlay_empty_title)
|
||||
}
|
||||
}
|
||||
#if os(iOS)
|
||||
.toolbar {
|
||||
#if os(iOS)
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
if #unavailable(iOS 16), horizontalSizeClass == .regular {
|
||||
Button {
|
||||
@ -65,8 +65,8 @@ struct Bookmarks: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private var gridItem: GridItem {
|
||||
|
@ -21,7 +21,7 @@ struct BrowserTab: View {
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
@EnvironmentObject private var browser: BrowserViewModel
|
||||
@EnvironmentObject private var library: LibraryViewModel
|
||||
@StateObject private var search = SearchViewModel()
|
||||
@StateObject private var search = SearchViewModel.shared
|
||||
|
||||
var body: some View {
|
||||
let model = if FeatureFlags.hasLibrary {
|
||||
|
@ -46,7 +46,7 @@ settings:
|
||||
packages:
|
||||
Defaults:
|
||||
url: https://github.com/sindresorhus/Defaults
|
||||
majorVersion: 6.0.0
|
||||
majorVersion: 8.2.0
|
||||
StripeApplePay:
|
||||
url: https://github.com/CodeLikeW/stripe-apple-pay
|
||||
majorVersion: 24.0.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user