Compare commits

..

1 Commits

Author SHA1 Message Date
64b2cc6f29 Fix 2022-06-18 20:19:11 -07:00
3 changed files with 21 additions and 225 deletions

View File

@ -45,20 +45,14 @@ public class SocketController {
var addr = sockaddr_un() var addr = sockaddr_un()
addr.sun_family = sa_family_t(AF_UNIX) addr.sun_family = sa_family_t(AF_UNIX)
var len: Int = 0 let len = MemoryLayout.size(ofValue: addr.sun_path) - 1
withUnsafeMutablePointer(to: &addr.sun_path.0) { pointer in withUnsafeMutablePointer(to: &addr.sun_path.0) { pointer in
path.withCString { cstring in // The buffer is pre-zeroed, so manual termination is unnecessary.
len = strlen(cstring) precondition(memccpy(pointer, path, 0, len) != nil)
strncpy(pointer, cstring, len)
}
}
addr.sun_len = UInt8(len+2)
var data: Data!
withUnsafePointer(to: &addr) { pointer in
data = Data(bytes: pointer, count: MemoryLayout<sockaddr_un>.size)
} }
addr.sun_len = UInt8(len)
let data = withUnsafeBytes(of: &addr, Data.init(_:))
return SocketPort(protocolFamily: AF_UNIX, socketType: SOCK_STREAM, protocol: 0, address: data)! return SocketPort(protocolFamily: AF_UNIX, socketType: SOCK_STREAM, protocol: 0, address: data)!
} }

View File

