Sources/Orgstar/CryptHoldBar.swift

9954efcbf435b2e8d78a4b59bfbbbb67c1b6c379
orgstar/Sources/Orgstar/CryptHoldBar.swift

45 lines · 1772 bytes

 1import OrgApp
 2import OrgDocument
 3import SwiftUI
 4
 5/// Above the mode line while the focused file isn't saved because it would put text on disk
 6/// unencrypted: why, and the button that asks for the passphrase. Stays while it applies.
 7struct CryptHoldBar: View {
 8    let session: DocumentSession
 9    let encrypt: () -> Void
10
11    var body: some View {
12        if let path = session.path, let hold = session.held[path] {
13            HStack(spacing: 8) {
14                Image(systemName: "lock.trianglebadge.exclamationmark").foregroundStyle(.orange)
15                Text(hold.notice(for: path)).lineLimit(3)
16                Spacer(minLength: 8)
17                if hold.takesPassphrase { Button(hold == .file ? "Set Passphrase…" : "Encrypt…", action: encrypt) }
18            }
19            .font(.callout)
20            .padding(.horizontal, 10)
21            .padding(.vertical, 5)
22            .frame(maxWidth: .infinity, alignment: .leading)
23            .background(Color.orange.opacity(0.12))
24            .accessibilityElement(children: .combine)
25        }
26    }
27}
28
29/// The session follows the org-crypt settings, and asks for the passphrase of an encrypted file
30/// it was asked to open.
31struct CryptSettings: ViewModifier {
32    let session: DocumentSession
33    let cryptBeforeSave: Bool
34    let cryptTagMatcher: String
35    let unlock: (String) -> Void
36
37    func body(content: Content) -> some View {
38        content
39            .onChange(of: cryptBeforeSave, initial: true) { _, on in session.encryptsTaggedEntries = on }
40            .onChange(of: cryptTagMatcher, initial: true) { session.cryptTag = OrgPreferences.cryptTag() }
41            .onChange(of: session.unlockRequest, initial: true) { _, path in
42                if let path { unlock(path) }
43            }
44    }
45}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form