This commit is contained in:
Max Goedjen 2022-04-08 18:20:40 -07:00
parent 0bbf950216
commit e2e996d43f
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8
1 changed files with 24 additions and 23 deletions

View File

@ -2,13 +2,13 @@ import SwiftUI
import SecretKit
struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
@ObservedObject var store: StoreType
@Binding var showing: Bool
@State private var name = ""
@State private var requiresAuthentication = true
var body: some View {
VStack {
HStack {
@ -56,24 +56,25 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
}
}.padding()
}
func save() {
try! store.create(name: name, requiresAuthentication: requiresAuthentication)
showing = false
}
}
struct ThumbnailPickerView<ValueType: Hashable>: View {
private let items: [Item<ValueType>]
@Binding var selection: ValueType
init(items: [ThumbnailPickerView<ValueType>.Item<ValueType>], selection: Binding<ValueType>) {
self.items = items
_selection = selection
}
var body: some View {
HStack(alignment: .top) {
ForEach(items) { item in
@ -96,18 +97,18 @@ struct ThumbnailPickerView<ValueType: Hashable>: View {
}
}
}
}
extension ThumbnailPickerView {
struct Item<ValueType: Hashable>: Identifiable {
let id = UUID()
let value: ValueType
let name: String
let description: String
let thumbnail: AnyView
init<ViewType: View>(value: ValueType, name: String, description: String, thumbnail: ViewType) {
self.value = value
self.name = name
@ -115,14 +116,14 @@ extension ThumbnailPickerView {
self.thumbnail = AnyView(thumbnail)
}
}
}
@MainActor class SystemBackground: ObservableObject {
static let shared = SystemBackground()
@Published var image: NSImage?
private init() {
if let mainScreen = NSScreen.main, let imageURL = NSWorkspace.shared.desktopImageURL(for: mainScreen) {
image = NSImage(contentsOf: imageURL)
@ -130,14 +131,14 @@ extension ThumbnailPickerView {
image = nil
}
}
}
@available(macOS 12.0, *)
struct SystemBackgroundView: View {
let anchor: UnitPoint
var body: some View {
if let x = SystemBackground.shared.image {
Image(nsImage: x)
@ -154,7 +155,7 @@ struct SystemBackgroundView: View {
@available(macOS 12.0, *)
struct AuthenticationView: View {
var body: some View {
ZStack {
SystemBackgroundView(anchor: .center)
@ -192,15 +193,15 @@ struct AuthenticationView: View {
.foregroundStyle(.ultraThickMaterial)
)
.padding()
}
}
}
@available(macOS 12.0, *)
struct NotificationView: View {
var body: some View {
ZStack {
SystemBackgroundView(anchor: .topTrailing)
@ -238,13 +239,13 @@ struct NotificationView: View {
}
}
}
}
#if DEBUG
struct CreateSecretView_Previews: PreviewProvider {
static var previews: some View {
Group {
CreateSecretView(store: Preview.StoreModifiable(), showing: .constant(true))