From 855772a4ba4a2ba586e971a711f94b5eebd853b9 Mon Sep 17 00:00:00 2001 From: Wolf McNally Date: Tue, 8 Mar 2022 17:53:17 -0800 Subject: [PATCH] #152, Seed Detail Name field menu. --- README.md | 5 ++++ SeedTool/Seeds/SeedDetail.swift | 28 ++++++++++++++++------ SeedTool/Utils/LifeHashNameGenerator.swift | 21 ++++++++++------ SeedTool/Views/ContextMenuItem.swift | 8 +++++++ 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 57f6eb02..144350b8 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,11 @@ _For related Threat Modeling, see the [Seed Tool Manual](https://github.com/Bloc * QR Code Display: To increase compatibility with certain QR code readers, QR codes are now displayed as black modules (pixels) on a white background, even in dark mode. * Other bug fixes and minor enhancements. +### 1.4 (55) + +* #152 In the Seed Detail screen, the "Randomize" and "Clear Field" buttons that appear in the Seed Name field when editing it have been replaced with a menu button that includes "Randomize" and "Clear" commands, that only appears when the field is *not* being edited. This is to reduce the chance of the user accidentally changing the field. +* When responding to a request for a key derivation that asks the user to select a seed, the pre-seed selection screen now shows information about the derivation path, as well as any note included with the request. This is in addition to showing this information on the request approval scren. + ### 1.4 (54) * Seed Tool now shows any associated note attached to requests for seeds or keys. It displays the note text in a distinctive style and warns the user to be careful about whether to trust what the note contains. To facilitate testing this, the "Show Example Request..." functions now include a dummy note. diff --git a/SeedTool/Seeds/SeedDetail.swift b/SeedTool/Seeds/SeedDetail.swift index 082475a4..60c4d565 100644 --- a/SeedTool/Seeds/SeedDetail.swift +++ b/SeedTool/Seeds/SeedDetail.swift @@ -10,6 +10,7 @@ import Combine import SwiftUIFlowLayout import BCFoundation import WolfLorem +import LifeHash struct SeedDetail: View { @ObservedObject var seed: ModelSeed @@ -307,13 +308,8 @@ struct SeedDetail: View { } .focused($nameIsFocused) .accessibility(label: Text("Name Field")) - if isEditingNameField { - HStack(spacing: 20) { - FieldRandomTitleButton(seed: seed, text: $seed.name) - FieldClearButton(text: $seed.name) - .accessibility(label: Text("Clear Name")) - } - .font(.title3) + if !isEditingNameField { + nameFieldMenu } } .validation(seed.nameValidator) @@ -322,6 +318,24 @@ struct SeedDetail: View { } } + var nameFieldMenu: some View { + Menu { + RandomizeMenuItem() { + let lifehashState = LifeHashState(seed.fingerprint, version: .version2, generateAsync: false) + let generator = LifeHashNameGenerator(lifeHashState: lifehashState) + seed.name = generator.next() + } + ClearMenuItem() { + seed.name = "" + } + } label: { + Image.menu + .foregroundColor(.secondary) + .font(.title3) + } + .accessibility(label: Text("Name Menu")) + } + static var notesLabel: some View { Label( title: { Text("Notes").bold() }, diff --git a/SeedTool/Utils/LifeHashNameGenerator.swift b/SeedTool/Utils/LifeHashNameGenerator.swift index 96572003..f5aa991c 100644 --- a/SeedTool/Utils/LifeHashNameGenerator.swift +++ b/SeedTool/Utils/LifeHashNameGenerator.swift @@ -21,16 +21,23 @@ final class LifeHashNameGenerator: ObservableObject { .receive(on: DispatchQueue.global()) .map { uiImage in guard let uiImage = uiImage else { return "Untitled" } - - if let matchedColors = getMatchedColors(for: uiImage, quality: .highest) { - self.colorName = matchedColors.background.namedColor.name - } else { - self.colorName = NamedColor.colors.randomElement()!.name - } - return self.next() + return self.update(image: uiImage) } .receive(on: DispatchQueue.main) .assign(to: &$suggestedName) + + if let image = lifeHashState.osImage { + suggestedName = update(image: image) + } + } + + func update(image: OSImage) -> String { + if let matchedColors = getMatchedColors(for: image, quality: .highest) { + self.colorName = matchedColors.background.namedColor.name + } else { + self.colorName = NamedColor.colors.randomElement()!.name + } + return self.next() } func next() -> String { diff --git a/SeedTool/Views/ContextMenuItem.swift b/SeedTool/Views/ContextMenuItem.swift index 1cbabc86..680f0964 100644 --- a/SeedTool/Views/ContextMenuItem.swift +++ b/SeedTool/Views/ContextMenuItem.swift @@ -70,3 +70,11 @@ struct ClearMenuItem: View { ContextMenuItem(title: "Clear", image: Image.clear, action: action) } } + +struct RandomizeMenuItem: View { + let action: () -> Void + + var body: some View { + ContextMenuItem(title: "Randomize", image: Image.randomize, action: action) + } +}