Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
Replace SQLite.swift with GRDB and use Combine for asynchronous code (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu authored Aug 20, 2021
1 parent c13d161 commit 43367fc
Show file tree
Hide file tree
Showing 52 changed files with 1,024 additions and 1,213 deletions.
6 changes: 0 additions & 6 deletions Integrations/Carthage/Cartfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Third-party dependencies used in the Test App itself.
github "onevcat/Kingfisher" ~> 5.15.8
github "jdg/MBProgressHUD" ~> 1.2.0
github "stephencelis/SQLite.swift" ~> 0.12.2
github "scinfu/SwiftSoup" ~> 2.3.2

# Readium 2 dependencies
github "readium/r2-shared-swift" "develop"
github "readium/r2-streamer-swift" "develop"
Expand Down
6 changes: 0 additions & 6 deletions Integrations/Carthage/Cartfile+lcp
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Third-party dependencies used in the Test App itself.
github "onevcat/Kingfisher" ~> 5.15.8
github "jdg/MBProgressHUD" ~> 1.2.0
github "stephencelis/SQLite.swift" ~> 0.12.2
github "scinfu/SwiftSoup" ~> 2.3.2

# Readium 2 dependencies
github "readium/r2-shared-swift" "develop"
github "readium/r2-streamer-swift" "develop"
Expand Down
17 changes: 14 additions & 3 deletions Integrations/Carthage/project+lcp.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
name: R2TestApp
options:
bundleIdPrefix: org.readium
packages:
GRDB:
url: https://github.com/groue/GRDB.swift.git
from: 5.8.0
Kingfisher:
url: https://github.com/onevcat/Kingfisher.git
from: 5.15.8
MBProgressHUD:
url: https://github.com/jdg/MBProgressHUD.git
from: 1.2.0
targets:
R2TestApp:
type: application
platform: iOS
deploymentTarget: "10.0"
deploymentTarget: "13.6"
sources:
- path: Sources
excludes:
Expand All @@ -17,8 +27,6 @@ targets:
- framework: Carthage/Build/CryptoSwift.xcframework
- framework: Carthage/Build/Fuzi.xcframework
- framework: Carthage/Build/GCDWebServer.xcframework
- framework: Carthage/Build/Kingfisher.xcframework
- framework: Carthage/Build/MBProgressHUD.xcframework
- framework: Carthage/Build/Minizip.xcframework
- framework: Carthage/Build/R2Navigator.xcframework
- framework: Carthage/Build/R2Shared.xcframework
Expand All @@ -28,6 +36,9 @@ targets:
- framework: Carthage/Build/SQLite.xcframework
- framework: Carthage/Build/SwiftSoup.xcframework
- framework: Carthage/Build/ZIPFoundation.xcframework
- package: GRDB
- package: Kingfisher
- package: MBProgressHUD
settings:
LIBRARY_SEARCH_PATHS: $(PROJECT_DIR)/Carthage
OTHER_SWIFT_FLAGS: -DLCP
18 changes: 14 additions & 4 deletions Integrations/Carthage/project.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
name: R2TestApp
options:
bundleIdPrefix: org.readium
packages:
GRDB:
url: https://github.com/groue/GRDB.swift.git
from: 5.8.0
Kingfisher:
url: https://github.com/onevcat/Kingfisher.git
from: 5.15.8
MBProgressHUD:
url: https://github.com/jdg/MBProgressHUD.git
from: 1.2.0
targets:
R2TestApp:
type: application
platform: iOS
deploymentTarget: "10.0"
deploymentTarget: "13.6"
sources:
- path: Sources
excludes:
Expand All @@ -16,14 +26,14 @@ targets:
- framework: Carthage/Build/CryptoSwift.xcframework
- framework: Carthage/Build/Fuzi.xcframework
- framework: Carthage/Build/GCDWebServer.xcframework
- framework: Carthage/Build/Kingfisher.xcframework
- framework: Carthage/Build/MBProgressHUD.xcframework
- framework: Carthage/Build/Minizip.xcframework
- framework: Carthage/Build/R2Navigator.xcframework
- framework: Carthage/Build/R2Shared.xcframework
- framework: Carthage/Build/R2Streamer.xcframework
- framework: Carthage/Build/ReadiumOPDS.xcframework
- framework: Carthage/Build/SQLite.xcframework
- framework: Carthage/Build/SwiftSoup.xcframework
- package: GRDB
- package: Kingfisher
- package: MBProgressHUD
settings:
LIBRARY_SEARCH_PATHS: $(PROJECT_DIR)/Carthage
2 changes: 1 addition & 1 deletion Integrations/CocoaPods/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ target 'R2TestApp' do
pod 'ReadiumLCP', podspec: 'https://raw.githubusercontent.com/readium/r2-lcp-swift/develop/ReadiumLCP.podspec'

pod 'GCDWebServer', podspec: 'https://raw.githubusercontent.com/readium/GCDWebServer/3.6.3/GCDWebServer.podspec'
pod 'GRDB.swift'
pod 'Kingfisher'
pod 'MBProgressHUD'
pod 'SQLite.swift'
pod 'SwiftSoup'
end

Expand Down
2 changes: 1 addition & 1 deletion Integrations/CocoaPods/Podfile+lcp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ target 'R2TestApp' do
pod 'R2LCPClient', podspec: 'LCP_URL'

pod 'GCDWebServer', podspec: 'https://raw.githubusercontent.com/readium/GCDWebServer/3.6.3/GCDWebServer.podspec'
pod 'GRDB.swift'
pod 'Kingfisher'
pod 'MBProgressHUD'
pod 'SQLite.swift'
pod 'SwiftSoup'
end

Expand Down
2 changes: 1 addition & 1 deletion Integrations/CocoaPods/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ targets:
R2TestApp:
type: application
platform: iOS
deploymentTarget: "10.0"
deploymentTarget: "13.6"
sources:
- path: Sources
excludes:
Expand Down
2 changes: 1 addition & 1 deletion Integrations/CocoaPods/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ targets:
R2TestApp:
type: application
platform: iOS
deploymentTarget: "10.0"
deploymentTarget: "13.6"
sources:
- path: Sources
excludes:
Expand Down
10 changes: 5 additions & 5 deletions Integrations/SPM/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ packages:
ReadiumLCP:
url: https://github.com/readium/r2-lcp-swift.git
branch: develop
GRDB:
url: https://github.com/groue/GRDB.swift.git
from: 5.8.0
Kingfisher:
url: https://github.com/onevcat/Kingfisher.git
from: 5.15.8
Expand All @@ -26,14 +29,11 @@ packages:
SwiftSoup:
url: https://github.com/scinfu/SwiftSoup.git
from: 2.3.2
SQLite:
url: https://github.com/stephencelis/SQLite.swift.git
from: 0.12.2
targets:
R2TestApp:
type: application
platform: iOS
deploymentTarget: "10.0"
deploymentTarget: "13.6"
sources:
- path: Sources
excludes:
Expand All @@ -47,10 +47,10 @@ targets:
- package: R2Navigator
- package: ReadiumOPDS
- package: ReadiumLCP
- package: GRDB
- package: Kingfisher
- package: MBProgressHUD
- package: SwiftSoup
- package: SQLite
settings:
OTHER_SWIFT_FLAGS: -DLCP

11 changes: 5 additions & 6 deletions Integrations/SPM/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ packages:
ReadiumOPDS:
url: https://github.com/readium/r2-opds-swift.git
branch: develop
GRDB:
url: https://github.com/groue/GRDB.swift.git
from: 5.8.0
Kingfisher:
url: https://github.com/onevcat/Kingfisher.git
from: 5.15.8
Expand All @@ -23,14 +26,11 @@ packages:
SwiftSoup:
url: https://github.com/scinfu/SwiftSoup.git
from: 2.3.2
SQLite:
url: https://github.com/stephencelis/SQLite.swift.git
from: 0.12.2
targets:
R2TestApp:
type: application
platform: iOS
deploymentTarget: "10.0"
deploymentTarget: "13.6"
sources:
- path: Sources
excludes:
Expand All @@ -42,8 +42,7 @@ targets:
- package: R2Streamer
- package: R2Navigator
- package: ReadiumOPDS
- package: GRDB
- package: Kingfisher
- package: MBProgressHUD
- package: SwiftSoup
- package: SQLite

10 changes: 5 additions & 5 deletions Integrations/Submodules/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ packages:
path: Integrations/Submodules/r2-opds-swift
ReadiumLCP:
path: Integrations/Submodules/r2-lcp-swift
GRDB:
url: https://github.com/groue/GRDB.swift.git
from: 5.8.0
Kingfisher:
url: https://github.com/onevcat/Kingfisher.git
from: 5.15.8
Expand All @@ -21,14 +24,11 @@ packages:
SwiftSoup:
url: https://github.com/scinfu/SwiftSoup.git
from: 2.3.2
SQLite:
url: https://github.com/stephencelis/SQLite.swift.git
from: 0.12.2
targets:
R2TestApp:
type: application
platform: iOS
deploymentTarget: "10.0"
deploymentTarget: "13.6"
sources:
- path: Sources
excludes:
Expand All @@ -42,9 +42,9 @@ targets:
- package: R2Navigator
- package: ReadiumOPDS
- package: ReadiumLCP
- package: GRDB
- package: Kingfisher
- package: MBProgressHUD
- package: SwiftSoup
- package: SQLite
settings:
OTHER_SWIFT_FLAGS: -DLCP
10 changes: 5 additions & 5 deletions Integrations/Submodules/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ packages:
path: Integrations/Submodules/r2-navigator-swift
ReadiumOPDS:
path: Integrations/Submodules/r2-opds-swift
GRDB:
url: https://github.com/groue/GRDB.swift.git
from: 5.8.0
Kingfisher:
url: https://github.com/onevcat/Kingfisher.git
from: 5.15.8
Expand All @@ -19,14 +22,11 @@ packages:
SwiftSoup:
url: https://github.com/scinfu/SwiftSoup.git
from: 2.3.2
SQLite:
url: https://github.com/stephencelis/SQLite.swift.git
from: 0.12.2
targets:
R2TestApp:
type: application
platform: iOS
deploymentTarget: "10.0"
deploymentTarget: "13.6"
sources:
- path: Sources
excludes:
Expand All @@ -38,7 +38,7 @@ targets:
- package: R2Streamer
- package: R2Navigator
- package: ReadiumOPDS
- package: GRDB
- package: Kingfisher
- package: MBProgressHUD
- package: SwiftSoup
- package: SQLite
22 changes: 13 additions & 9 deletions Sources/App/AppModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// LICENSE file present in the project repository where this source code is maintained.
//

import Combine
import Foundation
import UIKit
import R2Shared
Expand Down Expand Up @@ -40,14 +41,19 @@ final class AppModule {
fatalError("Can't start publication server")
}

library = LibraryModule(delegate: self, server: server)
reader = ReaderModule(delegate: self, resourcesServer: server)
let httpClient = DefaultHTTPClient()
let db = try Database(file: Paths.library.appendingPathComponent("database.db"))
let books = BookRepository(db: db)
let bookmarks = BookmarkRepository(db: db)

library = LibraryModule(delegate: self, books: books, server: server, httpClient: httpClient)
reader = ReaderModule(delegate: self, books: books, bookmarks: bookmarks, resourcesServer: server)
opds = OPDSModule(delegate: self)

// Set Readium 2's logging minimum level.
R2EnableLog(withMinimumSeverityLevel: .debug)

try library.preloadSamples()
library.preloadSamples()
}

