Multiple servers can be added to Ferrite to playback from any Kodi server that the user wants. This also adds the ability to have friendly names which makes it easier to select what server to play on. Each server shows the user whether it's online or not through Kodi's JSONRPC ping method. Signed-off-by: kingbri <bdashore3@proton.me>
96 lines
3.5 KiB
Swift
96 lines
3.5 KiB
Swift
//
|
|
// SettingsKodiView.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 3/4/23.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct SettingsKodiView: View {
|
|
let backgroundContext = PersistenceController.shared.backgroundContext
|
|
|
|
@EnvironmentObject var navModel: NavigationViewModel
|
|
|
|
// TODO: Change to var in v0.7
|
|
@FetchRequest(
|
|
entity: KodiServer.entity(),
|
|
sortDescriptors: []
|
|
) var kodiServers: FetchedResults<KodiServer>
|
|
|
|
@State private var presentEditSheet = false
|
|
|
|
var body: some View {
|
|
List {
|
|
Section(header: InlineHeader("Description")) {
|
|
VStack(alignment: .leading, spacing: 10) {
|
|
Text("Kodi is an external application that is used to manage a local media library and playback.")
|
|
|
|
Link("Website", destination: URL(string: "https://kodi.tv")!)
|
|
}
|
|
}
|
|
|
|
Section(
|
|
header: InlineHeader("Servers"),
|
|
footer: Text("Edit a server by holding it and accessing the context menu")
|
|
) {
|
|
if kodiServers.isEmpty {
|
|
Text("Add a server using the + button in the top-right")
|
|
} else {
|
|
ForEach(kodiServers, id: \.self) { server in
|
|
KodiServerView(server: server)
|
|
.contextMenu {
|
|
Button {
|
|
navModel.selectedKodiServer = server
|
|
presentEditSheet.toggle()
|
|
} label: {
|
|
Text("Edit")
|
|
Image(systemName: "pencil")
|
|
}
|
|
|
|
if #available(iOS 15.0, *) {
|
|
Button(role: .destructive) {
|
|
PersistenceController.shared.delete(server, context: backgroundContext)
|
|
} label: {
|
|
Text("Remove")
|
|
Image(systemName: "trash")
|
|
}
|
|
} else {
|
|
Button {
|
|
PersistenceController.shared.delete(server, context: backgroundContext)
|
|
} label: {
|
|
Text("Remove")
|
|
Image(systemName: "trash")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.onDelete { offsets in
|
|
for index in offsets {
|
|
if let server = kodiServers[safe: index] {
|
|
PersistenceController.shared.delete(server, context: backgroundContext)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.listStyle(.insetGrouped)
|
|
.sheet(isPresented: $presentEditSheet) {
|
|
KodiEditorView()
|
|
.environmentObject(navModel)
|
|
}
|
|
.navigationTitle("Kodi")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
Button {
|
|
navModel.selectedKodiServer = nil
|
|
presentEditSheet.toggle()
|
|
} label: {
|
|
Image(systemName: "plus")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|