-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathDefaults.swift
More file actions
147 lines (129 loc) · 6.25 KB
/
Copy pathDefaults.swift
File metadata and controls
147 lines (129 loc) · 6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import Cocoa
import Defaults
import SwiftUI
enum ColorFormat: String, Codable, CaseIterable, Equatable {
case hex = "Hex"
case rgb = "RGB"
case hsb = "HSB"
case hsl = "HSL"
case lab = "LAB"
case opengl = "OpenGL"
case oklch = "OKLCH"
func getExample(color: NSColor, style: CopyFormat) -> String {
color.toFormat(format: self, style: style)
}
static func withLabel(_ label: String) -> ColorFormat? {
allCases.first { label == "\($0)" }
}
}
enum CopyFormat: String, Codable, CaseIterable {
case css = "preferences.copy.options.css"
case design = "preferences.copy.options.design"
case swiftUI = "preferences.copy.options.swiftui"
case unformatted = "preferences.copy.options.unformatted"
func localizedString() -> String {
NSLocalizedString(rawValue, comment: "Copy Format")
}
}
enum ContrastStandard: String, Codable, CaseIterable {
case wcag = "WCAG"
case apca = "APCA"
case both = "BOTH"
func localizedString() -> String {
switch self {
case .wcag, .apca:
return rawValue
case .both:
return NSLocalizedString("color.standard.both", comment: "Both")
}
}
}
enum WindowShadow: String, Codable, CaseIterable {
case always = "preferences.shadow.options.always"
case hiddenWhilePicking = "preferences.shadow.options.hiddenWhilePicking"
case never = "preferences.shadow.options.never"
func localizedString() -> String {
NSLocalizedString(rawValue, comment: "Window Shadow")
}
/// The window's resting shadow state. `.hiddenWhilePicking` keeps the shadow at
/// rest and only drops it during an active pick (handled by the picker).
var showsShadowAtRest: Bool { self != .never }
}
enum PickerStyle: String, Codable, CaseIterable, Equatable {
case system // NSColorSampler (default, today's behaviour)
case custom // Pika-native loupe
}
enum LoupeTheme: String, Codable, CaseIterable, Equatable {
case lens // colour-filled rim engraved with the format + colour name (SF Pro)
case badge // white rounded badges hugging the inside edge (monospaced)
case card // plain magnifier with a readout card beside it
var localizedName: String {
switch self {
case .lens: return PikaText.textLoupeThemeLens
case .badge: return PikaText.textLoupeThemeBadge
case .card: return PikaText.textLoupeThemeCard
}
}
}
enum AppMode: String, Codable, CaseIterable {
case menubar = "preferences.app.mode.menubar"
case regular = "preferences.app.mode.regular"
case hidden = "preferences.app.mode.hidden"
case menubarPopover = "preferences.app.mode.menubarPopover"
func localizedString() -> String {
NSLocalizedString(rawValue, comment: "App Mode")
}
var activationPolicy: NSApplication.ActivationPolicy {
switch self {
case .regular: return .regular
case .menubar, .menubarPopover, .hidden: return .accessory
}
}
var usesStatusBarItem: Bool { self == .menubar || self == .menubarPopover }
var usesPopover: Bool { self == .menubarPopover }
}
extension Defaults.Keys {
static let colorFormat = Key<ColorFormat>("colorFormat", default: .hex)
static let viewedSplash = Key<Bool>("viewedSplash", default: false)
// The colour-name list to use, keyed to color.pizza's `/v1/lists/`. `default` is the
// list bundled at build time as the offline fallback.
static let colorNameList = Key<String>("colorNameList", default: "default")
// When false, the splash is shown on launch. The splash's pre-selected "Don't show
// this again" checkbox sets this to true on dismissal.
static let hideSplashOnLaunch = Key<Bool>("hideSplashOnLaunch", default: false)
// The `PikaConstants.currentSplashVersion` last shown to the user. Bumping that constant
// re-shows the splash once for everyone (even those who ticked "Don't show again"), so a
// release with new onboarding gets in front of existing users.
static let lastSeenSplashVersion = Key<Int>("lastSeenSplashVersion", default: 0)
static let hidePikaWhilePicking = Key<Bool>("hidePikaWhilePicking", default: false)
static let windowShadow = Key<WindowShadow>("windowShadow", default: .always)
static let pickContrastingColor = Key<Bool>("pickContrastingColor", default: false)
static let pickerStyle = Key<PickerStyle>("pickerStyle", default: .system)
static let loupeTheme = Key<LoupeTheme>("loupeTheme", default: .lens)
static let copyColorOnPick = Key<Bool>("copyColorOnPick", default: false)
static let hideMenuBarIcon = Key<Bool>("hideMenuBarIcon", default: false)
static let betaUpdates = Key<Bool>("betaUpdates", default: false)
static let combineCompliance = Key<Bool>("combineCompliance", default: false)
static let colorSpace = NSSecureCodingKey<NSColorSpace>(
"colorSpace", default: NSScreen.main!.colorSpace!
)
static let hideColorNames = Key<Bool>("hideColorNames", default: false)
static let formatColorsForCSS = Key<Bool>("formatColorsForCSS", default: false)
static let copyFormat = Key<CopyFormat>("copyFormat", default: .css)
static let appMode = Key<AppMode>("appMode", default: .menubar)
static let appFloating = Key<Bool>("appFloating", default: true)
static let alwaysShowOnLaunch = Key<Bool>("alwaysShowOnLaunch", default: false)
static let contrastStandard = Key<ContrastStandard>("contrastStandard", default: .wcag)
static let showColorOverlay = Key<Bool>("showColorOverlay", default: true)
static let colorOverlayDuration = Key<Double>("colorOverlayDuration", default: 2.0)
static let colorHistory = Key<[ColorPair]>("colorHistory", default: [])
static let palettes = Key<[Palette]>("palettes", default: [
Palette(id: UUID(), name: nil, pairs: [], createdAt: Date()),
])
static let activePaletteIndex = Key<Int>("activePaletteIndex", default: 0)
static let undoStack = Key<[[ColorPair]]>("undoStack", default: [])
static let redoStack = Key<[[ColorPair]]>("redoStack", default: [])
static let historyDrawerVisible = Key<Bool>("historyDrawerVisible", default: false)
static let showColorPreview = Key<Bool>("showColorPreview", default: false)
static let showCompliance = Key<Bool>("showCompliance", default: true)
}