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()
// Used to add server to CoreData. Not part of API
public func addServer(
urlString: String,
friendlyName: String?,
username: String?,
password: String?,
existingServer: KodiServer? = nil
) throws {
public func addServer(urlString: String,
friendlyName: String?,
username: String?,
password: String?,
existingServer: KodiServer? = nil) throws
{
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.")
}
var name: String = ""
var name = ""
if let friendlyName {
name = friendlyName
} else {

View file

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

View file

@ -6,23 +6,18 @@
//
//
import Foundation
import CoreData
import Foundation
extension KodiServer {
@nonobjc public class func fetchRequest() -> NSFetchRequest<KodiServer> {
return NSFetchRequest<KodiServer>(entityName: "KodiServer")
public extension KodiServer {
@nonobjc class func fetchRequest() -> NSFetchRequest<KodiServer> {
NSFetchRequest<KodiServer>(entityName: "KodiServer")
}
@NSManaged public var urlString: String
@NSManaged public var name: String
@NSManaged public var username: String?
@NSManaged public var password: String?
@NSManaged var urlString: String
@NSManaged var name: String
@NSManaged var username: 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 tags: [PluginTagJson]?
public init(
name: String,
version: Int16,
minVersion: String?,
requires: [ActionRequirement],
deeplink: [DeeplinkActionJson]?,
author: String?,
listId: UUID?,
tags: [PluginTagJson]?
) {
public init(name: String,
version: Int16,
minVersion: String?,
requires: [ActionRequirement],
deeplink: [DeeplinkActionJson]?,
author: String?,
listId: UUID?,
tags: [PluginTagJson]?)
{
self.name = name
self.version = version
self.minVersion = minVersion
@ -39,20 +38,20 @@ public struct ActionJson: Codable, Hashable, PluginJson {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.name = try container.decode(String.self, forKey: .name)
self.version = try container.decode(Int16.self, forKey: .version)
self.minVersion = try container.decodeIfPresent(String.self, forKey: .minVersion)
self.requires = try container.decode([ActionRequirement].self, forKey: .requires)
self.author = try container.decodeIfPresent(String.self, forKey: .author)
self.listId = try container.decodeIfPresent(UUID.self, forKey: .listId)
self.tags = try container.decodeIfPresent([PluginTagJson].self, forKey: .tags)
name = try container.decode(String.self, forKey: .name)
version = try container.decode(Int16.self, forKey: .version)
minVersion = try container.decodeIfPresent(String.self, forKey: .minVersion)
requires = try container.decode([ActionRequirement].self, forKey: .requires)
author = try container.decodeIfPresent(String.self, forKey: .author)
listId = try container.decodeIfPresent(UUID.self, forKey: .listId)
tags = try container.decodeIfPresent([PluginTagJson].self, forKey: .tags)
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) {
self.deeplink = deeplinkAction
deeplink = deeplinkAction
} 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) {
self.os = os
} 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
// TODO: Maybe append to a constant logfile?
public func info(_ message: String,
@ -168,7 +169,7 @@ class LoggingManager: ObservableObject {
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()
} catch {
self.error(

View file

@ -188,8 +188,8 @@ public class PluginManager: ObservableObject {
.filter { availablePlugin in
let pluginExists = installedPlugins.contains(where: {
availablePlugin.name == $0.name &&
availablePlugin.listId == $0.listId &&
availablePlugin.author == $0.author
availablePlugin.listId == $0.listId &&
availablePlugin.author == $0.author
})
if searchText.isEmpty {
@ -210,10 +210,10 @@ public class PluginManager: ObservableObject {
for plugin in installedPlugins {
if let availablePlugin = availablePlugins.first(where: {
plugin.listId == $0.listId &&
plugin.name == $0.name &&
plugin.author == $0.author
plugin.name == $0.name &&
plugin.author == $0.author
}),
availablePlugin.version > plugin.version
availablePlugin.version > plugin.version
{
updatedPlugins.append(availablePlugin)
}
@ -277,8 +277,8 @@ public class PluginManager: ObservableObject {
UserDefaults.standard.set(nil, forKey: "Action.DefaultDebridList")
actionErrorAlertMessage =
"The default action could not be run. The action choice sheet has been opened. \n\n" +
"Please check your default actions in Settings"
"The default action could not be run. The action choice sheet has been opened. \n\n" +
"Please check your default actions in Settings"
showActionErrorAlert.toggle()
}
} else {
@ -306,8 +306,8 @@ public class PluginManager: ObservableObject {
UserDefaults.standard.set(nil, forKey: "Actions.DefaultMagnetList")
actionErrorAlertMessage =
"The default action could not be run. The action choice sheet has been opened. \n\n" +
"Please check your default actions in Settings"
"The default action could not be run. The action choice sheet has been opened. \n\n" +
"Please check your default actions in Settings"
showActionErrorAlert.toggle()
}
} else {
@ -321,9 +321,9 @@ public class PluginManager: ObservableObject {
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!"
showActionErrorAlert.toggle()
logManager?.error("Could not run action: \(action.name) since there is no deeplink to execute.")
return
}
@ -334,7 +334,7 @@ public class PluginManager: ObservableObject {
} else {
actionErrorAlertMessage = "Could not run action: \(action.name) because the created deeplink was invalid. Contact the action dev!"
showActionErrorAlert.toggle()
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 {
actionErrorAlertMessage = "Kodi Error: \(error)"
showActionErrorAlert.toggle()
logManager?.error("Kodi action: \(error)")
}
}

View file

@ -79,7 +79,7 @@ struct KodiEditorView: View {
presentationMode.wrappedValue.dismiss()
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button("Save") {
do {

View file

@ -28,10 +28,10 @@ struct SettingsPluginListView: View {
ForEach(pluginLists, id: \.self) { pluginList in
VStack(alignment: .leading, spacing: 5) {
Text(pluginList.name)
Group {
Text(pluginList.author)
Text("ID: \(pluginList.id)")
.font(.caption)
}
@ -46,7 +46,7 @@ struct SettingsPluginListView: View {
Text("Edit")
Image(systemName: "pencil")
}
if #available(iOS 15.0, *) {
Button(role: .destructive) {
PersistenceController.shared.delete(pluginList, context: backgroundContext)

View file

@ -78,6 +78,7 @@ struct MainView: View {
Application.shared.osVersion.majorVersion >= Application.shared.minVersion.majorVersion
{
// MARK: If scope bar duplication happens, this may be the problem
logManager.info("Ferrite started")
viewTask = Task {

View file

@ -13,18 +13,18 @@ struct PluginsView: View {
@EnvironmentObject var navModel: NavigationViewModel
/*
@FetchRequest(
entity: Source.entity(),
sortDescriptors: []
) var sources: FetchedResults<Source>
*/
@FetchRequest(
entity: Source.entity(),
sortDescriptors: []
) var sources: FetchedResults<Source>
*/
/*
@FetchRequest(
entity: Action.entity(),
sortDescriptors: []
) var actions: FetchedResults<Action>
*/
@FetchRequest(
entity: Action.entity(),
sortDescriptors: []
) var actions: FetchedResults<Action>
*/
@AppStorage("Behavior.AutocorrectSearch") var autocorrectSearch = true