mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 18:15:01 +02:00
Added realm
This commit is contained in:
parent
2f4b3050fd
commit
c0ac3b7bb5
14 changed files with 19001 additions and 377 deletions
31
ios/App/Shared/models/ServerConnectionConfig.swift
Normal file
31
ios/App/Shared/models/ServerConnectionConfig.swift
Normal file
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// ServerConnectionConfig.swift
|
||||
// App
|
||||
//
|
||||
// Created by Rasmus Krämer on 11.04.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RealmSwift
|
||||
|
||||
class ServerConnectionConfig: Object {
|
||||
@Persisted var id: String
|
||||
@Persisted var index: Int = 0
|
||||
@Persisted var name: String
|
||||
@Persisted var address: String
|
||||
@Persisted var userId: String
|
||||
@Persisted var username: String
|
||||
@Persisted var token: String
|
||||
}
|
||||
|
||||
func serverConnectionConfigToJSON(config: ServerConnectionConfig) -> Dictionary<String, Any> {
|
||||
return [
|
||||
"id": config.id,
|
||||
"name": config.name,
|
||||
"index": config.index,
|
||||
"address": config.address,
|
||||
"userId": config.userId,
|
||||
"username": config.username,
|
||||
"token": config.token,
|
||||
]
|
||||
}
|
17
ios/App/Shared/player/PlayerHandler.swift
Normal file
17
ios/App/Shared/player/PlayerHandler.swift
Normal file
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// PlayerHandler.swift
|
||||
// App
|
||||
//
|
||||
// Created by Rasmus Krämer on 11.04.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class PlayerHandler {
|
||||
private static var player: AudioPlayer?
|
||||
// private static var item: any
|
||||
|
||||
public static func setItem() {
|
||||
|
||||
}
|
||||
}
|
32
ios/App/Shared/util/Database.swift
Normal file
32
ios/App/Shared/util/Database.swift
Normal file
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
// Database.swift
|
||||
// App
|
||||
//
|
||||
// Created by Rasmus Krämer on 11.04.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RealmSwift
|
||||
|
||||
class Database {
|
||||
public static let realmQueue = DispatchQueue(label: "realm-queue")
|
||||
|
||||
public static func setServerConnectionConfig(config: ServerConnectionConfig) {
|
||||
let realm = try! Realm(queue: realmQueue)
|
||||
let existing = realm.objects(ServerConnectionConfig.self)
|
||||
|
||||
try! realm.write {
|
||||
realm.delete(existing)
|
||||
realm.add(config)
|
||||
}
|
||||
}
|
||||
public static func getServerConnectionConfig() -> ServerConnectionConfig {
|
||||
let realm = try! Realm(queue: realmQueue)
|
||||
guard let config = realm.objects(ServerConnectionConfig.self).first else {
|
||||
let fallback = ServerConnectionConfig()
|
||||
return fallback
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
}
|
20
ios/App/Shared/util/Store.swift
Normal file
20
ios/App/Shared/util/Store.swift
Normal file
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// Store.swift
|
||||
// App
|
||||
//
|
||||
// Created by Rasmus Krämer on 11.04.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RealmSwift
|
||||
|
||||
class Store {
|
||||
public static var serverConfig: ServerConnectionConfig {
|
||||
get {
|
||||
return Database.getServerConnectionConfig()
|
||||
}
|
||||
set(updated) {
|
||||
Database.setServerConnectionConfig(config: updated)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue