Skip to content

Commit

Permalink
Add setting to quit after picking color
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 22, 2023
1 parent 452bec8 commit 0535cca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Color Picker/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ final class AppState: ObservableObject {
if NSEvent.modifiers == .shift {
pickColor()
}

if
Defaults[.quitAfterPicking],
Defaults[.copyColorAfterPicking],
!Defaults[.showInMenuBar]
{
SSApp.quit()
}
}
}

Expand Down
1 change: 1 addition & 0 deletions Color Picker/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extension Defaults.Keys {
static let shownColorFormats = Key<Set<ColorFormat>>("shownColorFormats", default: [.hex, .hsl, .rgb, .lch])
static let largerText = Key<Bool>("largerText", default: false)
static let copyColorAfterPicking = Key<Bool>("copyColorAfterPicking", default: false)
static let quitAfterPicking = Key<Bool>("quitAfterPicking", default: false)
static let showAccessibilityColorName = Key<Bool>("showAccessibilityColorName", default: false)
static let stickyPaletteName = Key<String?>("stickyPaletteName")
}
Expand Down
7 changes: 7 additions & 0 deletions Color Picker/SettingsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct SettingsScreen: View {

private struct GeneralSettings: View {
@Default(.showInMenuBar) private var showInMenuBar
@Default(.copyColorAfterPicking) private var copyColorAfterPicking

var body: some View {
Form {
Expand All @@ -45,6 +46,12 @@ private struct GeneralSettings: View {
Defaults.Toggle("Stay on top", key: .stayOnTop)
.help("Make the color picker window stay on top of all other windows.")
Defaults.Toggle("Copy color in preferred format after picking", key: .copyColorAfterPicking)
if
copyColorAfterPicking,
!showInMenuBar
{
Defaults.Toggle("Quit after picking", key: .quitAfterPicking)
}
}
Section {} footer: {
Button("Feedback & Support") {
Expand Down

0 comments on commit 0535cca

Please sign in to comment.