Ferrite-backup/Ferrite/Views/ComponentViews/Plugin/Buttons/InstalledPluginButtonView.swift
kingbri 39a705717e Plugins: Unify settings
Plugin settings used to only be available for installed sources.
Change this to display info about an installed plugin and add settings
depending on the plugin type.

For example, a source will have additional settings specified by its
own views.

Signed-off-by: kingbri <bdashore3@proton.me>
2023-03-24 17:20:40 -04:00

71 lines
2.1 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
@ObservedObject var installedPlugin: P
@Binding var showPluginOptions: Bool
@Binding var selectedPlugin: 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(spacing: 5) {
Text(installedPlugin.name)
Text("v\(installedPlugin.version)")
.foregroundColor(.secondary)
}
Text("by \(installedPlugin.author)")
.foregroundColor(.secondary)
.lineLimit(1)
}
if let tags = installedPlugin.getTags(), !tags.isEmpty {
PluginTagsView(tags: tags)
}
}
.padding(.vertical, 2)
}
.contextMenu {
Button {
selectedPlugin = installedPlugin
showPluginOptions.toggle()
} label: {
Text("Options")
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")
}
}
}
}
}