mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-05 02:25:45 +02:00
Convert remain NSLog statement to new logging framework
This commit is contained in:
parent
f8836be147
commit
7a68cc99af
9 changed files with 95 additions and 80 deletions
|
@ -4,6 +4,8 @@ import RealmSwift
|
|||
|
||||
@UIApplicationMain
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
private let logger = AppLogger(category: "AppDelegate")
|
||||
|
||||
var window: UIWindow?
|
||||
var backgroundCompletionHandler: (() -> Void)?
|
||||
|
@ -13,15 +15,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
|
||||
let configuration = Realm.Configuration(
|
||||
schemaVersion: 4,
|
||||
migrationBlock: { migration, oldSchemaVersion in
|
||||
migrationBlock: { [weak self] migration, oldSchemaVersion in
|
||||
if (oldSchemaVersion < 1) {
|
||||
NSLog("Realm schema version was \(oldSchemaVersion)")
|
||||
self?.logger.log("Realm schema version was \(oldSchemaVersion)")
|
||||
migration.enumerateObjects(ofType: DeviceSettings.className()) { oldObject, newObject in
|
||||
newObject?["enableAltView"] = false
|
||||
}
|
||||
}
|
||||
if (oldSchemaVersion < 4) {
|
||||
NSLog("Realm schema version was \(oldSchemaVersion)... Reindexing server configs")
|
||||
self?.logger.log("Realm schema version was \(oldSchemaVersion)... Reindexing server configs")
|
||||
var indexCounter = 1
|
||||
migration.enumerateObjects(ofType: ServerConnectionConfig.className()) { oldObject, newObject in
|
||||
newObject?["index"] = indexCounter
|
||||
|
@ -43,22 +45,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
func applicationDidEnterBackground(_ application: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
NSLog("Audiobookself is now in the background")
|
||||
logger.log("Audiobookself is now in the background")
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
|
||||
NSLog("Audiobookself is now in the foreground")
|
||||
logger.log("Audiobookself is now in the foreground")
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(_ application: UIApplication) {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
NSLog("Audiobookself is now active")
|
||||
logger.log("Audiobookself is now active")
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
NSLog("Audiobookself is terminating")
|
||||
logger.log("Audiobookself is terminating")
|
||||
}
|
||||
|
||||
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
|
||||
|
|
|
@ -11,6 +11,8 @@ import RealmSwift
|
|||
|
||||
@objc(AbsAudioPlayer)
|
||||
public class AbsAudioPlayer: CAPPlugin {
|
||||
private let logger = AppLogger(category: "AbsAudioPlayer")
|
||||
|
||||
private var initialPlayWhenReady = false
|
||||
private var isUIReady = false
|
||||
|
||||
|
@ -46,7 +48,7 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||
try self.startPlaybackSession(activeSession, playWhenReady: false, playbackRate: PlayerSettings.main().playbackRate)
|
||||
}
|
||||
} catch {
|
||||
NSLog("Failed to restore playback session")
|
||||
logger.error("Failed to restore playback session")
|
||||
debugPrint(error)
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +69,7 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||
let playbackRate = call.getFloat("playbackRate", 1)
|
||||
|
||||
if libraryItemId == nil {
|
||||
NSLog("provide library item id")
|
||||
logger.error("provide library item id")
|
||||
return call.resolve()
|
||||
}
|
||||
|
||||
|
@ -78,7 +80,7 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||
let item = Database.shared.getLocalLibraryItem(localLibraryItemId: libraryItemId!)
|
||||
let episode = item?.getPodcastEpisode(episodeId: episodeId)
|
||||
guard let playbackSession = item?.getPlaybackSession(episode: episode) else {
|
||||
NSLog("Failed to get local playback session")
|
||||
logger.error("Failed to get local playback session")
|
||||
return call.resolve([:])
|
||||
}
|
||||
|
||||
|
@ -87,18 +89,18 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||
try self.startPlaybackSession(playbackSession, playWhenReady: playWhenReady, playbackRate: playbackRate)
|
||||
call.resolve(try playbackSession.asDictionary())
|
||||
} catch(let exception) {
|
||||
NSLog("Failed to start session")
|
||||
logger.error("Failed to start session")
|
||||
debugPrint(exception)
|
||||
call.resolve([:])
|
||||
}
|
||||
} else { // Playing from the server
|
||||
ApiClient.startPlaybackSession(libraryItemId: libraryItemId!, episodeId: episodeId, forceTranscode: false) { session in
|
||||
ApiClient.startPlaybackSession(libraryItemId: libraryItemId!, episodeId: episodeId, forceTranscode: false) { [weak self] session in
|
||||
do {
|
||||
try session.save()
|
||||
try self.startPlaybackSession(session, playWhenReady: playWhenReady, playbackRate: playbackRate)
|
||||
try self?.startPlaybackSession(session, playWhenReady: playWhenReady, playbackRate: playbackRate)
|
||||
call.resolve(try session.asDictionary())
|
||||
} catch(let exception) {
|
||||
NSLog("Failed to start session")
|
||||
self?.logger.error("Failed to start session")
|
||||
debugPrint(exception)
|
||||
call.resolve([:])
|
||||
}
|
||||
|
@ -107,7 +109,7 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||
}
|
||||
|
||||
@objc func closePlayback(_ call: CAPPluginCall) {
|
||||
NSLog("Close playback")
|
||||
logger.log("Close playback")
|
||||
|
||||
PlayerHandler.stopPlayback()
|
||||
call.resolve()
|
||||
|
@ -193,7 +195,7 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||
|
||||
let seconds = time / 1000
|
||||
|
||||
NSLog("chapter time: \(isChapterTime)")
|
||||
logger.log("chapter time: \(isChapterTime)")
|
||||
if isChapterTime {
|
||||
PlayerHandler.setChapterSleepTime(stopAt: seconds)
|
||||
return call.resolve([ "success": true ])
|
||||
|
@ -230,7 +232,7 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||
guard let localMediaProgressId = PlayerHandler.getPlaybackSession()?.localMediaProgressId else { return }
|
||||
guard let localMediaProgress = Database.shared.getLocalMediaProgress(localMediaProgressId: localMediaProgressId) else { return }
|
||||
guard let progressUpdate = try? localMediaProgress.asDictionary() else { return }
|
||||
NSLog("Sending local progress back to the UI")
|
||||
logger.log("Sending local progress back to the UI")
|
||||
self.notifyListeners("onLocalMediaProgressUpdate", data: progressUpdate)
|
||||
}
|
||||
|
||||
|
@ -239,17 +241,18 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||
let session = PlayerHandler.getPlaybackSession()
|
||||
let libraryItemId = session?.libraryItemId ?? ""
|
||||
let episodeId = session?.episodeId ?? nil
|
||||
NSLog("Forcing Transcode")
|
||||
logger.log("Forcing Transcode")
|
||||
|
||||
// If direct playing then fallback to transcode
|
||||
ApiClient.startPlaybackSession(libraryItemId: libraryItemId, episodeId: episodeId, forceTranscode: true) { session in
|
||||
ApiClient.startPlaybackSession(libraryItemId: libraryItemId, episodeId: episodeId, forceTranscode: true) { [weak self] session in
|
||||
do {
|
||||
guard let self = self else { return }
|
||||
try session.save()
|
||||
PlayerHandler.startPlayback(sessionId: session.id, playWhenReady: self.initialPlayWhenReady, playbackRate: PlayerSettings.main().playbackRate)
|
||||
self.sendPlaybackSession(session: try session.asDictionary())
|
||||
self.sendMetadata()
|
||||
} catch(let exception) {
|
||||
NSLog("Failed to start transcoded session")
|
||||
self?.logger.error("Failed to start transcoded session")
|
||||
debugPrint(exception)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ extension String {
|
|||
|
||||
@objc(AbsDatabase)
|
||||
public class AbsDatabase: CAPPlugin {
|
||||
private let logger = AppLogger(category: "AbsDatabase")
|
||||
|
||||
@objc func setCurrentServerConnectionConfig(_ call: CAPPluginCall) {
|
||||
var id = call.getString("id")
|
||||
let address = call.getString("address", "")
|
||||
|
@ -82,7 +84,7 @@ public class AbsDatabase: CAPPlugin {
|
|||
let items = Database.shared.getLocalLibraryItems()
|
||||
call.resolve([ "value": try items.asDictionaryArray()])
|
||||
} catch(let exception) {
|
||||
NSLog("error while readling local library items")
|
||||
logger.error("error while readling local library items")
|
||||
debugPrint(exception)
|
||||
call.resolve()
|
||||
}
|
||||
|
@ -98,7 +100,7 @@ public class AbsDatabase: CAPPlugin {
|
|||
call.resolve()
|
||||
}
|
||||
} catch(let exception) {
|
||||
NSLog("error while readling local library items")
|
||||
logger.error("error while readling local library items")
|
||||
debugPrint(exception)
|
||||
call.resolve()
|
||||
}
|
||||
|
@ -114,7 +116,7 @@ public class AbsDatabase: CAPPlugin {
|
|||
call.resolve()
|
||||
}
|
||||
} catch(let exception) {
|
||||
NSLog("error while readling local library items")
|
||||
logger.error("error while readling local library items")
|
||||
debugPrint(exception)
|
||||
call.resolve()
|
||||
}
|
||||
|
@ -128,7 +130,7 @@ public class AbsDatabase: CAPPlugin {
|
|||
do {
|
||||
call.resolve([ "value": try Database.shared.getAllLocalMediaProgress().asDictionaryArray() ])
|
||||
} catch {
|
||||
NSLog("Error while loading local media progress")
|
||||
logger.error("Error while loading local media progress")
|
||||
debugPrint(error)
|
||||
call.resolve(["value": []])
|
||||
}
|
||||
|
@ -178,7 +180,7 @@ public class AbsDatabase: CAPPlugin {
|
|||
return
|
||||
}
|
||||
|
||||
NSLog("syncServerMediaProgressWithLocalMediaProgress: Saving local media progress")
|
||||
logger.log("syncServerMediaProgressWithLocalMediaProgress: Saving local media progress")
|
||||
try localMediaProgress.updateFromServerMediaProgress(serverMediaProgress)
|
||||
|
||||
call.resolve(try localMediaProgress.asDictionary())
|
||||
|
@ -194,7 +196,7 @@ public class AbsDatabase: CAPPlugin {
|
|||
let localMediaProgressId = call.getString("localMediaProgressId")
|
||||
let isFinished = call.getBool("isFinished", false)
|
||||
|
||||
NSLog("updateLocalMediaProgressFinished \(localMediaProgressId ?? "Unknown") | Is Finished: \(isFinished)")
|
||||
logger.log("updateLocalMediaProgressFinished \(localMediaProgressId ?? "Unknown") | Is Finished: \(isFinished)")
|
||||
|
||||
do {
|
||||
let localMediaProgress = try LocalMediaProgress.fetchOrCreateLocalMediaProgress(localMediaProgressId: localMediaProgressId, localLibraryItemId: localLibraryItemId, localEpisodeId: localEpisodeId)
|
||||
|
|
|
@ -14,6 +14,8 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
|||
|
||||
static private let downloadsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
||||
|
||||
private let logger = AppLogger(category: "AbsDownloader")
|
||||
|
||||
private lazy var session: URLSession = {
|
||||
let config = URLSessionConfiguration.background(withIdentifier: "AbsDownloader")
|
||||
let queue = OperationQueue()
|
||||
|
@ -94,7 +96,7 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
|||
private func handleDownloadTaskUpdate(downloadTask: URLSessionTask, progressHandler: DownloadProgressHandler) {
|
||||
do {
|
||||
guard let downloadItemPartId = downloadTask.taskDescription else { throw LibraryItemDownloadError.noTaskDescription }
|
||||
NSLog("Received download update for \(downloadItemPartId)")
|
||||
logger.log("Received download update for \(downloadItemPartId)")
|
||||
|
||||
// Find the download item
|
||||
let downloadItem = Database.shared.getDownloadItem(downloadItemPartId: downloadItemPartId)
|
||||
|
@ -108,7 +110,7 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
|||
do {
|
||||
try progressHandler(downloadItem, part)
|
||||
} catch {
|
||||
NSLog("Error while processing progress")
|
||||
logger.error("Error while processing progress")
|
||||
debugPrint(error)
|
||||
}
|
||||
|
||||
|
@ -119,7 +121,7 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
|||
}
|
||||
self.notifyDownloadProgress()
|
||||
} catch {
|
||||
NSLog("DownloadItemError")
|
||||
logger.error("DownloadItemError")
|
||||
debugPrint(error)
|
||||
}
|
||||
}
|
||||
|
@ -127,18 +129,18 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
|||
// We want to handle updating the UI in the background and throttled so we don't overload the UI with progress updates
|
||||
private func notifyDownloadProgress() {
|
||||
if self.monitoringProgressTimer?.isValid ?? false {
|
||||
NSLog("Already monitoring progress, no need to start timer again")
|
||||
logger.log("Already monitoring progress, no need to start timer again")
|
||||
} else {
|
||||
DispatchQueue.runOnMainQueue {
|
||||
self.monitoringProgressTimer = Timer.scheduledTimer(withTimeInterval: 0.2, repeats: true, block: { t in
|
||||
NSLog("Starting monitoring download progress...")
|
||||
self.monitoringProgressTimer = Timer.scheduledTimer(withTimeInterval: 0.2, repeats: true, block: { [unowned self] t in
|
||||
self.logger.log("Starting monitoring download progress...")
|
||||
|
||||
// Fetch active downloads in a thread-safe way
|
||||
func fetchActiveDownloads() -> [String: DownloadItem]? {
|
||||
self.progressStatusQueue.sync {
|
||||
let activeDownloads = self.downloadItemProgress
|
||||
if activeDownloads.isEmpty {
|
||||
NSLog("Finishing monitoring download progress...")
|
||||
logger.log("Finishing monitoring download progress...")
|
||||
t.invalidate()
|
||||
}
|
||||
return activeDownloads
|
||||
|
@ -173,8 +175,8 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
|||
statusNotification["libraryItemId"] = downloadItem.id
|
||||
|
||||
if ( downloadItem.didDownloadSuccessfully() ) {
|
||||
ApiClient.getLibraryItemWithProgress(libraryItemId: downloadItem.libraryItemId!, episodeId: downloadItem.episodeId) { libraryItem in
|
||||
guard let libraryItem = libraryItem else { NSLog("LibraryItem not found"); return }
|
||||
ApiClient.getLibraryItemWithProgress(libraryItemId: downloadItem.libraryItemId!, episodeId: downloadItem.episodeId) { [weak self] libraryItem in
|
||||
guard let libraryItem = libraryItem else { self?.logger.error("LibraryItem not found"); return }
|
||||
let localDirectory = libraryItem.id
|
||||
var coverFile: String?
|
||||
|
||||
|
@ -206,7 +208,7 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
|||
statusNotification["localMediaProgress"] = try? localMediaProgress.asDictionary()
|
||||
}
|
||||
|
||||
self.notifyListeners("onItemDownloadComplete", data: statusNotification)
|
||||
self?.notifyListeners("onItemDownloadComplete", data: statusNotification)
|
||||
}
|
||||
} else {
|
||||
self.notifyListeners("onItemDownloadComplete", data: statusNotification)
|
||||
|
@ -221,22 +223,22 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
|||
var episodeId = call.getString("episodeId")
|
||||
if ( episodeId == "null" ) { episodeId = nil }
|
||||
|
||||
NSLog("Download library item \(libraryItemId ?? "N/A") / episode \(episodeId ?? "N/A")")
|
||||
logger.log("Download library item \(libraryItemId ?? "N/A") / episode \(episodeId ?? "N/A")")
|
||||
guard let libraryItemId = libraryItemId else { return call.resolve(["error": "libraryItemId not specified"]) }
|
||||
|
||||
ApiClient.getLibraryItemWithProgress(libraryItemId: libraryItemId, episodeId: episodeId) { libraryItem in
|
||||
ApiClient.getLibraryItemWithProgress(libraryItemId: libraryItemId, episodeId: episodeId) { [weak self] libraryItem in
|
||||
if let libraryItem = libraryItem {
|
||||
NSLog("Got library item from server \(libraryItem.id)")
|
||||
self?.logger.log("Got library item from server \(libraryItem.id)")
|
||||
do {
|
||||
if let episodeId = episodeId {
|
||||
// Download a podcast episode
|
||||
guard libraryItem.mediaType == "podcast" else { throw LibraryItemDownloadError.libraryItemNotPodcast }
|
||||
let episode = libraryItem.media?.episodes.enumerated().first(where: { $1.id == episodeId })?.element
|
||||
guard let episode = episode else { throw LibraryItemDownloadError.podcastEpisodeNotFound }
|
||||
try self.startLibraryItemDownload(libraryItem, episode: episode)
|
||||
try self?.startLibraryItemDownload(libraryItem, episode: episode)
|
||||
} else {
|
||||
// Download a book
|
||||
try self.startLibraryItemDownload(libraryItem)
|
||||
try self?.startLibraryItemDownload(libraryItem)
|
||||
}
|
||||
call.resolve()
|
||||
} catch {
|
||||
|
@ -298,7 +300,7 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
|||
}
|
||||
|
||||
private func startLibraryItemTrackDownload(item: LibraryItem, position: Int, track: AudioTrack, episode: PodcastEpisode?) throws -> DownloadItemPartTask {
|
||||
NSLog("TRACK \(track.contentUrl!)")
|
||||
logger.log("TRACK \(track.contentUrl!)")
|
||||
|
||||
// If we don't name metadata, then we can't proceed
|
||||
guard let filename = track.metadata?.filename else {
|
||||
|
@ -342,10 +344,10 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
|||
|
||||
private func createLibraryItemFileDirectory(item: LibraryItem) throws -> String {
|
||||
let itemDirectory = item.id
|
||||
NSLog("ITEM DIR \(itemDirectory)")
|
||||
logger.log("ITEM DIR \(itemDirectory)")
|
||||
|
||||
guard AbsDownloader.itemDownloadFolder(path: itemDirectory) != nil else {
|
||||
NSLog("Failed to CREATE LI DIRECTORY \(itemDirectory)")
|
||||
logger.error("Failed to CREATE LI DIRECTORY \(itemDirectory)")
|
||||
throw LibraryItemDownloadError.failedDirectory
|
||||
}
|
||||
|
||||
|
@ -367,7 +369,7 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
|||
|
||||
return itemFolder
|
||||
} catch {
|
||||
NSLog("Failed to CREATE LI DIRECTORY \(error)")
|
||||
AppLogger().error("Failed to CREATE LI DIRECTORY \(error)")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,12 @@ import Capacitor
|
|||
|
||||
@objc(AbsFileSystem)
|
||||
public class AbsFileSystem: CAPPlugin {
|
||||
private let logger = AppLogger(category: "AbsFileSystem")
|
||||
|
||||
@objc func selectFolder(_ call: CAPPluginCall) {
|
||||
let mediaType = call.getString("mediaType")
|
||||
|
||||
NSLog("Select Folder for media type \(mediaType ?? "UNSET")")
|
||||
logger.log("Select Folder for media type \(mediaType ?? "UNSET")")
|
||||
|
||||
call.unavailable("Not available on iOS")
|
||||
}
|
||||
|
@ -21,7 +23,7 @@ public class AbsFileSystem: CAPPlugin {
|
|||
@objc func checkFolderPermission(_ call: CAPPluginCall) {
|
||||
let folderUrl = call.getString("folderUrl")
|
||||
|
||||
NSLog("checkFolderPermission for folder \(folderUrl ?? "UNSET")")
|
||||
logger.log("checkFolderPermission for folder \(folderUrl ?? "UNSET")")
|
||||
|
||||
call.unavailable("Not available on iOS")
|
||||
}
|
||||
|
@ -30,7 +32,7 @@ public class AbsFileSystem: CAPPlugin {
|
|||
let folderId = call.getString("folderId")
|
||||
let forceAudioProbe = call.getBool("forceAudioProbe", false)
|
||||
|
||||
NSLog("scanFolder \(folderId ?? "UNSET") | Force Probe = \(forceAudioProbe)")
|
||||
logger.log("scanFolder \(folderId ?? "UNSET") | Force Probe = \(forceAudioProbe)")
|
||||
|
||||
call.unavailable("Not available on iOS")
|
||||
}
|
||||
|
@ -38,7 +40,7 @@ public class AbsFileSystem: CAPPlugin {
|
|||
@objc func removeFolder(_ call: CAPPluginCall) {
|
||||
let folderId = call.getString("folderId")
|
||||
|
||||
NSLog("removeFolder \(folderId ?? "UNSET")")
|
||||
logger.log("removeFolder \(folderId ?? "UNSET")")
|
||||
|
||||
call.unavailable("Not available on iOS")
|
||||
}
|
||||
|
@ -46,7 +48,7 @@ public class AbsFileSystem: CAPPlugin {
|
|||
@objc func removeLocalLibraryItem(_ call: CAPPluginCall) {
|
||||
let localLibraryItemId = call.getString("localLibraryItemId")
|
||||
|
||||
NSLog("removeLocalLibraryItem \(localLibraryItemId ?? "UNSET")")
|
||||
logger.log("removeLocalLibraryItem \(localLibraryItemId ?? "UNSET")")
|
||||
|
||||
call.unavailable("Not available on iOS")
|
||||
}
|
||||
|
@ -55,7 +57,7 @@ public class AbsFileSystem: CAPPlugin {
|
|||
let localLibraryItemId = call.getString("localLibraryItemId")
|
||||
let forceAudioProbe = call.getBool("forceAudioProbe", false)
|
||||
|
||||
NSLog("scanLocalLibraryItem \(localLibraryItemId ?? "UNSET") | Force Probe = \(forceAudioProbe)")
|
||||
logger.log("scanLocalLibraryItem \(localLibraryItemId ?? "UNSET") | Force Probe = \(forceAudioProbe)")
|
||||
|
||||
call.unavailable("Not available on iOS")
|
||||
}
|
||||
|
@ -64,7 +66,7 @@ public class AbsFileSystem: CAPPlugin {
|
|||
let localLibraryItemId = call.getString("id")
|
||||
let contentUrl = call.getString("contentUrl")
|
||||
|
||||
NSLog("deleteItem \(localLibraryItemId ?? "UNSET") url \(contentUrl ?? "UNSET")")
|
||||
logger.log("deleteItem \(localLibraryItemId ?? "UNSET") url \(contentUrl ?? "UNSET")")
|
||||
|
||||
var success = false
|
||||
do {
|
||||
|
@ -74,7 +76,7 @@ public class AbsFileSystem: CAPPlugin {
|
|||
success = true
|
||||
}
|
||||
} catch {
|
||||
NSLog("Failed to delete \(error)")
|
||||
logger.error("Failed to delete \(error)")
|
||||
success = false
|
||||
}
|
||||
|
||||
|
@ -85,7 +87,7 @@ public class AbsFileSystem: CAPPlugin {
|
|||
let localLibraryItemId = call.getString("id")
|
||||
let trackLocalFileId = call.getString("trackLocalFileId")
|
||||
|
||||
NSLog("deleteTrackFromItem \(localLibraryItemId ?? "UNSET") track file \(trackLocalFileId ?? "UNSET")")
|
||||
logger.log("deleteTrackFromItem \(localLibraryItemId ?? "UNSET") track file \(trackLocalFileId ?? "UNSET")")
|
||||
|
||||
var success = false
|
||||
if let localLibraryItemId = localLibraryItemId, let trackLocalFileId = trackLocalFileId, let item = Database.shared.getLocalLibraryItem(localLibraryItemId: localLibraryItemId) {
|
||||
|
@ -105,12 +107,12 @@ public class AbsFileSystem: CAPPlugin {
|
|||
success = true
|
||||
}
|
||||
} catch {
|
||||
NSLog("Failed to delete \(error)")
|
||||
logger.error("Failed to delete \(error)")
|
||||
success = false
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
NSLog("Failed to delete \(error)")
|
||||
logger.error("Failed to delete \(error)")
|
||||
success = false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ extension AudioPlayer {
|
|||
}
|
||||
|
||||
public func setSleepTimer(secondsUntilSleep: Double) {
|
||||
NSLog("SLEEP TIMER: Sleeping in \(secondsUntilSleep) seconds")
|
||||
logger.log("SLEEP TIMER: Sleeping in \(secondsUntilSleep) seconds")
|
||||
self.removeSleepTimer()
|
||||
self.sleepTimeRemaining = secondsUntilSleep
|
||||
|
||||
|
@ -48,7 +48,7 @@ extension AudioPlayer {
|
|||
}
|
||||
|
||||
public func setChapterSleepTimer(stopAt: Double) {
|
||||
NSLog("SLEEP TIMER: Scheduling for chapter end \(stopAt)")
|
||||
logger.log("SLEEP TIMER: Scheduling for chapter end \(stopAt)")
|
||||
self.removeSleepTimer()
|
||||
|
||||
// Schedule the observation time
|
||||
|
@ -124,7 +124,7 @@ extension AudioPlayer {
|
|||
}
|
||||
|
||||
private func handleSleepEnd() {
|
||||
NSLog("SLEEP TIMER: Pausing audio")
|
||||
logger.log("SLEEP TIMER: Pausing audio")
|
||||
self.pause()
|
||||
self.removeSleepTimer()
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import Foundation
|
|||
import Alamofire
|
||||
|
||||
class ApiClient {
|
||||
private static let logger = AppLogger(category: "ApiClient")
|
||||
|
||||
public static func getData(from url: URL, completion: @escaping (UIImage?) -> Void) {
|
||||
URLSession.shared.dataTask(with: url, completionHandler: {(data, response, error) in
|
||||
if let data = data {
|
||||
|
@ -19,7 +21,7 @@ class ApiClient {
|
|||
|
||||
public static func postResource<T: Decodable>(endpoint: String, parameters: [String: Any], decodable: T.Type = T.self, callback: ((_ param: T) -> Void)?) {
|
||||
if (Store.serverConfig == nil) {
|
||||
NSLog("Server config not set")
|
||||
logger.error("Server config not set")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -32,7 +34,7 @@ class ApiClient {
|
|||
case .success(let obj):
|
||||
callback?(obj)
|
||||
case .failure(let error):
|
||||
NSLog("api request to \(endpoint) failed")
|
||||
logger.error("api request to \(endpoint) failed")
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +42,7 @@ class ApiClient {
|
|||
|
||||
public static func postResource<T: Encodable, U: Decodable>(endpoint: String, parameters: T, decodable: U.Type = U.self, callback: ((_ param: U) -> Void)?) {
|
||||
if (Store.serverConfig == nil) {
|
||||
NSLog("Server config not set")
|
||||
logger.error("Server config not set")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -53,7 +55,7 @@ class ApiClient {
|
|||
case .success(let obj):
|
||||
callback?(obj)
|
||||
case .failure(let error):
|
||||
NSLog("api request to \(endpoint) failed")
|
||||
logger.error("api request to \(endpoint) failed")
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +71,7 @@ class ApiClient {
|
|||
|
||||
public static func postResource<T:Encodable>(endpoint: String, parameters: T, callback: ((_ success: Bool) -> Void)?) {
|
||||
if (Store.serverConfig == nil) {
|
||||
NSLog("Server config not set")
|
||||
logger.error("Server config not set")
|
||||
callback?(false)
|
||||
return
|
||||
}
|
||||
|
@ -83,7 +85,7 @@ class ApiClient {
|
|||
case .success(_):
|
||||
callback?(true)
|
||||
case .failure(let error):
|
||||
NSLog("api request to \(endpoint) failed")
|
||||
logger.error("api request to \(endpoint) failed")
|
||||
print(error)
|
||||
|
||||
callback?(false)
|
||||
|
@ -93,7 +95,7 @@ class ApiClient {
|
|||
|
||||
public static func patchResource<T: Encodable>(endpoint: String, parameters: T, callback: ((_ success: Bool) -> Void)?) {
|
||||
if (Store.serverConfig == nil) {
|
||||
NSLog("Server config not set")
|
||||
logger.error("Server config not set")
|
||||
callback?(false)
|
||||
return
|
||||
}
|
||||
|
@ -107,7 +109,7 @@ class ApiClient {
|
|||
case .success(_):
|
||||
callback?(true)
|
||||
case .failure(let error):
|
||||
NSLog("api request to \(endpoint) failed")
|
||||
logger.error("api request to \(endpoint) failed")
|
||||
print(error)
|
||||
callback?(false)
|
||||
}
|
||||
|
@ -124,7 +126,7 @@ class ApiClient {
|
|||
|
||||
public static func getResource<T: Decodable>(endpoint: String, decodable: T.Type = T.self, callback: ((_ param: T?) -> Void)?) {
|
||||
if (Store.serverConfig == nil) {
|
||||
NSLog("Server config not set")
|
||||
logger.error("Server config not set")
|
||||
callback?(nil)
|
||||
return
|
||||
}
|
||||
|
@ -138,7 +140,7 @@ class ApiClient {
|
|||
case .success(let obj):
|
||||
callback?(obj)
|
||||
case .failure(let error):
|
||||
NSLog("api request to \(endpoint) failed")
|
||||
logger.error("api request to \(endpoint) failed")
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
|
@ -193,10 +195,10 @@ class ApiClient {
|
|||
|
||||
if ( !localMediaProgressList.isEmpty ) {
|
||||
let payload = LocalMediaProgressSyncPayload(localMediaProgress: localMediaProgressList)
|
||||
NSLog("Sending sync local progress request with \(localMediaProgressList.count) progress items")
|
||||
logger.log("Sending sync local progress request with \(localMediaProgressList.count) progress items")
|
||||
postResource(endpoint: "api/me/sync-local-progress", parameters: payload, decodable: MediaProgressSyncResponsePayload.self) { response in
|
||||
let resultsPayload = LocalMediaProgressSyncResultsPayload(numLocalMediaProgressForServer: localMediaProgressList.count, numServerProgressUpdates: response.numServerProgressUpdates, numLocalProgressUpdates: response.localProgressUpdates?.count)
|
||||
NSLog("Media Progress Sync | \(String(describing: try? resultsPayload.asDictionary()))")
|
||||
logger.log("Media Progress Sync | \(String(describing: try? resultsPayload.asDictionary()))")
|
||||
|
||||
if let updates = response.localProgressUpdates {
|
||||
for update in updates {
|
||||
|
@ -212,13 +214,13 @@ class ApiClient {
|
|||
callback(resultsPayload)
|
||||
}
|
||||
} else {
|
||||
NSLog("No local media progress to sync")
|
||||
logger.log("No local media progress to sync")
|
||||
callback(LocalMediaProgressSyncResultsPayload(numLocalMediaProgressForServer: 0, numServerProgressUpdates: 0, numLocalProgressUpdates: 0))
|
||||
}
|
||||
}
|
||||
|
||||
public static func updateMediaProgress<T:Encodable>(libraryItemId: String, episodeId: String?, payload: T, callback: @escaping () -> Void) {
|
||||
NSLog("updateMediaProgress \(libraryItemId) \(episodeId ?? "NIL") \(payload)")
|
||||
logger.log("updateMediaProgress \(libraryItemId) \(episodeId ?? "NIL") \(payload)")
|
||||
let endpoint = episodeId?.isEmpty ?? true ? "api/me/progress/\(libraryItemId)" : "api/me/progress/\(libraryItemId)/\(episodeId ?? "")"
|
||||
patchResource(endpoint: endpoint, parameters: payload) { success in
|
||||
callback()
|
||||
|
@ -226,7 +228,7 @@ class ApiClient {
|
|||
}
|
||||
|
||||
public static func getMediaProgress(libraryItemId: String, episodeId: String?) async -> MediaProgress? {
|
||||
NSLog("getMediaProgress \(libraryItemId) \(episodeId ?? "NIL")")
|
||||
logger.log("getMediaProgress \(libraryItemId) \(episodeId ?? "NIL")")
|
||||
let endpoint = episodeId?.isEmpty ?? true ? "api/me/progress/\(libraryItemId)" : "api/me/progress/\(libraryItemId)/\(episodeId ?? "")"
|
||||
return await getResource(endpoint: endpoint, decodable: MediaProgress.self)
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ class Database {
|
|||
public static var shared = {
|
||||
return Database()
|
||||
}()
|
||||
|
||||
private let logger = AppLogger(category: "Database")
|
||||
|
||||
private init() {}
|
||||
|
||||
|
@ -30,7 +32,7 @@ class Database {
|
|||
existing.token = config.token
|
||||
}
|
||||
} catch {
|
||||
NSLog("failed to update server config")
|
||||
logger.error("failed to update server config")
|
||||
debugPrint(error)
|
||||
}
|
||||
|
||||
|
@ -51,7 +53,7 @@ class Database {
|
|||
realm.add(config)
|
||||
}
|
||||
} catch(let exception) {
|
||||
NSLog("failed to save server config")
|
||||
logger.error("failed to save server config")
|
||||
debugPrint(exception)
|
||||
}
|
||||
|
||||
|
@ -70,7 +72,7 @@ class Database {
|
|||
}
|
||||
}
|
||||
} catch(let exception) {
|
||||
NSLog("failed to delete server config")
|
||||
logger.error("failed to delete server config")
|
||||
debugPrint(exception)
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +103,7 @@ class Database {
|
|||
}
|
||||
}
|
||||
} catch(let exception) {
|
||||
NSLog("failed to save server config active index")
|
||||
logger.error("failed to save server config active index")
|
||||
debugPrint(exception)
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +123,7 @@ class Database {
|
|||
realm.add(deviceSettings)
|
||||
}
|
||||
} catch {
|
||||
NSLog("failed to save device settings")
|
||||
logger.error("failed to save device settings")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ extension CAPPluginCall {
|
|||
let json = try JSONSerialization.data(withJSONObject: value)
|
||||
return try JSONDecoder().decode(type, from: json)
|
||||
} catch {
|
||||
NSLog("Failed to get json for \(key)")
|
||||
AppLogger().error("Failed to get json for \(key)")
|
||||
debugPrint(error)
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue