Ferrite: Format
Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
69d2f6babe
commit
edfba1c62e
10 changed files with 70 additions and 77 deletions
|
|
@ -11,20 +11,19 @@ public class Kodi {
|
||||||
let encoder = JSONEncoder()
|
let encoder = JSONEncoder()
|
||||||
|
|
||||||
// Used to add server to CoreData. Not part of API
|
// Used to add server to CoreData. Not part of API
|
||||||
public func addServer(
|
public func addServer(urlString: String,
|
||||||
urlString: String,
|
friendlyName: String?,
|
||||||
friendlyName: String?,
|
username: String?,
|
||||||
username: String?,
|
password: String?,
|
||||||
password: String?,
|
existingServer: KodiServer? = nil) throws
|
||||||
existingServer: KodiServer? = nil
|
{
|
||||||
) throws {
|
|
||||||
let backgroundContext = PersistenceController.shared.backgroundContext
|
let backgroundContext = PersistenceController.shared.backgroundContext
|
||||||
|
|
||||||
if !urlString.starts(with: "http://") && !urlString.starts(with: "https://") {
|
if !urlString.starts(with: "http://"), !urlString.starts(with: "https://") {
|
||||||
throw KodiError.ServerAddition(description: "Could not add Kodi server because the URL is invalid.")
|
throw KodiError.ServerAddition(description: "Could not add Kodi server because the URL is invalid.")
|
||||||
}
|
}
|
||||||
|
|
||||||
var name: String = ""
|
var name = ""
|
||||||
if let friendlyName {
|
if let friendlyName {
|
||||||
name = friendlyName
|
name = friendlyName
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,8 @@
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import CoreData
|
import CoreData
|
||||||
|
import Foundation
|
||||||
|
|
||||||
@objc(KodiServer)
|
@objc(KodiServer)
|
||||||
public class KodiServer: NSManagedObject {
|
public class KodiServer: NSManagedObject {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,18 @@
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import CoreData
|
import CoreData
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
public extension KodiServer {
|
||||||
extension KodiServer {
|
@nonobjc class func fetchRequest() -> NSFetchRequest<KodiServer> {
|
||||||
|
NSFetchRequest<KodiServer>(entityName: "KodiServer")
|
||||||
@nonobjc public class func fetchRequest() -> NSFetchRequest<KodiServer> {
|
|
||||||
return NSFetchRequest<KodiServer>(entityName: "KodiServer")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NSManaged public var urlString: String
|
@NSManaged var urlString: String
|
||||||
@NSManaged public var name: String
|
@NSManaged var name: String
|
||||||
@NSManaged public var username: String?
|
@NSManaged var username: String?
|
||||||
@NSManaged public var password: String?
|
@NSManaged var password: String?
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension KodiServer : Identifiable {
|
extension KodiServer: Identifiable {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -17,16 +17,15 @@ public struct ActionJson: Codable, Hashable, PluginJson {
|
||||||
public let listId: UUID?
|
public let listId: UUID?
|
||||||
public let tags: [PluginTagJson]?
|
public let tags: [PluginTagJson]?
|
||||||
|
|
||||||
public init(
|
public init(name: String,
|
||||||
name: String,
|
version: Int16,
|
||||||
version: Int16,
|
minVersion: String?,
|
||||||
minVersion: String?,
|
requires: [ActionRequirement],
|
||||||
requires: [ActionRequirement],
|
deeplink: [DeeplinkActionJson]?,
|
||||||
deeplink: [DeeplinkActionJson]?,
|
author: String?,
|
||||||
author: String?,
|
listId: UUID?,
|
||||||
listId: UUID?,
|
tags: [PluginTagJson]?)
|
||||||
tags: [PluginTagJson]?
|
{
|
||||||
) {
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self.version = version
|
self.version = version
|
||||||
self.minVersion = minVersion
|
self.minVersion = minVersion
|
||||||
|
|
@ -39,20 +38,20 @@ public struct ActionJson: Codable, Hashable, PluginJson {
|
||||||
|
|
||||||
public init(from decoder: Decoder) throws {
|
public init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
self.name = try container.decode(String.self, forKey: .name)
|
name = try container.decode(String.self, forKey: .name)
|
||||||
self.version = try container.decode(Int16.self, forKey: .version)
|
version = try container.decode(Int16.self, forKey: .version)
|
||||||
self.minVersion = try container.decodeIfPresent(String.self, forKey: .minVersion)
|
minVersion = try container.decodeIfPresent(String.self, forKey: .minVersion)
|
||||||
self.requires = try container.decode([ActionRequirement].self, forKey: .requires)
|
requires = try container.decode([ActionRequirement].self, forKey: .requires)
|
||||||
self.author = try container.decodeIfPresent(String.self, forKey: .author)
|
author = try container.decodeIfPresent(String.self, forKey: .author)
|
||||||
self.listId = try container.decodeIfPresent(UUID.self, forKey: .listId)
|
listId = try container.decodeIfPresent(UUID.self, forKey: .listId)
|
||||||
self.tags = try container.decodeIfPresent([PluginTagJson].self, forKey: .tags)
|
tags = try container.decodeIfPresent([PluginTagJson].self, forKey: .tags)
|
||||||
|
|
||||||
if let deeplinkString = try? container.decode(String.self, forKey: .deeplink) {
|
if let deeplinkString = try? container.decode(String.self, forKey: .deeplink) {
|
||||||
self.deeplink = [DeeplinkActionJson(os: [], scheme: deeplinkString)]
|
deeplink = [DeeplinkActionJson(os: [], scheme: deeplinkString)]
|
||||||
} else if let deeplinkAction = try? container.decode([DeeplinkActionJson].self, forKey: .deeplink) {
|
} else if let deeplinkAction = try? container.decode([DeeplinkActionJson].self, forKey: .deeplink) {
|
||||||
self.deeplink = deeplinkAction
|
deeplink = deeplinkAction
|
||||||
} else {
|
} else {
|
||||||
self.deeplink = nil
|
deeplink = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -74,10 +73,10 @@ public struct DeeplinkActionJson: Codable, Hashable {
|
||||||
} else if let os = try? container.decode([String].self, forKey: .os) {
|
} else if let os = try? container.decode([String].self, forKey: .os) {
|
||||||
self.os = os
|
self.os = os
|
||||||
} else {
|
} else {
|
||||||
self.os = []
|
os = []
|
||||||
}
|
}
|
||||||
|
|
||||||
self.scheme = try container.decode(String.self, forKey: .scheme)
|
scheme = try container.decode(String.self, forKey: .scheme)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ class LoggingManager: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Logging functions
|
// MARK: - Logging functions
|
||||||
|
|
||||||
// TODO: Maybe append to a constant logfile?
|
// TODO: Maybe append to a constant logfile?
|
||||||
|
|
||||||
public func info(_ message: String,
|
public func info(_ message: String,
|
||||||
|
|
@ -168,7 +169,7 @@ class LoggingManager: ObservableObject {
|
||||||
|
|
||||||
try joinedMessages.write(to: logPath, atomically: true, encoding: .utf8)
|
try joinedMessages.write(to: logPath, atomically: true, encoding: .utf8)
|
||||||
|
|
||||||
self.info("Log \(logFileName) was written to path \(logPath.description)")
|
info("Log \(logFileName) was written to path \(logPath.description)")
|
||||||
showLogExportedAlert.toggle()
|
showLogExportedAlert.toggle()
|
||||||
} catch {
|
} catch {
|
||||||
self.error(
|
self.error(
|
||||||
|
|
|
||||||
|
|
@ -188,8 +188,8 @@ public class PluginManager: ObservableObject {
|
||||||
.filter { availablePlugin in
|
.filter { availablePlugin in
|
||||||
let pluginExists = installedPlugins.contains(where: {
|
let pluginExists = installedPlugins.contains(where: {
|
||||||
availablePlugin.name == $0.name &&
|
availablePlugin.name == $0.name &&
|
||||||
availablePlugin.listId == $0.listId &&
|
availablePlugin.listId == $0.listId &&
|
||||||
availablePlugin.author == $0.author
|
availablePlugin.author == $0.author
|
||||||
})
|
})
|
||||||
|
|
||||||
if searchText.isEmpty {
|
if searchText.isEmpty {
|
||||||
|
|
@ -210,10 +210,10 @@ public class PluginManager: ObservableObject {
|
||||||
for plugin in installedPlugins {
|
for plugin in installedPlugins {
|
||||||
if let availablePlugin = availablePlugins.first(where: {
|
if let availablePlugin = availablePlugins.first(where: {
|
||||||
plugin.listId == $0.listId &&
|
plugin.listId == $0.listId &&
|
||||||
plugin.name == $0.name &&
|
plugin.name == $0.name &&
|
||||||
plugin.author == $0.author
|
plugin.author == $0.author
|
||||||
}),
|
}),
|
||||||
availablePlugin.version > plugin.version
|
availablePlugin.version > plugin.version
|
||||||
{
|
{
|
||||||
updatedPlugins.append(availablePlugin)
|
updatedPlugins.append(availablePlugin)
|
||||||
}
|
}
|
||||||
|
|
@ -277,8 +277,8 @@ public class PluginManager: ObservableObject {
|
||||||
UserDefaults.standard.set(nil, forKey: "Action.DefaultDebridList")
|
UserDefaults.standard.set(nil, forKey: "Action.DefaultDebridList")
|
||||||
|
|
||||||
actionErrorAlertMessage =
|
actionErrorAlertMessage =
|
||||||
"The default action could not be run. The action choice sheet has been opened. \n\n" +
|
"The default action could not be run. The action choice sheet has been opened. \n\n" +
|
||||||
"Please check your default actions in Settings"
|
"Please check your default actions in Settings"
|
||||||
showActionErrorAlert.toggle()
|
showActionErrorAlert.toggle()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -306,8 +306,8 @@ public class PluginManager: ObservableObject {
|
||||||
UserDefaults.standard.set(nil, forKey: "Actions.DefaultMagnetList")
|
UserDefaults.standard.set(nil, forKey: "Actions.DefaultMagnetList")
|
||||||
|
|
||||||
actionErrorAlertMessage =
|
actionErrorAlertMessage =
|
||||||
"The default action could not be run. The action choice sheet has been opened. \n\n" +
|
"The default action could not be run. The action choice sheet has been opened. \n\n" +
|
||||||
"Please check your default actions in Settings"
|
"Please check your default actions in Settings"
|
||||||
showActionErrorAlert.toggle()
|
showActionErrorAlert.toggle()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -321,9 +321,9 @@ public class PluginManager: ObservableObject {
|
||||||
guard let deeplink = action.deeplink, let urlString else {
|
guard let deeplink = action.deeplink, let urlString else {
|
||||||
actionErrorAlertMessage = "Could not run action: \(action.name) since there is no deeplink to execute. Contact the action dev!"
|
actionErrorAlertMessage = "Could not run action: \(action.name) since there is no deeplink to execute. Contact the action dev!"
|
||||||
showActionErrorAlert.toggle()
|
showActionErrorAlert.toggle()
|
||||||
|
|
||||||
logManager?.error("Could not run action: \(action.name) since there is no deeplink to execute.")
|
logManager?.error("Could not run action: \(action.name) since there is no deeplink to execute.")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -334,7 +334,7 @@ public class PluginManager: ObservableObject {
|
||||||
} else {
|
} else {
|
||||||
actionErrorAlertMessage = "Could not run action: \(action.name) because the created deeplink was invalid. Contact the action dev!"
|
actionErrorAlertMessage = "Could not run action: \(action.name) because the created deeplink was invalid. Contact the action dev!"
|
||||||
showActionErrorAlert.toggle()
|
showActionErrorAlert.toggle()
|
||||||
|
|
||||||
logManager?.error("Could not run action: \(action.name) because the created deeplink (\(String(describing: playbackUrl))) was invalid")
|
logManager?.error("Could not run action: \(action.name) because the created deeplink (\(String(describing: playbackUrl))) was invalid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -360,7 +360,7 @@ public class PluginManager: ObservableObject {
|
||||||
} catch {
|
} catch {
|
||||||
actionErrorAlertMessage = "Kodi Error: \(error)"
|
actionErrorAlertMessage = "Kodi Error: \(error)"
|
||||||
showActionErrorAlert.toggle()
|
showActionErrorAlert.toggle()
|
||||||
|
|
||||||
logManager?.error("Kodi action: \(error)")
|
logManager?.error("Kodi action: \(error)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ struct KodiEditorView: View {
|
||||||
presentationMode.wrappedValue.dismiss()
|
presentationMode.wrappedValue.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolbarItem(placement: .navigationBarTrailing) {
|
ToolbarItem(placement: .navigationBarTrailing) {
|
||||||
Button("Save") {
|
Button("Save") {
|
||||||
do {
|
do {
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,10 @@ struct SettingsPluginListView: View {
|
||||||
ForEach(pluginLists, id: \.self) { pluginList in
|
ForEach(pluginLists, id: \.self) { pluginList in
|
||||||
VStack(alignment: .leading, spacing: 5) {
|
VStack(alignment: .leading, spacing: 5) {
|
||||||
Text(pluginList.name)
|
Text(pluginList.name)
|
||||||
|
|
||||||
Group {
|
Group {
|
||||||
Text(pluginList.author)
|
Text(pluginList.author)
|
||||||
|
|
||||||
Text("ID: \(pluginList.id)")
|
Text("ID: \(pluginList.id)")
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +46,7 @@ struct SettingsPluginListView: View {
|
||||||
Text("Edit")
|
Text("Edit")
|
||||||
Image(systemName: "pencil")
|
Image(systemName: "pencil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if #available(iOS 15.0, *) {
|
if #available(iOS 15.0, *) {
|
||||||
Button(role: .destructive) {
|
Button(role: .destructive) {
|
||||||
PersistenceController.shared.delete(pluginList, context: backgroundContext)
|
PersistenceController.shared.delete(pluginList, context: backgroundContext)
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ struct MainView: View {
|
||||||
Application.shared.osVersion.majorVersion >= Application.shared.minVersion.majorVersion
|
Application.shared.osVersion.majorVersion >= Application.shared.minVersion.majorVersion
|
||||||
{
|
{
|
||||||
// MARK: If scope bar duplication happens, this may be the problem
|
// MARK: If scope bar duplication happens, this may be the problem
|
||||||
|
|
||||||
logManager.info("Ferrite started")
|
logManager.info("Ferrite started")
|
||||||
|
|
||||||
viewTask = Task {
|
viewTask = Task {
|
||||||
|
|
|
||||||
|
|
@ -13,18 +13,18 @@ struct PluginsView: View {
|
||||||
@EnvironmentObject var navModel: NavigationViewModel
|
@EnvironmentObject var navModel: NavigationViewModel
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@FetchRequest(
|
@FetchRequest(
|
||||||
entity: Source.entity(),
|
entity: Source.entity(),
|
||||||
sortDescriptors: []
|
sortDescriptors: []
|
||||||
) var sources: FetchedResults<Source>
|
) var sources: FetchedResults<Source>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@FetchRequest(
|
@FetchRequest(
|
||||||
entity: Action.entity(),
|
entity: Action.entity(),
|
||||||
sortDescriptors: []
|
sortDescriptors: []
|
||||||
) var actions: FetchedResults<Action>
|
) var actions: FetchedResults<Action>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@AppStorage("Behavior.AutocorrectSearch") var autocorrectSearch = true
|
@AppStorage("Behavior.AutocorrectSearch") var autocorrectSearch = true
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue