mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-25 21:05:09 -04:00
commit
This commit is contained in:
parent
a8ef99a8da
commit
57ab32c482
@ -61,6 +61,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||
URLProtocol.registerClass(KiwixURLProtocol)
|
||||
|
||||
let op = RefreshLibrary()
|
||||
GlobalQueue.shared.add(operation: op)
|
||||
|
||||
// Network.shared
|
||||
|
||||
// Register notification
|
||||
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.2036</string>
|
||||
<string>1.8.2097</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.2036</string>
|
||||
<string>1.8.2097</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
@ -44,6 +44,8 @@
|
||||
973208231DD19C7600EDD3DC /* DownloadProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9726591A1D8DB91200D1DFFB /* DownloadProgress.swift */; };
|
||||
973208241DD217B600EDD3DC /* BookmarkHUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97219DBC1D383A00009FDFF1 /* BookmarkHUD.swift */; };
|
||||
973208261DD21E9C00EDD3DC /* CoreDataContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973208251DD21E9C00EDD3DC /* CoreDataContainer.swift */; };
|
||||
973208271DD2238B00EDD3DC /* GlobalQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D6811C1D6F70AC00E5FA99 /* GlobalQueue.swift */; };
|
||||
973208291DD223DB00EDD3DC /* RefreshLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973208281DD223DB00EDD3DC /* RefreshLibrary.swift */; };
|
||||
9734E54E1D289D060061C39B /* Welcome.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9734E54D1D289D060061C39B /* Welcome.storyboard */; };
|
||||
973BCD1A1CEB402900F10B44 /* KiwixTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973BCD181CEB402900F10B44 /* KiwixTests.swift */; };
|
||||
973DD40F1D343F2F009D45DB /* libicudata.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD4041D343F2F009D45DB /* libicudata.a */; };
|
||||
@ -188,6 +190,7 @@
|
||||
9726591C1D90A64500D1DFFB /* Notifications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; };
|
||||
9732075B1DD136BB00EDD3DC /* CoreDataExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataExtension.swift; sourceTree = "<group>"; };
|
||||
973208251DD21E9C00EDD3DC /* CoreDataContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataContainer.swift; sourceTree = "<group>"; };
|
||||
973208281DD223DB00EDD3DC /* RefreshLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RefreshLibrary.swift; sourceTree = "<group>"; };
|
||||
9734E54D1D289D060061C39B /* Welcome.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Welcome.storyboard; path = "Kiwix-iOS/Storyboard/Welcome.storyboard"; sourceTree = SOURCE_ROOT; };
|
||||
973BCD001CEB3FA500F10B44 /* Kiwix_OSXTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Kiwix_OSXTests.swift; sourceTree = "<group>"; };
|
||||
973BCD021CEB3FA500F10B44 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
@ -759,10 +762,11 @@
|
||||
97E5712A1CA0525300FF4F1D /* Operation */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
97D6811C1D6F70AC00E5FA99 /* GlobalQueue.swift */,
|
||||
9764CBD21D8083AA00072D6A /* ArticleOperation.swift */,
|
||||
974F33C51D99CAD700879D35 /* BookmarkOperation.swift */,
|
||||
97DF259B1D6F7612001648A3 /* BookOperation.swift */,
|
||||
97D6811C1D6F70AC00E5FA99 /* GlobalQueue.swift */,
|
||||
973208281DD223DB00EDD3DC /* RefreshLibrary.swift */,
|
||||
97D6811D1D6F70AC00E5FA99 /* RefreshLibraryOperation.swift */,
|
||||
97D6811E1D6F70AC00E5FA99 /* ScanLocalBookOperation.swift */,
|
||||
97D4D64E1D874E6E00C1B065 /* SearchOperation.swift */,
|
||||
@ -1114,6 +1118,7 @@
|
||||
971A102E1D022AD5007FC62C /* TableViewCells.swift in Sources */,
|
||||
97E60A021D10423A00EBCB9D /* ShadowViews.swift in Sources */,
|
||||
970E68BA1D3809A3001E8514 /* MainController.swift in Sources */,
|
||||
973208291DD223DB00EDD3DC /* RefreshLibrary.swift in Sources */,
|
||||
97D6813A1D6F711A00E5FA99 /* Language.swift in Sources */,
|
||||
970E7F791DA003FA00741290 /* WebViewController.swift in Sources */,
|
||||
97D681401D6F712800E5FA99 /* Book+CoreDataProperties.swift in Sources */,
|
||||
@ -1158,6 +1163,7 @@
|
||||
97A1FD441D6F728200A80EE2 /* Preference.swift in Sources */,
|
||||
97D681311D6F70EC00E5FA99 /* 1.5.xcmappingmodel in Sources */,
|
||||
9732075C1DD136BB00EDD3DC /* CoreDataExtension.swift in Sources */,
|
||||
973208271DD2238B00EDD3DC /* GlobalQueue.swift in Sources */,
|
||||
97A1FD181D6F71CE00A80EE2 /* SearchResult.swift in Sources */,
|
||||
973207A11DD1983D00EDD3DC /* LocalBooksController.swift in Sources */,
|
||||
973DD4281D36E3E4009D45DB /* SettingDetailController.swift in Sources */,
|
||||
|
@ -12,63 +12,37 @@ class GlobalQueue: ProcedureQueue {
|
||||
static let shared = GlobalQueue()
|
||||
|
||||
// Fix: use specific class type
|
||||
fileprivate weak var scanOperation: Procedure?
|
||||
fileprivate weak var searchOperation: Procedure?
|
||||
fileprivate weak var articleLoadOperation: ArticleLoadOperation?
|
||||
// private weak var scanOperation: Procedure?
|
||||
// private weak var searchOperation: Procedure?
|
||||
// private weak var articleLoadOperation: ArticleLoadOperation?
|
||||
|
||||
func add(scan operation: Procedure) {
|
||||
addOperation(operation)
|
||||
scanOperation = operation
|
||||
}
|
||||
|
||||
func add(search operation: Procedure) {
|
||||
if let scanOperation = scanOperation {
|
||||
operation.addDependency(scanOperation)
|
||||
}
|
||||
|
||||
if let searchOperation = self.searchOperation {
|
||||
searchOperation.cancel()
|
||||
}
|
||||
addOperation(operation)
|
||||
searchOperation = operation
|
||||
}
|
||||
|
||||
func add(load operation: ArticleLoadOperation) {
|
||||
if let scanOperation = scanOperation {
|
||||
operation.addDependency(scanOperation)
|
||||
}
|
||||
|
||||
if let articleLoadOperation = self.articleLoadOperation {
|
||||
operation.addDependency(articleLoadOperation)
|
||||
}
|
||||
|
||||
addOperation(operation)
|
||||
articleLoadOperation = operation
|
||||
}
|
||||
}
|
||||
|
||||
public enum OperationErrorCode: Int {
|
||||
case conditionFailed = 1
|
||||
case executionFailed = 2
|
||||
|
||||
// Error that should be reported to user
|
||||
case networkError
|
||||
case serverNameInvalid
|
||||
case authError
|
||||
case accessRevoked
|
||||
case unreachable
|
||||
case lackOfValue
|
||||
case unexpectedError
|
||||
}
|
||||
//
|
||||
//extension OperationQueue {
|
||||
// // Oneday should be replaced with ExclusivityController
|
||||
// func getOperation(_ id: String) -> Operation? {
|
||||
// for operation in operations {
|
||||
// guard operation.name == id else {continue}
|
||||
// guard let operation = operation as? Operation else {continue}
|
||||
// return operation
|
||||
// }
|
||||
// return nil
|
||||
// func add(scan operation: Procedure) {
|
||||
// addOperation(operation)
|
||||
// scanOperation = operation
|
||||
// }
|
||||
//}
|
||||
//
|
||||
// func add(search operation: Procedure) {
|
||||
// if let scanOperation = scanOperation {
|
||||
// operation.addDependency(scanOperation)
|
||||
// }
|
||||
//
|
||||
// if let searchOperation = self.searchOperation {
|
||||
// searchOperation.cancel()
|
||||
// }
|
||||
// addOperation(operation)
|
||||
// searchOperation = operation
|
||||
// }
|
||||
//
|
||||
// func add(load operation: ArticleLoadOperation) {
|
||||
// if let scanOperation = scanOperation {
|
||||
// operation.addDependency(scanOperation)
|
||||
// }
|
||||
//
|
||||
// if let articleLoadOperation = self.articleLoadOperation {
|
||||
// operation.addDependency(articleLoadOperation)
|
||||
// }
|
||||
//
|
||||
// addOperation(operation)
|
||||
// articleLoadOperation = operation
|
||||
// }
|
||||
}
|
||||
|
63
Kiwix/Operations/RefreshLibrary.swift
Normal file
63
Kiwix/Operations/RefreshLibrary.swift
Normal file
@ -0,0 +1,63 @@
|
||||
//
|
||||
// RefreshLibrary.swift
|
||||
// Kiwix
|
||||
//
|
||||
// Created by Chris Li on 11/8/16.
|
||||
// Copyright © 2016 Wikimedia CH. All rights reserved.
|
||||
//
|
||||
|
||||
import ProcedureKit
|
||||
|
||||
class RefreshLibrary: GroupProcedure {
|
||||
|
||||
init() {
|
||||
let retrieve = Retrieve()
|
||||
let process = Process()
|
||||
process.injectResult(from: retrieve)
|
||||
super.init(operations: [retrieve, process])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class Retrieve: NetworkDataProcedure<URLSession> {
|
||||
|
||||
init() {
|
||||
let session = URLSession.shared
|
||||
let url = URL(string: "https://download.kiwix.org/library/library.xml")!
|
||||
let request = URLRequest(url: url)
|
||||
super.init(session: session, request: request)
|
||||
}
|
||||
}
|
||||
|
||||
private class Process: Procedure, ResultInjection, XMLParserDelegate {
|
||||
var requirement: PendingValue<HTTPResult<Data>> = .pending
|
||||
var result: PendingValue<Void> = .void
|
||||
|
||||
override func execute() {
|
||||
guard let data = requirement.value?.payload else {
|
||||
finish(withError: ProcedureKitError.requirementNotSatisfied())
|
||||
return
|
||||
}
|
||||
let parser = XMLParser(data: data)
|
||||
parser.delegate = self
|
||||
parser.parse()
|
||||
|
||||
finish()
|
||||
}
|
||||
|
||||
func parserDidStartDocument(_ parser: XMLParser) {
|
||||
// let ids = Book.fetch(all: <#T##NSManagedObjectContext#>)
|
||||
}
|
||||
|
||||
func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) {
|
||||
print(attributeDict["id"])
|
||||
}
|
||||
|
||||
func parserDidEndDocument(_ parser: XMLParser) {
|
||||
|
||||
}
|
||||
|
||||
func parser(_ parser: XMLParser, parseErrorOccurred parseError: Error) {
|
||||
|
||||
}
|
||||
}
|
@ -48,7 +48,7 @@ private class Retrieve: Procedure, ResultInjection {
|
||||
|
||||
fileprivate override func execute() {
|
||||
guard !isCancelled else {return}
|
||||
let task = URLSession.shared.dataTask(with: Retrieve.url, completionHandler: { (data, response, error) in
|
||||
let task = URLSession.shared.dataTask(with: Re`trieve.url, completionHandler: { (data, response, error) in
|
||||
self.result = data
|
||||
self.finish()
|
||||
})
|
||||
|
1
Podfile
1
Podfile
@ -9,5 +9,6 @@ pod 'DZNEmptyDataSet'
|
||||
pod 'MBProgressHUD', '~> 1.0.0'
|
||||
pod 'SwiftyUserDefaults'
|
||||
pod 'ProcedureKit', :git => 'https://github.com/ProcedureKit/ProcedureKit.git', :branch => 'release/4.0.0.beta.4'
|
||||
pod 'ProcedureKit/Network', :git => 'https://github.com/ProcedureKit/ProcedureKit.git', :branch => 'release/4.0.0.beta.4'
|
||||
|
||||
end
|
@ -3,6 +3,8 @@ PODS:
|
||||
- MBProgressHUD (1.0.0)
|
||||
- ProcedureKit (4.0.0.beta.4):
|
||||
- ProcedureKit/Standard (= 4.0.0.beta.4)
|
||||
- ProcedureKit/Network (4.0.0.beta.4):
|
||||
- ProcedureKit/Standard
|
||||
- ProcedureKit/Standard (4.0.0.beta.4)
|
||||
- SwiftyUserDefaults (3.0.0)
|
||||
|
||||
@ -10,6 +12,7 @@ DEPENDENCIES:
|
||||
- DZNEmptyDataSet
|
||||
- MBProgressHUD (~> 1.0.0)
|
||||
- ProcedureKit (from `https://github.com/ProcedureKit/ProcedureKit.git`, branch `release/4.0.0.beta.4`)
|
||||
- ProcedureKit/Network (from `https://github.com/ProcedureKit/ProcedureKit.git`, branch `release/4.0.0.beta.4`)
|
||||
- SwiftyUserDefaults
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
@ -28,6 +31,6 @@ SPEC CHECKSUMS:
|
||||
ProcedureKit: 9160071e54e3885fad82f72acc8474366c764f5b
|
||||
SwiftyUserDefaults: 0f1d45fc3aafb9064dac661e367f8f83fe21a4b4
|
||||
|
||||
PODFILE CHECKSUM: 3a6500d8c36bc65c0475e02525c34c847c978e18
|
||||
PODFILE CHECKSUM: 2a43cf5fd02fa27c74c7964ae4d60a691552505d
|
||||
|
||||
COCOAPODS: 1.0.1
|
||||
|
Loading…
x
Reference in New Issue
Block a user