From edfba1c62e8a6bd13affd0bf4f8e46badd0793e3 Mon Sep 17 00:00:00 2001 From: kingbri Date: Sun, 19 Mar 2023 21:26:42 -0400 Subject: [PATCH] Ferrite: Format Signed-off-by: kingbri --- Ferrite/API/KodiWrapper.swift | 17 ++++---- .../Classes/KodiServer+CoreDataClass.swift | 6 +-- .../KodiServer+CoreDataProperties.swift | 23 ++++------ Ferrite/Models/ActionModels.swift | 43 +++++++++---------- Ferrite/ViewModels/LoggingManager.swift | 3 +- Ferrite/ViewModels/PluginManager.swift | 26 +++++------ .../Settings/Kodi/KodiEditorView.swift | 2 +- .../PluginList/SettingsPluginListView.swift | 6 +-- Ferrite/Views/MainView.swift | 1 + Ferrite/Views/PluginsView.swift | 20 ++++----- 10 files changed, 70 insertions(+), 77 deletions(-) diff --git a/Ferrite/API/KodiWrapper.swift b/Ferrite/API/KodiWrapper.swift index 1afb1c8..f0ade8e 100644 --- a/Ferrite/API/KodiWrapper.swift +++ b/Ferrite/API/KodiWrapper.swift @@ -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 { diff --git a/Ferrite/DataManagement/Classes/KodiServer+CoreDataClass.swift b/Ferrite/DataManagement/Classes/KodiServer+CoreDataClass.swift index 2cdb899..8d7da17 100644 --- a/Ferrite/DataManagement/Classes/KodiServer+CoreDataClass.swift +++ b/Ferrite/DataManagement/Classes/KodiServer+CoreDataClass.swift @@ -6,10 +6,8 @@ // // -import Foundation import CoreData +import Foundation @objc(KodiServer) -public class KodiServer: NSManagedObject { - -} +public class KodiServer: NSManagedObject {} diff --git a/Ferrite/DataManagement/Classes/KodiServer+CoreDataProperties.swift b/Ferrite/DataManagement/Classes/KodiServer+CoreDataProperties.swift index e8a8ece..ff3875d 100644 --- a/Ferrite/DataManagement/Classes/KodiServer+CoreDataProperties.swift +++ b/Ferrite/DataManagement/Classes/KodiServer+CoreDataProperties.swift @@ -6,23 +6,18 @@ // // -import Foundation import CoreData +import Foundation - -extension KodiServer { - - @nonobjc public class func fetchRequest() -> NSFetchRequest { - return NSFetchRequest(entityName: "KodiServer") +public extension KodiServer { + @nonobjc class func fetchRequest() -> NSFetchRequest { + NSFetchRequest(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 {} diff --git a/Ferrite/Models/ActionModels.swift b/Ferrite/Models/ActionModels.swift index 25888c0..86b8582 100644 --- a/Ferrite/Models/ActionModels.swift +++ b/Ferrite/Models/ActionModels.swift @@ -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) } } diff --git a/Ferrite/ViewModels/LoggingManager.swift b/Ferrite/ViewModels/LoggingManager.swift index bdce46f..3e84b14 100644 --- a/Ferrite/ViewModels/LoggingManager.swift +++ b/Ferrite/ViewModels/LoggingManager.swift @@ -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( diff --git a/Ferrite/ViewModels/PluginManager.swift b/Ferrite/ViewModels/PluginManager.swift index 9229615..5dfc965 100644 --- a/Ferrite/ViewModels/PluginManager.swift +++ b/Ferrite/ViewModels/PluginManager.swift @@ -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)") } } diff --git a/Ferrite/Views/ComponentViews/Settings/Kodi/KodiEditorView.swift b/Ferrite/Views/ComponentViews/Settings/Kodi/KodiEditorView.swift index c39948e..86e1411 100644 --- a/Ferrite/Views/ComponentViews/Settings/Kodi/KodiEditorView.swift +++ b/Ferrite/Views/ComponentViews/Settings/Kodi/KodiEditorView.swift @@ -79,7 +79,7 @@ struct KodiEditorView: View { presentationMode.wrappedValue.dismiss() } } - + ToolbarItem(placement: .navigationBarTrailing) { Button("Save") { do { diff --git a/Ferrite/Views/ComponentViews/Settings/PluginList/SettingsPluginListView.swift b/Ferrite/Views/ComponentViews/Settings/PluginList/SettingsPluginListView.swift index 2e5fdb3..82da472 100644 --- a/Ferrite/Views/ComponentViews/Settings/PluginList/SettingsPluginListView.swift +++ b/Ferrite/Views/ComponentViews/Settings/PluginList/SettingsPluginListView.swift @@ -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) diff --git a/Ferrite/Views/MainView.swift b/Ferrite/Views/MainView.swift index b130b82..28e5c2b 100644 --- a/Ferrite/Views/MainView.swift +++ b/Ferrite/Views/MainView.swift @@ -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 { diff --git a/Ferrite/Views/PluginsView.swift b/Ferrite/Views/PluginsView.swift index 4e57e7f..0c9315d 100644 --- a/Ferrite/Views/PluginsView.swift +++ b/Ferrite/Views/PluginsView.swift @@ -13,18 +13,18 @@ struct PluginsView: View { @EnvironmentObject var navModel: NavigationViewModel /* - @FetchRequest( - entity: Source.entity(), - sortDescriptors: [] - ) var sources: FetchedResults - */ + @FetchRequest( + entity: Source.entity(), + sortDescriptors: [] + ) var sources: FetchedResults + */ /* - @FetchRequest( - entity: Action.entity(), - sortDescriptors: [] - ) var actions: FetchedResults - */ + @FetchRequest( + entity: Action.entity(), + sortDescriptors: [] + ) var actions: FetchedResults + */ @AppStorage("Behavior.AutocorrectSearch") var autocorrectSearch = true