Skip to content

Commit

Permalink
#152, Seed Detail Name field menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfmcnally committed Mar 9, 2022
1 parent 6729281 commit 855772a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 21 additions & 7 deletions SeedTool/Seeds/SeedDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Combine
import SwiftUIFlowLayout
import BCFoundation
import WolfLorem
import LifeHash

struct SeedDetail: View {
@ObservedObject var seed: ModelSeed
Expand Down Expand Up @@ -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)
Expand All @@ -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() },
Expand Down
21 changes: 14 additions & 7 deletions SeedTool/Utils/LifeHashNameGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions SeedTool/Views/ContextMenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 855772a

Please sign in to comment.