From 0bbf950216a2dd040a12e91343f21a385556ddca Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sun, 20 Mar 2022 16:25:31 -0700 Subject: [PATCH] . --- .../xcshareddata/xcschemes/Secretive.xcscheme | 1 + .../Secretive/Views/CreateSecretView.swift | 86 ++++++++++--------- 2 files changed, 46 insertions(+), 41 deletions(-) diff --git a/Sources/Secretive.xcodeproj/xcshareddata/xcschemes/Secretive.xcscheme b/Sources/Secretive.xcodeproj/xcshareddata/xcschemes/Secretive.xcscheme index 7f8d2cb..757e085 100644 --- a/Sources/Secretive.xcodeproj/xcshareddata/xcschemes/Secretive.xcscheme +++ b/Sources/Secretive.xcodeproj/xcshareddata/xcschemes/Secretive.xcscheme @@ -75,6 +75,7 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" + enableGPUValidationMode = "1" allowLocationSimulation = "YES"> diff --git a/Sources/Secretive/Views/CreateSecretView.swift b/Sources/Secretive/Views/CreateSecretView.swift index 0538da1..eca8b10 100644 --- a/Sources/Secretive/Views/CreateSecretView.swift +++ b/Sources/Secretive/Views/CreateSecretView.swift @@ -2,13 +2,13 @@ import SwiftUI import SecretKit struct CreateSecretView: 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,7 +56,7 @@ struct CreateSecretView: View { } }.padding() } - + func save() { try! store.create(name: name, requiresAuthentication: requiresAuthentication) showing = false @@ -64,16 +64,16 @@ struct CreateSecretView: View { } struct ThumbnailPickerView: View { - + private let items: [Item] @Binding var selection: ValueType - + init(items: [ThumbnailPickerView.Item], selection: Binding) { self.items = items _selection = selection } - - + + var body: some View { HStack(alignment: .top) { ForEach(items) { item in @@ -96,18 +96,18 @@ struct ThumbnailPickerView: View { } } } - + } extension ThumbnailPickerView { - + struct Item: Identifiable { let id = UUID() let value: ValueType let name: String let description: String let thumbnail: AnyView - + init(value: ValueType, name: String, description: String, thumbnail: ViewType) { self.value = value self.name = name @@ -115,32 +115,36 @@ 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) + } else { + image = nil + } + } + } @available(macOS 12.0, *) struct SystemBackgroundView: View { - + let anchor: UnitPoint - + var body: some View { - if let mainScreen = NSScreen.main, let imageURL = NSWorkspace.shared.desktopImageURL(for: mainScreen) { - AsyncImage(url: imageURL) { phase in - switch phase { - case .empty, .failure: - Rectangle() - .foregroundColor(Color(.systemPurple)) - case .success(let image): - image - .resizable() - .scaleEffect(3, anchor: anchor) - .clipped() - .allowsHitTesting(false) - @unknown default: - Rectangle() - .foregroundColor(Color(.systemPurple)) - } - } + if let x = SystemBackground.shared.image { + Image(nsImage: x) + .resizable() + .scaleEffect(3, anchor: anchor) + .clipped() + .allowsHitTesting(false) } else { Rectangle() .foregroundColor(Color(.systemPurple)) @@ -150,7 +154,7 @@ struct SystemBackgroundView: View { @available(macOS 12.0, *) struct AuthenticationView: View { - + var body: some View { ZStack { SystemBackgroundView(anchor: .center) @@ -188,15 +192,15 @@ struct AuthenticationView: View { .foregroundStyle(.ultraThickMaterial) ) .padding() - + } } - + } @available(macOS 12.0, *) struct NotificationView: View { - + var body: some View { ZStack { SystemBackgroundView(anchor: .topTrailing) @@ -222,11 +226,11 @@ struct NotificationView: View { .foregroundColor(.primary) } }.padding() - .redacted(reason: .placeholder) - .background( - RoundedRectangle(cornerRadius: 15) - .foregroundStyle(.ultraThickMaterial) - ) + .redacted(reason: .placeholder) + .background( + RoundedRectangle(cornerRadius: 15) + .foregroundStyle(.ultraThickMaterial) + ) } Spacer() } @@ -234,13 +238,13 @@ struct NotificationView: View { } } } - + } #if DEBUG struct CreateSecretView_Previews: PreviewProvider { - + static var previews: some View { Group { CreateSecretView(store: Preview.StoreModifiable(), showing: .constant(true))