ScanLocalBookOperation thread fix

This commit is contained in:
Chris Li 2016-09-13 11:42:50 -04:00
parent 7775515fde
commit 9181d34c0f
4 changed files with 15 additions and 7 deletions

View File

@ -49,7 +49,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1.8.342</string>
<string>1.8.361</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>

View File

@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.8.345</string>
<string>1.8.364</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>

View File

@ -81,6 +81,13 @@
ReferencedContainer = "container:Kiwix.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "OS_ACTIVITY_MODE"
value = "disable"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>

View File

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