Skip to content

Commit b934cae

Browse files
Address PR review feedback from #200
Fix swap undo consistency, context menu labels, index clamping, filename sanitization, compliance icon differentiation, unused import, and migration guard. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b227aff commit b934cae

6 files changed

Lines changed: 33 additions & 11 deletions

File tree

Pika/AppDelegate.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,18 @@ class AppDelegate: NSObject, NSApplicationDelegate {
133133
let existing = Defaults[.colorHistory]
134134
guard !existing.isEmpty else { return }
135135
let history = Palette(id: UUID(), name: nil, pairs: existing, createdAt: Date())
136-
Defaults[.palettes] = [history]
136+
var palettes = Defaults[.palettes]
137+
if palettes.isEmpty {
138+
palettes = [history]
139+
} else {
140+
palettes[0] = Palette(
141+
id: palettes[0].id,
142+
name: palettes[0].name,
143+
pairs: existing + palettes[0].pairs,
144+
createdAt: palettes[0].createdAt
145+
)
146+
}
147+
Defaults[.palettes] = palettes
137148
Defaults[.colorHistory] = []
138149
}
139150

Pika/Services/Exporter.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Defaults
21
import Foundation
32

43
class Exporter {

Pika/Services/Eyedroppers.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ class Eyedroppers: ObservableObject {
7979
}
8080

8181
func swap() {
82-
pushUndo()
82+
let paletteIndex = Defaults[.activePaletteIndex]
83+
if paletteIndex == 0 { pushUndo() }
8384
let temp = foreground.color
8485
foreground.color = background.color
8586
background.color = temp
86-
87-
let paletteIndex = Defaults[.activePaletteIndex]
8887
var palettes = Defaults[.palettes]
8988
guard paletteIndex >= 0, paletteIndex < palettes.count else { return }
9089

Pika/Views/ColorHistoryDrawer.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct ColorHistoryChip: View {
99
let onApplyBackground: () -> Void
1010
let onRemove: () -> Void
1111
let onClearAll: (() -> Void)?
12+
var isAutoHistory: Bool = true
1213

1314
@State private var isHovered = false
1415

@@ -40,7 +41,7 @@ struct ColorHistoryChip: View {
4041
Button(PikaText.textHistoryApplyForeground, action: onApplyForeground)
4142
Button(PikaText.textHistoryApplyBackground, action: onApplyBackground)
4243
Divider()
43-
Button(PikaText.textHistoryRemove, action: onRemove)
44+
Button(isAutoHistory ? PikaText.textHistoryRemove : PikaText.textPaletteRemoveChip, action: onRemove)
4445
if let onClearAll = onClearAll {
4546
Button(PikaText.textHistoryClear, action: onClearAll)
4647
}
@@ -217,12 +218,15 @@ struct ColorHistoryDrawer: View {
217218

218219
private var activePalette: Palette? {
219220
let idx = activePaletteIndex
220-
guard idx >= 0, idx < palettes.count else { return palettes.first }
221+
guard idx >= 0, idx < palettes.count else {
222+
DispatchQueue.main.async { activePaletteIndex = 0 }
223+
return palettes.first
224+
}
221225
return palettes[idx]
222226
}
223227

224228
private var isAutoHistory: Bool {
225-
activePaletteIndex == 0
229+
activePalette?.isAutoHistory ?? false
226230
}
227231

228232
var body: some View {
@@ -241,7 +245,8 @@ struct ColorHistoryDrawer: View {
241245
onApplyForeground: { applyForeground(pair) },
242246
onApplyBackground: { applyBackground(pair) },
243247
onRemove: { removePair(pair) },
244-
onClearAll: isAutoHistory ? { isShowingClearConfirm = true } : nil
248+
onClearAll: isAutoHistory ? { isShowingClearConfirm = true } : nil,
249+
isAutoHistory: isAutoHistory
245250
)
246251
.transition(.opacity)
247252
.animation(

Pika/Views/ContentView.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,24 @@ struct ContentView: View {
140140
guard let palette = palette else { return }
141141

142142
let json = Exporter.paletteToJSON(pairs: palette.pairs, name: palette.name)
143+
let invalidChars = CharacterSet(charactersIn: "/:\\")
143144
let fileName = (palette.name ?? "color-history")
144145
.lowercased()
145146
.replacingOccurrences(of: " ", with: "-")
147+
.components(separatedBy: invalidChars)
148+
.joined()
146149

147150
let savePanel = NSSavePanel()
148151
savePanel.allowedContentTypes = [.json]
149152
savePanel.nameFieldStringValue = "\(fileName).json"
150153
savePanel.isExtensionHidden = false
151154
if savePanel.runModal() == .OK, let url = savePanel.url {
152-
try? json.write(to: url, atomically: true, encoding: .utf8)
155+
do {
156+
try json.write(to: url, atomically: true, encoding: .utf8)
157+
} catch {
158+
let alert = NSAlert(error: error)
159+
alert.runModal()
160+
}
153161
}
154162
}
155163
}

Pika/Views/NavigationMenu.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct NavigationMenu: View {
4242
Button(action: {
4343
NSApp.sendAction(#selector(AppDelegate.triggerToggleCompliance), to: nil, from: nil)
4444
}, label: {
45-
IconImage(name: showCompliance ? "checkmark.shield" : "checkmark.shield")
45+
IconImage(name: showCompliance ? "checkmark.shield.fill" : "checkmark.shield")
4646
})
4747
.buttonStyle(PlainButtonStyle())
4848
.padding(.horizontal, 6.0)

0 commit comments

Comments
 (0)