Ferrite: Format

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri 2023-03-19 21:26:42 -04:00
parent 69d2f6babe
commit edfba1c62e
10 changed files with 70 additions and 77 deletions

View file

@ -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 existingServer: KodiServer? = nil) throws
) 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 {

View file

@ -6,10 +6,8 @@
// //
// //
import Foundation
import CoreData import CoreData
import Foundation
@objc(KodiServer) @objc(KodiServer)
public class KodiServer: NSManagedObject { public class KodiServer: NSManagedObject {}
}

View file

@ -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 {}
}

View file

@ -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)
} }
} }

View file

@ -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(

View file

@ -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 {