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