From a7e20f30e6fc28dbfd29dfbc815f6e9e5a62602b Mon Sep 17 00:00:00 2001 From: kingbri Date: Wed, 27 Nov 2024 21:33:27 -0500 Subject: [PATCH] Settings: Properly report login status of Debrid services Since protocols can't be observed in SwiftUI, use a roundabout way to check if a user is logged in. Maybe this should be changed in the future, but it works for now. Signed-off-by: kingbri --- Ferrite.xcodeproj/project.pbxproj | 4 +++ .../Settings/SettingsDebridLinkView.swift | 31 +++++++++++++++++++ Ferrite/Views/SettingsView.swift | 11 +------ 3 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 Ferrite/Views/ComponentViews/Settings/SettingsDebridLinkView.swift diff --git a/Ferrite.xcodeproj/project.pbxproj b/Ferrite.xcodeproj/project.pbxproj index 9b2f02d..e8b1067 100644 --- a/Ferrite.xcodeproj/project.pbxproj +++ b/Ferrite.xcodeproj/project.pbxproj @@ -104,6 +104,7 @@ 0C8DC35429CE2AB5008A83AD /* SourceSettingsBaseUrlView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C8DC35329CE2AB5008A83AD /* SourceSettingsBaseUrlView.swift */; }; 0C8DC35629CE2ABF008A83AD /* SourceSettingsApiView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C8DC35529CE2ABF008A83AD /* SourceSettingsApiView.swift */; }; 0C8DC35829CE2ACA008A83AD /* SourceSettingsMethodView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C8DC35729CE2ACA008A83AD /* SourceSettingsMethodView.swift */; }; + 0C93DED82CF80101009EA8D2 /* SettingsDebridLinkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C93DED72CF80101009EA8D2 /* SettingsDebridLinkView.swift */; }; 0C95D8D828A55B03005E22B3 /* DefaultActionPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C95D8D728A55B03005E22B3 /* DefaultActionPickerView.swift */; }; 0CA05457288EE58200850554 /* SettingsPluginListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CA05456288EE58200850554 /* SettingsPluginListView.swift */; }; 0CA05459288EE9E600850554 /* PluginManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CA05458288EE9E600850554 /* PluginManager.swift */; }; @@ -259,6 +260,7 @@ 0C8DC35329CE2AB5008A83AD /* SourceSettingsBaseUrlView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceSettingsBaseUrlView.swift; sourceTree = ""; }; 0C8DC35529CE2ABF008A83AD /* SourceSettingsApiView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceSettingsApiView.swift; sourceTree = ""; }; 0C8DC35729CE2ACA008A83AD /* SourceSettingsMethodView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceSettingsMethodView.swift; sourceTree = ""; }; + 0C93DED72CF80101009EA8D2 /* SettingsDebridLinkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsDebridLinkView.swift; sourceTree = ""; }; 0C95D8D728A55B03005E22B3 /* DefaultActionPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultActionPickerView.swift; sourceTree = ""; }; 0CA05456288EE58200850554 /* SettingsPluginListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsPluginListView.swift; sourceTree = ""; }; 0CA05458288EE9E600850554 /* PluginManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginManager.swift; sourceTree = ""; }; @@ -555,6 +557,7 @@ 0C10848A28BD9A38008F0BA6 /* SettingsAppVersionView.swift */, 0C6771FD29B521F1005D38D2 /* SettingsDebridInfoView.swift */, 0C5708EA29B8F89300BE07F9 /* SettingsLogView.swift */, + 0C93DED72CF80101009EA8D2 /* SettingsDebridLinkView.swift */, ); path = Settings; sourceTree = ""; @@ -981,6 +984,7 @@ 0C32FB572890D1F2002BD219 /* ListRowViews.swift in Sources */, 0CEC8AAE299B31B6007BFE8F /* SearchFilterHeaderView.swift in Sources */, 0C84F4822895BFED0074B7C9 /* Source+CoreDataClass.swift in Sources */, + 0C93DED82CF80101009EA8D2 /* SettingsDebridLinkView.swift in Sources */, 0C3DD43F29B6968D006429DB /* KodiEditorView.swift in Sources */, 0CB725322C123E6F0047FC0B /* CloudDownloadView.swift in Sources */, 0C3DD44329B6ACD9006429DB /* KodiServer+CoreDataProperties.swift in Sources */, diff --git a/Ferrite/Views/ComponentViews/Settings/SettingsDebridLinkView.swift b/Ferrite/Views/ComponentViews/Settings/SettingsDebridLinkView.swift new file mode 100644 index 0000000..87d7818 --- /dev/null +++ b/Ferrite/Views/ComponentViews/Settings/SettingsDebridLinkView.swift @@ -0,0 +1,31 @@ +// +// SettingsDebridLinkView.swift +// Ferrite +// +// Created by Brian Dashore on 11/27/24. +// + +import SwiftUI + +struct SettingsDebridLinkView: View { + var debridSource: DebridSource + + // TODO: Use a roundabout state for now + @State private var isLoggedIn = false + + var body: some View { + NavigationLink { + SettingsDebridInfoView(debridSource: debridSource) + } label: { + HStack { + Text(debridSource.id) + Spacer() + Text(isLoggedIn ? "Enabled" : "Disabled") + .foregroundColor(.secondary) + } + } + .onAppear { + isLoggedIn = debridSource.isLoggedIn + } + } +} diff --git a/Ferrite/Views/SettingsView.swift b/Ferrite/Views/SettingsView.swift index 692ce43..74524ce 100644 --- a/Ferrite/Views/SettingsView.swift +++ b/Ferrite/Views/SettingsView.swift @@ -47,16 +47,7 @@ struct SettingsView: View { Form { Section(header: InlineHeader("Debrid services")) { ForEach(debridManager.debridSources, id: \.id) { (debridSource: DebridSource) in - NavigationLink { - SettingsDebridInfoView(debridSource: debridSource) - } label: { - HStack { - Text(debridSource.id) - Spacer() - Text(debridSource.isLoggedIn ? "Enabled" : "Disabled") - .foregroundColor(.secondary) - } - } + SettingsDebridLinkView(debridSource: debridSource) } }