mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-07-02 02:03:36 +00:00
Compare commits
1 Commits
newcreatio
...
xcode_14
Author | SHA1 | Date | |
---|---|---|---|
0eab79c4c4 |
@ -50,6 +50,7 @@
|
||||
50B8550D24138C4F009958AC /* DeleteSecretView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50B8550C24138C4F009958AC /* DeleteSecretView.swift */; };
|
||||
50BB046B2418AAAE00D6E079 /* EmptyStoreView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50BB046A2418AAAE00D6E079 /* EmptyStoreView.swift */; };
|
||||
50C385A52407A76D00AF2719 /* SecretDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C385A42407A76D00AF2719 /* SecretDetailView.swift */; };
|
||||
50C511B0285064DB00704B27 /* MainActorWrappers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C511AF285064DB00704B27 /* MainActorWrappers.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@ -147,6 +148,7 @@
|
||||
50B8550C24138C4F009958AC /* DeleteSecretView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeleteSecretView.swift; sourceTree = "<group>"; };
|
||||
50BB046A2418AAAE00D6E079 /* EmptyStoreView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyStoreView.swift; sourceTree = "<group>"; };
|
||||
50C385A42407A76D00AF2719 /* SecretDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecretDetailView.swift; sourceTree = "<group>"; };
|
||||
50C511AF285064DB00704B27 /* MainActorWrappers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainActorWrappers.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -187,6 +189,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
50033AC227813F1700253856 /* BundleIDs.swift */,
|
||||
50C511AF285064DB00704B27 /* MainActorWrappers.swift */,
|
||||
);
|
||||
path = Helpers;
|
||||
sourceTree = "<group>";
|
||||
@ -479,6 +482,7 @@
|
||||
50571E0324393C2600F76F6C /* JustUpdatedChecker.swift in Sources */,
|
||||
5079BA0F250F29BF00EA86F4 /* StoreListView.swift in Sources */,
|
||||
50617DD223FCEFA90099B055 /* PreviewStore.swift in Sources */,
|
||||
50C511B0285064DB00704B27 /* MainActorWrappers.swift in Sources */,
|
||||
5066A6F7251829B1004B5A36 /* ShellConfigurationController.swift in Sources */,
|
||||
50033AC327813F1700253856 /* BundleIDs.swift in Sources */,
|
||||
508A58B3241ED2180069DC07 /* AgentStatusChecker.swift in Sources */,
|
||||
|
17
Sources/Secretive/Helpers/MainActorWrappers.swift
Normal file
17
Sources/Secretive/Helpers/MainActorWrappers.swift
Normal file
@ -0,0 +1,17 @@
|
||||
import Foundation
|
||||
|
||||
func mainActorWrapped(_ f: @escaping @MainActor () -> Void) -> () -> Void {
|
||||
return {
|
||||
DispatchQueue.main.async {
|
||||
f()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mainActorWrapped<T: Sendable>(_ f: @escaping @MainActor (T) -> Void) -> (T) -> Void {
|
||||
return { x in
|
||||
DispatchQueue.main.async {
|
||||
f(x)
|
||||
}
|
||||
}
|
||||
}
|
@ -88,7 +88,7 @@ extension ContentView {
|
||||
}, label: {
|
||||
Image(systemName: "plus")
|
||||
})
|
||||
.sheet(isPresented: $showingCreation) {
|
||||
.popover(isPresented: $showingCreation, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) {
|
||||
if let modifiable = storeList.modifiableStore {
|
||||
CreateSecretView(store: modifiable, showing: $showingCreation)
|
||||
}
|
||||
|
@ -8,40 +8,32 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
|
||||
@State private var name = ""
|
||||
@State private var requiresAuthentication = true
|
||||
@State private var test: ThumbnailPickerView.Item = ThumbnailPickerView.Item(name: "Test", description: "Hello", thumbnail: Text("Hello"))
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
HStack {
|
||||
Image(nsImage: NSApplication.shared.applicationIconImage)
|
||||
.resizable()
|
||||
.frame(width: 64, height: 64)
|
||||
.padding()
|
||||
VStack {
|
||||
HStack {
|
||||
Text("Create a New Secret")
|
||||
.font(.largeTitle)
|
||||
Text("Create a New Secret").bold()
|
||||
Spacer()
|
||||
}
|
||||
HStack {
|
||||
Text("Name:")
|
||||
TextField("Shhhhh", text: $name)
|
||||
.focusable()
|
||||
TextField("Shhhhh", text: $name).focusable()
|
||||
}
|
||||
if #available(macOS 12.0, *) {
|
||||
ThumbnailPickerView(items: [
|
||||
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()),
|
||||
ThumbnailPickerView.Item(name: "Notify on Use",
|
||||
description: "No authentication is required while your Mac is unlocked.",
|
||||
thumbnail: NotificationView())
|
||||
], selection: $test)
|
||||
} else {
|
||||
// HStack {
|
||||
// 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()
|
||||
// }
|
||||
HStack {
|
||||
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(RadioGroupPickerStyle())
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,7 +43,7 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
showing = false
|
||||
}
|
||||
.keyboardShortcut(.cancelAction)
|
||||
Button("Create", action: save)
|
||||
Button("Create", action: mainActorWrapped(save))
|
||||
.disabled(name.isEmpty)
|
||||
.keyboardShortcut(.defaultAction)
|
||||
}
|
||||
@ -63,193 +55,3 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
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
|
||||
|
@ -33,7 +33,7 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
}
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Delete", action: delete)
|
||||
Button("Delete", action: mainActorWrapped(delete))
|
||||
.disabled(confirm != secret.name)
|
||||
.keyboardShortcut(.delete)
|
||||
Button("Don't Delete") {
|
||||
|
@ -28,7 +28,7 @@ struct RenameSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
}
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Rename", action: rename)
|
||||
Button("Rename", action: mainActorWrapped(rename))
|
||||
.disabled(newName.count == 0)
|
||||
.keyboardShortcut(.return)
|
||||
Button("Cancel") {
|
||||
|
@ -31,8 +31,8 @@ struct StoreListView: View {
|
||||
store: store,
|
||||
secret: secret,
|
||||
activeSecret: $activeSecret,
|
||||
deletedSecret: self.secretDeleted,
|
||||
renamedSecret: self.secretRenamed
|
||||
deletedSecret: mainActorWrapped(self.secretDeleted),
|
||||
renamedSecret: mainActorWrapped(self.secretRenamed)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user