@ -88,7 +88,7 @@ extension ContentView {
}, label: { }, label: {
Image(systemName: "plus") Image(systemName: "plus")
}) })
.sheet(isPresented: $showingCreation) { .popover(isPresented: $showingCreation, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) {
if let modifiable = storeList.modifiableStore { if let modifiable = storeList.modifiableStore {
CreateSecretView(store: modifiable, showing: $showingCreation) CreateSecretView(store: modifiable, showing: $showingCreation)
} }

View File

@ -8,40 +8,32 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
@State private var name = "" @State private var name = ""
@State private var requiresAuthentication = true @State private var requiresAuthentication = true
@State private var test: ThumbnailPickerView.Item = ThumbnailPickerView.Item(name: "Test", description: "Hello", thumbnail: Text("Hello"))
var body: some View { var body: some View {
VStack { VStack {
HStack { HStack {
Image(nsImage: NSApplication.shared.applicationIconImage)
.resizable()
.frame(width: 64, height: 64)
.padding()
VStack { VStack {
HStack { HStack {
Text("Create a New Secret") Text("Create a New Secret").bold()
.font(.largeTitle)
Spacer() Spacer()
} }
HStack { HStack {
Text("Name:") Text("Name:")
TextField("Shhhhh", text: $name) TextField("Shhhhh", text: $name).focusable()
.focusable()
} }
if #available(macOS 12.0, *) { HStack {
ThumbnailPickerView(items: [ VStack(spacing: 20) {
ThumbnailPickerView.Item(name: "Requires Authentication Before Use", description: "You will be required to authenticate using Touch ID, Apple Watch, or password before each use.", thumbnail: AuthenticationView()), Picker("", selection: $requiresAuthentication) {
ThumbnailPickerView.Item(name: "Notify on Use", Text("Requires Authentication (Biometrics or Password) before each use").tag(true)
description: "No authentication is required while your Mac is unlocked.", Text("Authentication not required when Mac is unlocked").tag(false)
thumbnail: NotificationView()) }
], selection: $test) .pickerStyle(RadioGroupPickerStyle())
} else { }
// HStack { Spacer()
// VStack(spacing: 20) {
// Picker("", selection: $requiresAuthentication) {
// Text("Requires Authentication (Biometrics or Password) before each use").tag(true)
// Text("Authentication not required when Mac is unlocked").tag(false)
// }
// .pickerStyle(SegmentedPickerStyle())
// }
// Spacer()
// }
} }
} }
} }
@ -63,193 +55,3 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
showing = false showing = false
} }
} }
struct ThumbnailPickerView: View {
let items: [Item]
@Binding var selection: Item
var body: some View {
HStack {
ForEach(items) { item in
VStack {
item.thumbnail
.clipShape(RoundedRectangle(cornerRadius: 10))
.overlay(RoundedRectangle(cornerRadius: 10)
.stroke(lineWidth: item.id == selection.id ? 5 : 0))
.foregroundColor(.accentColor)
Text(item.name)
.bold()
Text(item.description)
}.onTapGesture {
selection = item
}
}
}.onAppear {
selection = items.first!
}
}
}
extension ThumbnailPickerView {
struct Item: Identifiable {
let id = UUID()
let name: String
let description: String
let thumbnail: AnyView
init<ViewType: View>(name: String, description: String, thumbnail: ViewType) {
self.name = name
self.description = description
self.thumbnail = AnyView(thumbnail)
}
}
}
@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()
@unknown default:
Rectangle()
.foregroundColor(Color(.systemPurple))
}
}
} else {
Rectangle()
.foregroundColor(Color(.systemPurple))
}
}
}
@available(macOS 12.0, *)
struct AuthenticationView: View {
var body: some View {
ZStack {
SystemBackgroundView(anchor: .center)
VStack {
Spacer()
Image(systemName: "touchid")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 100)
.foregroundColor(Color(.systemRed))
Spacer()
Text("Touch ID Prompt")
.font(.largeTitle)
.foregroundColor(.primary)
.redacted(reason: .placeholder)
Spacer()
VStack {
Text("Touch ID Detail prompt.Detail two.")
.font(.title3)
.foregroundColor(.primary)
Text("Touch ID Detail prompt.Detail two.")
.font(.title3)
.foregroundColor(.primary)
}
.redacted(reason: .placeholder)
Spacer()
RoundedRectangle(cornerRadius: 10)
.frame(width: 275, height: 40, alignment: .center)
.foregroundColor(.accentColor)
RoundedRectangle(cornerRadius: 10)
.frame(width: 275, height: 40, alignment: .center)
.foregroundColor(Color(.unemphasizedSelectedContentBackgroundColor))
}
.padding()
.background(
RoundedRectangle(cornerRadius: 15)
.foregroundStyle(.ultraThickMaterial)
)
.padding()
}
}
}
@available(macOS 12.0, *)
struct NotificationView: View {
var body: some View {
ZStack {
SystemBackgroundView(anchor: .topTrailing)
VStack {
Rectangle()
.background(Color.clear)
.foregroundStyle(.thinMaterial)
.frame(height: 35)
VStack {
HStack {
Spacer()
HStack {
Image(nsImage: NSApplication.shared.applicationIconImage)
.resizable()
.frame(width: 64, height: 64)
.foregroundColor(.primary)
.padding()
VStack(alignment: .leading) {
Text("Secretive")
.font(.largeTitle)
.foregroundColor(.primary)
Text("Secretive wants to sign some request")
.font(.title3)
.foregroundColor(.primary)
Text("Secretive wants to sign some request")
.font(.title3)
.foregroundColor(.primary)
}
.padding()
}
.redacted(reason: .placeholder)
.background(
RoundedRectangle(cornerRadius: 15)
.foregroundStyle(.ultraThickMaterial)
)
}
Spacer()
}
.padding()
}
}
}
}
#if DEBUG
struct CreateSecretView_Previews: PreviewProvider {
static var previews: some View {
Group {
CreateSecretView(store: Preview.StoreModifiable(), showing: .constant(true))
if #available(macOS 12.0, *) {
AuthenticationView().environment(\.colorScheme, .dark)
AuthenticationView().environment(\.colorScheme, .light)
NotificationView().environment(\.colorScheme, .dark)
NotificationView().environment(\.colorScheme, .light)
} else {
// Fallback on earlier versions
}
}
}
}
#endif