private(set) lazy var aboutViewController: UIViewController = {
Expand All @@ -70,6 +76,7 @@ extension AppModule: ModuleDelegate {

func presentError(_ error: Error?, from viewController: UIViewController) {
guard let error = error else { return }
if case LibraryError.cancelled = error { return }
presentAlert(
NSLocalizedString("error_title", comment: "Alert title for errors"),
message: error.localizedDescription,
Expand All @@ -95,15 +102,12 @@ extension AppModule: ReaderModuleDelegate {

extension AppModule: OPDSModuleDelegate {

func opdsDownloadPublication(_ publication: Publication?, at link: Link, sender: UIViewController, completion: @escaping (CancellableResult<Book, Error>) -> ()) {
func opdsDownloadPublication(_ publication: Publication?, at link: Link, sender: UIViewController) -> AnyPublisher<Book, LibraryError> {
guard let url = link.url(relativeTo: publication?.baseURL) else {
completion(.cancelled)
return
return .fail(.cancelled)
}

library.importPublication(from: url, title: publication?.metadata.title, sender: sender) {
completion($0.eraseToAnyError())
}
return library.importPublication(from: url, sender: sender)
}

}
5 changes: 5 additions & 0 deletions Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// LICENSE file present in the project repository where this source code is maintained.
//

import Combine
import UIKit

@UIApplicationMain
Expand All @@ -18,6 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

private var app: AppModule!
private var subscriptions = Set<AnyCancellable>()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
app = try! AppModule()
Expand Down Expand Up @@ -60,6 +62,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
app.library.importPublication(from: url, sender: window!.rootViewController!)
.assertNoFailure()
.sink { _ in }
.store(in: &subscriptions)
return true
}

Expand Down
Loading

0 comments on commit 43367fc

Please sign in to comment.