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> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.8.342</string> <string>1.8.361</string>
<key>ITSAppUsesNonExemptEncryption</key> <key>ITSAppUsesNonExemptEncryption</key>
<false/> <false/>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>

View File

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

View File

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

View File

@ -46,7 +46,10 @@ class ScanLocalBookOperation: Operation {
} }
updateReaders() updateReaders()
updateCoreData() context.performBlockAndWait {self.updateCoreData()}
context.performBlockAndWait {self.context.saveIfNeeded()}
NSManagedObjectContext.mainQueueContext.performBlockAndWait {NSManagedObjectContext.mainQueueContext.saveIfNeeded()}
} }
override func operationDidFinish(errors: [ErrorType]) { override func operationDidFinish(errors: [ErrorType]) {
@ -71,6 +74,7 @@ class ScanLocalBookOperation: Operation {
for id in removedZimFileIDs { for id in removedZimFileIDs {
guard let book = localBooks[id] else {continue} guard let book = localBooks[id] else {continue}
if let _ = book.meta4URL { if let _ = book.meta4URL {
print(book.isLocal)
book.isLocal = false book.isLocal = false
} else { } else {
context.deleteObject(book) context.deleteObject(book)
@ -94,12 +98,9 @@ class ScanLocalBookOperation: Operation {
book.hasIndex = reader.hasIndex() book.hasIndex = reader.hasIndex()
} }
if localBooks.count == 0 && addedZimFileIDs.count == 1 { if localBooks.count == 0 && addedZimFileIDs.count >= 1 {
firstBookAdded = true firstBookAdded = true
} }
context.performBlockAndWait {self.context.saveIfNeeded()}
NSManagedObjectContext.mainQueueContext.performBlockAndWait {NSManagedObjectContext.mainQueueContext.saveIfNeeded()}
} }
// MARK: - Helper // MARK: - Helper