mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-28 22:43:55 -04:00
renaming ZimMultiReader.shared
This commit is contained in:
parent
bf3adbe58a
commit
6a2ff68936
@ -132,7 +132,7 @@ class LocalBooksController: UIViewController, UITableViewDelegate, UITableViewDa
|
|||||||
let delete = UITableViewRowAction(style: .Destructive, title: LocalizedStrings.delete) { (action, indexPath) -> Void in
|
let delete = UITableViewRowAction(style: .Destructive, title: LocalizedStrings.delete) { (action, indexPath) -> Void in
|
||||||
guard let book = self.fetchedResultController.objectAtIndexPath(indexPath) as? Book else {return}
|
guard let book = self.fetchedResultController.objectAtIndexPath(indexPath) as? Book else {return}
|
||||||
self.managedObjectContext.performBlock({ () -> Void in
|
self.managedObjectContext.performBlock({ () -> Void in
|
||||||
if let zimURL = ZimMultiReader.sharedInstance.readers[book.id]?.fileURL {
|
if let zimURL = ZimMultiReader.shared.readers[book.id]?.fileURL {
|
||||||
FileManager.removeItem(atURL: zimURL)
|
FileManager.removeItem(atURL: zimURL)
|
||||||
|
|
||||||
let indexFolderURL = zimURL.URLByAppendingPathExtension("idx")
|
let indexFolderURL = zimURL.URLByAppendingPathExtension("idx")
|
||||||
|
@ -54,7 +54,7 @@ class MainController: UIViewController {
|
|||||||
|
|
||||||
navigationItem.titleView = searchBar
|
navigationItem.titleView = searchBar
|
||||||
searchBar.delegate = self
|
searchBar.delegate = self
|
||||||
ZimMultiReader.sharedInstance.delegate = self
|
ZimMultiReader.shared.delegate = self
|
||||||
|
|
||||||
NSUserDefaults.standardUserDefaults().addObserver(self, forKeyPath: "webViewNotInjectJavascriptToAdjustPageLayout", options: .New, context: context)
|
NSUserDefaults.standardUserDefaults().addObserver(self, forKeyPath: "webViewNotInjectJavascriptToAdjustPageLayout", options: .New, context: context)
|
||||||
NSUserDefaults.standardUserDefaults().addObserver(self, forKeyPath: "webViewZoomScale", options: .New, context: context)
|
NSUserDefaults.standardUserDefaults().addObserver(self, forKeyPath: "webViewZoomScale", options: .New, context: context)
|
||||||
@ -110,7 +110,7 @@ class MainController: UIViewController {
|
|||||||
let urlString = activity.userInfo?["ArticleURL"] as? String,
|
let urlString = activity.userInfo?["ArticleURL"] as? String,
|
||||||
let url = NSURL(string: urlString),
|
let url = NSURL(string: urlString),
|
||||||
let host = url.host else {return}
|
let host = url.host else {return}
|
||||||
if ZimMultiReader.sharedInstance.readers.keys.contains(host) {
|
if ZimMultiReader.shared.readers.keys.contains(host) {
|
||||||
load(url)
|
load(url)
|
||||||
} else {
|
} else {
|
||||||
// TODO: - Alert cannot complete hand off
|
// TODO: - Alert cannot complete hand off
|
||||||
@ -132,7 +132,7 @@ class MainController: UIViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadMainPage(id: ZimID) {
|
func loadMainPage(id: ZimID) {
|
||||||
guard let reader = ZimMultiReader.sharedInstance.readers[id] else {return}
|
guard let reader = ZimMultiReader.shared.readers[id] else {return}
|
||||||
let mainPageURLString = reader.mainPageURL()
|
let mainPageURLString = reader.mainPageURL()
|
||||||
let mainPageURL = NSURL.kiwixURLWithZimFileid(id, contentURLString: mainPageURLString)
|
let mainPageURL = NSURL.kiwixURLWithZimFileid(id, contentURLString: mainPageURLString)
|
||||||
load(mainPageURL)
|
load(mainPageURL)
|
||||||
|
@ -101,7 +101,7 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate,
|
|||||||
// MARK: - ZimMultiReaderDelegate
|
// MARK: - ZimMultiReaderDelegate
|
||||||
|
|
||||||
func firstBookAdded() {
|
func firstBookAdded() {
|
||||||
guard let id = ZimMultiReader.sharedInstance.readers.keys.first else {return}
|
guard let id = ZimMultiReader.shared.readers.keys.first else {return}
|
||||||
loadMainPage(id)
|
loadMainPage(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.277</string>
|
<string>1.8.279</string>
|
||||||
<key>ITSAppUsesNonExemptEncryption</key>
|
<key>ITSAppUsesNonExemptEncryption</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.280</string>
|
<string>1.8.282</string>
|
||||||
<key>NSExtension</key>
|
<key>NSExtension</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSExtensionMainStoryboard</key>
|
<key>NSExtensionMainStoryboard</key>
|
||||||
|
@ -57,13 +57,13 @@ class ScanLocalBookOperation: Operation {
|
|||||||
let removedZimFileURLs = lastZimFileURLSnapshot.subtract(currentZimFileURLSnapshot)
|
let removedZimFileURLs = lastZimFileURLSnapshot.subtract(currentZimFileURLSnapshot)
|
||||||
|
|
||||||
guard addedZimFileURLs.count > 0 || removedZimFileURLs.count > 0 else {return}
|
guard addedZimFileURLs.count > 0 || removedZimFileURLs.count > 0 else {return}
|
||||||
ZimMultiReader.sharedInstance.removeReaders(removedZimFileURLs)
|
ZimMultiReader.shared.removeReaders(removedZimFileURLs)
|
||||||
ZimMultiReader.sharedInstance.addReaders(addedZimFileURLs)
|
ZimMultiReader.shared.addReaders(addedZimFileURLs)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateCoreData() {
|
private func updateCoreData() {
|
||||||
let localBooks = Book.fetchLocal(context)
|
let localBooks = Book.fetchLocal(context)
|
||||||
let zimReaderIDs = Set(ZimMultiReader.sharedInstance.readers.keys)
|
let zimReaderIDs = Set(ZimMultiReader.shared.readers.keys)
|
||||||
let addedZimFileIDs = zimReaderIDs.subtract(Set(localBooks.keys))
|
let addedZimFileIDs = zimReaderIDs.subtract(Set(localBooks.keys))
|
||||||
let removedZimFileIDs = Set(localBooks.keys).subtract(zimReaderIDs)
|
let removedZimFileIDs = Set(localBooks.keys).subtract(zimReaderIDs)
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ class ScanLocalBookOperation: Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for id in addedZimFileIDs {
|
for id in addedZimFileIDs {
|
||||||
guard let reader = ZimMultiReader.sharedInstance.readers[id] else {return}
|
guard let reader = ZimMultiReader.shared.readers[id] else {return}
|
||||||
let book: Book? = {
|
let book: Book? = {
|
||||||
let book = Book.fetch(id, context: NSManagedObjectContext.mainQueueContext)
|
let book = Book.fetch(id, context: NSManagedObjectContext.mainQueueContext)
|
||||||
return book ?? Book.add(reader.metaData, context: NSManagedObjectContext.mainQueueContext)
|
return book ?? Book.add(reader.metaData, context: NSManagedObjectContext.mainQueueContext)
|
||||||
@ -89,7 +89,7 @@ class ScanLocalBookOperation: Operation {
|
|||||||
|
|
||||||
for (id, book) in localBooks {
|
for (id, book) in localBooks {
|
||||||
guard !context.deletedObjects.contains(book) else {continue}
|
guard !context.deletedObjects.contains(book) else {continue}
|
||||||
guard let reader = ZimMultiReader.sharedInstance.readers[id] else {return}
|
guard let reader = ZimMultiReader.shared.readers[id] else {return}
|
||||||
book.hasIndex = reader.hasIndex()
|
book.hasIndex = reader.hasIndex()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class SearchOperation: GroupOperation {
|
|||||||
self.results = results
|
self.results = results
|
||||||
}
|
}
|
||||||
|
|
||||||
for (id, zimReader) in ZimMultiReader.sharedInstance.readers {
|
for (id, zimReader) in ZimMultiReader.shared.readers {
|
||||||
let managedObjectContext = UIApplication.appDelegate.managedObjectContext
|
let managedObjectContext = UIApplication.appDelegate.managedObjectContext
|
||||||
guard let book = Book.fetch(id, context: managedObjectContext) else {continue}
|
guard let book = Book.fetch(id, context: managedObjectContext) else {continue}
|
||||||
guard book.includeInSearch else {continue}
|
guard book.includeInSearch else {continue}
|
||||||
|
@ -27,7 +27,7 @@ class KiwixURLProtocol: NSURLProtocol {
|
|||||||
client?.URLProtocol(self, didFailWithError: error)
|
client?.URLProtocol(self, didFailWithError: error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard let dataDic = ZimMultiReader.sharedInstance.data(id, contentURLString: contentURLString),
|
guard let dataDic = ZimMultiReader.shared.data(id, contentURLString: contentURLString),
|
||||||
let data = dataDic["data"] as? NSData,
|
let data = dataDic["data"] as? NSData,
|
||||||
let mimeType = dataDic["mime"] as? String,
|
let mimeType = dataDic["mime"] as? String,
|
||||||
let dataLength = dataDic["length"]?.integerValue else {
|
let dataLength = dataDic["length"]?.integerValue else {
|
||||||
@ -60,7 +60,7 @@ extension NSURL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class func kiwixURLWithZimFileid(id: String, articleTitle: String) -> NSURL? {
|
class func kiwixURLWithZimFileid(id: String, articleTitle: String) -> NSURL? {
|
||||||
guard let contentURLString = ZimMultiReader.sharedInstance.pageURLString(articleTitle, bookid: id) else {
|
guard let contentURLString = ZimMultiReader.shared.pageURLString(articleTitle, bookid: id) else {
|
||||||
print("ZimMultiReader cannot get pageURLString from \(articleTitle) in book \(id)")
|
print("ZimMultiReader cannot get pageURLString from \(articleTitle) in book \(id)")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import CoreData
|
|||||||
import Operations
|
import Operations
|
||||||
|
|
||||||
class ZimMultiReader: NSObject, DirectoryMonitorDelegate {
|
class ZimMultiReader: NSObject, DirectoryMonitorDelegate {
|
||||||
static let sharedInstance = ZimMultiReader()
|
static let shared = ZimMultiReader()
|
||||||
|
|
||||||
weak var delegate: ZimMultiReaderDelegate?
|
weak var delegate: ZimMultiReaderDelegate?
|
||||||
private let monitor = DirectoryMonitor(URL: NSFileManager.docDirURL)
|
private let monitor = DirectoryMonitor(URL: NSFileManager.docDirURL)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user