Plugin entries were not syncing properly inside the plugins view. Instead of adding events to update filtered lists, make it so that these filtered lists are updated on state changes. This is the intended method of reactive programming and removes complexity from filtering logic. Signed-off-by: kingbri <bdashore3@proton.me>
71 lines
2.2 KiB
Swift
71 lines
2.2 KiB
Swift
//
|
|
// InstalledSourceButtonView.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 8/5/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct InstalledPluginButtonView<P: Plugin>: View {
|
|
let backgroundContext = PersistenceController.shared.backgroundContext
|
|
|
|
@EnvironmentObject var navModel: NavigationViewModel
|
|
|
|
@ObservedObject var installedPlugin: P
|
|
|
|
var body: some View {
|
|
Toggle(isOn: Binding<Bool>(
|
|
get: { installedPlugin.enabled },
|
|
set: {
|
|
installedPlugin.enabled = $0
|
|
PersistenceController.shared.save()
|
|
}
|
|
)) {
|
|
VStack(alignment: .leading) {
|
|
VStack(alignment: .leading, spacing: 5) {
|
|
HStack {
|
|
Text(installedPlugin.name)
|
|
Text("v\(installedPlugin.version)")
|
|
.foregroundColor(.secondary)
|
|
}
|
|
|
|
Text("by \(installedPlugin.author)")
|
|
.foregroundColor(.secondary)
|
|
}
|
|
|
|
if let tags = installedPlugin.getTags(), !tags.isEmpty {
|
|
PluginTagsView(tags: tags)
|
|
}
|
|
}
|
|
.padding(.vertical, 2)
|
|
}
|
|
.contextMenu {
|
|
if let installedSource = installedPlugin as? Source {
|
|
Button {
|
|
navModel.selectedSource = installedSource
|
|
navModel.showSourceSettings.toggle()
|
|
} label: {
|
|
Text("Settings")
|
|
Image(systemName: "gear")
|
|
}
|
|
}
|
|
|
|
if #available(iOS 15.0, *) {
|
|
Button(role: .destructive) {
|
|
PersistenceController.shared.delete(installedPlugin, context: backgroundContext)
|
|
} label: {
|
|
Text("Remove")
|
|
Image(systemName: "trash")
|
|
}
|
|
} else {
|
|
Button {
|
|
PersistenceController.shared.delete(installedPlugin, context: backgroundContext)
|
|
} label: {
|
|
Text("Remove")
|
|
Image(systemName: "trash")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|