From 9181d34c0f90d09cd405007cc82a927908c66923 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Tue, 13 Sep 2016 11:42:50 -0400 Subject: [PATCH] ScanLocalBookOperation thread fix --- Kiwix-iOS/Info.plist | 2 +- Kiwix-iOSWidgets/Bookmarks/Info.plist | 2 +- .../Chrisli.xcuserdatad/xcschemes/Kiwix-iOS.xcscheme | 7 +++++++ Kiwix/Operations/ScanLocalBookOperation.swift | 11 ++++++----- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 5b2bf79a..8170ac85 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 1.8.342 + 1.8.361 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOSWidgets/Bookmarks/Info.plist b/Kiwix-iOSWidgets/Bookmarks/Info.plist index 4dd03936..d973ac60 100644 --- a/Kiwix-iOSWidgets/Bookmarks/Info.plist +++ b/Kiwix-iOSWidgets/Bookmarks/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1.8.345 + 1.8.364 NSExtension NSExtensionMainStoryboard diff --git a/Kiwix.xcodeproj/xcuserdata/Chrisli.xcuserdatad/xcschemes/Kiwix-iOS.xcscheme b/Kiwix.xcodeproj/xcuserdata/Chrisli.xcuserdatad/xcschemes/Kiwix-iOS.xcscheme index ce3aad74..902986d0 100644 --- a/Kiwix.xcodeproj/xcuserdata/Chrisli.xcuserdatad/xcschemes/Kiwix-iOS.xcscheme +++ b/Kiwix.xcodeproj/xcuserdata/Chrisli.xcuserdatad/xcschemes/Kiwix-iOS.xcscheme @@ -81,6 +81,13 @@ ReferencedContainer = "container:Kiwix.xcodeproj"> + + + + diff --git a/Kiwix/Operations/ScanLocalBookOperation.swift b/Kiwix/Operations/ScanLocalBookOperation.swift index 18e3c4e1..2d82b9c3 100644 --- a/Kiwix/Operations/ScanLocalBookOperation.swift +++ b/Kiwix/Operations/ScanLocalBookOperation.swift @@ -46,7 +46,10 @@ class ScanLocalBookOperation: Operation { } updateReaders() - updateCoreData() + context.performBlockAndWait {self.updateCoreData()} + + context.performBlockAndWait {self.context.saveIfNeeded()} + NSManagedObjectContext.mainQueueContext.performBlockAndWait {NSManagedObjectContext.mainQueueContext.saveIfNeeded()} } override func operationDidFinish(errors: [ErrorType]) { @@ -71,6 +74,7 @@ class ScanLocalBookOperation: Operation { for id in removedZimFileIDs { guard let book = localBooks[id] else {continue} if let _ = book.meta4URL { + print(book.isLocal) book.isLocal = false } else { context.deleteObject(book) @@ -94,12 +98,9 @@ class ScanLocalBookOperation: Operation { book.hasIndex = reader.hasIndex() } - if localBooks.count == 0 && addedZimFileIDs.count == 1 { + if localBooks.count == 0 && addedZimFileIDs.count >= 1 { firstBookAdded = true } - - context.performBlockAndWait {self.context.saveIfNeeded()} - NSManagedObjectContext.mainQueueContext.performBlockAndWait {NSManagedObjectContext.mainQueueContext.saveIfNeeded()} } // MARK: - Helper