This commit is contained in:
Max Goedjen 2020-03-20 21:14:51 -07:00
parent f674d47507
commit c5abca4099
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8
1 changed files with 21 additions and 21 deletions

View File

@ -3,15 +3,15 @@ import SwiftUI
import ServiceManagement import ServiceManagement
struct SetupView: View { struct SetupView: View {
var completion: ((Bool) -> Void)? var completion: ((Bool) -> Void)?
var body: some View { var body: some View {
Form { Form {
SetupStepView<Spacer>(text: "Secretive needs to install a helper app to sign requests when the main app isn't running. This app is called \"SecretAgent\" and you might see it in Activity Manager from time to time.", SetupStepView<Spacer>(text: "Secretive needs to install a helper app to sign requests when the main app isn't running. This app is called \"SecretAgent\" and you might see it in Activity Manager from time to time.",
index: 1, index: 1,
nestedView: nil, nestedView: nil,
actionText: "Install") { actionText: "Install") {
self.installLaunchAgent() self.installLaunchAgent()
} }
SetupStepView(text: "You need to add a line to your shell config (.bashrc or .zshrc) telling SSH to talk to SecretAgent when it wants to authenticate. Drag this into your config file.", SetupStepView(text: "You need to add a line to your shell config (.bashrc or .zshrc) telling SSH to talk to SecretAgent when it wants to authenticate. Drag this into your config file.",
@ -22,25 +22,25 @@ struct SetupView: View {
} }
HStack { HStack {
Spacer() Spacer()
Button(action: { self.completion?(true) }) { Button(action: { self.completion?(true) }) {
Text("Finish") Text("Finish")
} }
.padding() .padding()
} }
} }
} }
} }
struct SetupStepView<NestedViewType: View>: View { struct SetupStepView<NestedViewType: View>: View {
let text: String let text: String
let index: Int let index: Int
let nestedView: NestedViewType? let nestedView: NestedViewType?
@State var completed = false @State var completed = false
let actionText: String let actionText: String
let action: (() -> Bool) let action: (() -> Bool)
var body: some View { var body: some View {
Section { Section {
HStack { HStack {
@ -83,9 +83,9 @@ struct SetupStepView<NestedViewType: View>: View {
} }
struct SetupStepCommandView: View { struct SetupStepCommandView: View {
let text: String let text: String
var body: some View { var body: some View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
Text(text) Text(text)
@ -104,36 +104,36 @@ struct SetupStepCommandView: View {
.cornerRadius(10) .cornerRadius(10)
.onDrag { .onDrag {
return NSItemProvider(item: NSData(data: self.text.data(using: .utf8)!), typeIdentifier: kUTTypeUTF8PlainText as String) return NSItemProvider(item: NSData(data: self.text.data(using: .utf8)!), typeIdentifier: kUTTypeUTF8PlainText as String)
} }
} }
func copy() { func copy() {
NSPasteboard.general.declareTypes([.string], owner: nil) NSPasteboard.general.declareTypes([.string], owner: nil)
NSPasteboard.general.setString(text, forType: .string) NSPasteboard.general.setString(text, forType: .string)
} }
} }
extension SetupView { extension SetupView {
func installLaunchAgent() -> Bool { func installLaunchAgent() -> Bool {
SMLoginItemSetEnabled("com.maxgoedjen.Secretive.SecretAgent" as CFString, true) SMLoginItemSetEnabled("com.maxgoedjen.Secretive.SecretAgent" as CFString, true)
} }
func markAsDone() -> Bool { func markAsDone() -> Bool {
return true return true
} }
} }
extension SetupView { extension SetupView {
enum Constants { enum Constants {
static let socketPath = (NSHomeDirectory().replacingOccurrences(of: "com.maxgoedjen.Secretive.Host", with: "com.maxgoedjen.Secretive.SecretAgent") as NSString).appendingPathComponent("socket.ssh") as String static let socketPath = (NSHomeDirectory().replacingOccurrences(of: "com.maxgoedjen.Secretive.Host", with: "com.maxgoedjen.Secretive.SecretAgent") as NSString).appendingPathComponent("socket.ssh") as String
static let socketPrompt = "export SSH_AUTH_SOCK=\(socketPath)" static let socketPrompt = "export SSH_AUTH_SOCK=\(socketPath)"
} }
} }
#if DEBUG #if DEBUG