Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
Fixes #40
  • Loading branch information
sindresorhus committed May 8, 2024
1 parent aa43517 commit 04b4f5a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 36 deletions.
16 changes: 9 additions & 7 deletions Color Picker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,15 @@
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Intents Extension/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = "Intents Extension";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INFOPLIST_KEY_CFBundleDisplayName = "Color Picker Intents Extension";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.sindresorhus.Color-Picker.Intents-Extension";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG APP_EXTENSION";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -388,15 +388,15 @@
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Intents Extension/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = "Intents Extension";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INFOPLIST_KEY_CFBundleDisplayName = "Color Picker Intents Extension";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.sindresorhus.Color-Picker.Intents-Extension";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = APP_EXTENSION;
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -459,7 +459,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 14.1;
MACOSX_DEPLOYMENT_TARGET = 14.4;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -519,7 +519,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 14.1;
MACOSX_DEPLOYMENT_TARGET = 14.4;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
Expand All @@ -544,6 +544,7 @@
DEVELOPMENT_TEAM = YG56YK5RN5;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Color Picker/Info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -571,6 +572,7 @@
DEVELOPMENT_TEAM = YG56YK5RN5;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Color Picker/Info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -629,7 +631,7 @@
repositoryURL = "https://github.com/sindresorhus/KeyboardShortcuts";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.9.0;
minimumVersion = 2.0.0;
};
};
E3E14060259A0D97004FC89F /* XCRemoteSwiftPackageReference "Defaults" */ = {
Expand Down
4 changes: 4 additions & 0 deletions Color Picker/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extension Defaults.Keys {
static let recentlyPickedColors = Key<[NSColor]>("recentlyPickedColors", default: [])

// Settings

static let showInMenuBar = Key<Bool>("showInMenuBar", default: false)
static let hideMenuBarIcon = Key<Bool>("hideMenuBarIcon", default: false)
static let showColorSamplerOnOpen = Key<Bool>("showColorSamplerOnOpen", default: false)
Expand All @@ -25,7 +26,10 @@ extension Defaults.Keys {
static let showAccessibilityColorName = Key<Bool>("showAccessibilityColorName", default: false)
static let stickyPaletteName = Key<String?>("stickyPaletteName")


// Hidden settings

// defaults write com.sindresorhus.System-Color-Picker showOnAllSpaces -bool false
static let showOnAllSpaces = Key<Bool>("showOnAllSpaces", default: true)
}

Expand Down
20 changes: 0 additions & 20 deletions Color Picker/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>MDItemKeywords</key>
<string>color,picker,system,pick,colour,colors,colours,sampler</string>
</dict>
Expand Down
30 changes: 28 additions & 2 deletions Color Picker/MainScreen.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import SwiftUI
import TipKit

struct MainScreen: View {
// Note to self: Do not access the color picker here as it would create an infinite loop.

@Default(.uppercaseHexColor) private var uppercaseHexColor
@Default(.hashPrefixInHexColor) private var hashPrefixInHexColor
@Default(.legacyColorSyntax) private var legacyColorSyntax
Expand All @@ -10,6 +13,7 @@ struct MainScreen: View {
@State private var isPreventingUpdate = false
@State private var focusedTextField: ColorFormat?
@State private var colorStrings = EnumCaseMap<ColorFormat, String>(defaultValue: "")
@State private var colorAccessibilityName: String?

let colorPanel: NSColorPanel

Expand All @@ -18,6 +22,9 @@ struct MainScreen: View {
BarView()
colorInputs
colorName
if SSApp.isFirstLaunch { // Note: We only show it on first launch as TipKit doesn't currently preserve the dismissed state. (macOS 14.3)
TipView(ColorPaletteTip())
}
}
.padding(9)
// 244 makes `HSL` always fit in the text field.
Expand All @@ -35,13 +42,18 @@ struct MainScreen: View {
.onChange(of: legacyColorSyntax) {
updateColorsFromPanel()
}
.onReceive(colorPanel.colorDidChangePublisher) {
.onReceive(colorPanel.colorDidChange) {
colorAccessibilityName = colorPanel.color.accessibilityName

guard focusedTextField == nil else {
return
}

updateColorsFromPanel(preventUpdate: true)
}
.task {
try? Tips.configure()
}
}

private func updateColorsFromPanel(
Expand Down Expand Up @@ -124,7 +136,7 @@ struct MainScreen: View {
@ViewBuilder
private var colorName: some View {
if showAccessibilityColorName {
Text(colorPanel.color.accessibilityName)
Text(colorAccessibilityName ?? colorPanel.color.accessibilityName)
.font(.system(largerText ? .title3 : .body))
.textSelection(.enabled)
.accessibilityHidden(true)
Expand Down Expand Up @@ -358,3 +370,17 @@ private struct PalettesButton: View {
}
}
}

private struct ColorPaletteTip: Tip {
var title: Text {
Text("Creating a Color Palette")
}

var message: Text? {
Text("To create a new color palette, click the third tab at the top of the window, click the \(Image(systemName: "ellipsis.circle")) button, and then select “New”.")
}

var image: Image? {
Image(systemName: "swatchpalette")
}
}
32 changes: 27 additions & 5 deletions Color Picker/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ extension SSApp {
Initialize Sentry.
*/
static func initSentry(_ dsn: String) {
#if !DEBUG && canImport(Sentry)
#if !DEBUG && !APP_EXTENSION && canImport(Sentry)
SentrySDK.start {
$0.dsn = dsn
$0.enableSwizzling = false
Expand Down Expand Up @@ -1278,7 +1278,7 @@ extension NSColorPanel {
/**
Publishes when the color in the color panel changes.
*/
var colorDidChangePublisher: some Publisher<Void, Never> {
var colorDidChange: some Publisher<Void, Never> {
NotificationCenter.default
.publisher(for: Self.colorDidChangeNotification, object: self)
.map { _ in }
Expand Down Expand Up @@ -2054,7 +2054,7 @@ extension NSObject {
}


enum SSPublishers {
enum SSEvents {
/**
Publishes when the app becomes active/inactive.
*/
Expand Down Expand Up @@ -2157,7 +2157,10 @@ extension NSPasteboard {

@Published var pasteboard: NSPasteboard {
didSet {
if onlyWhenAppIsActive, !NSApp.isActive {
if
onlyWhenAppIsActive,
!NSApp.isActive
{
stop()
return
}
Expand All @@ -2178,7 +2181,7 @@ extension NSPasteboard {
self.onlyWhenAppIsActive = onlyWhileAppIsActive

if onlyWhileAppIsActive {
SSPublishers.appIsActive
SSEvents.appIsActive
.sink { [weak self] isActive in
guard let self else {
return
Expand Down Expand Up @@ -3302,6 +3305,7 @@ extension NSStatusItem {
/**
Show a one-time menu from the status item.
*/
@MainActor
func showMenu(_ menu: NSMenu) {
self.menu = menu
button!.performClick(nil)
Expand Down Expand Up @@ -3459,6 +3463,7 @@ extension NSColorList {
.filter { !$0.allKeys.isEmpty }
// `availableColorLists` returns duplicates after editing a palette, for example, adding a color to it.
.removingDuplicates()
.sorted(using: .keyPath(\.name))
}

var colors: [Color.Resolved] {
Expand Down Expand Up @@ -3555,3 +3560,20 @@ extension NSColorPanel {
}
}
}


extension SortComparator {
static func keyPath<Compared, Value: Comparable>(
_ keyPath: KeyPath<Compared, Value>,
order: SortOrder = .forward
) -> KeyPathComparator<Compared> where Self == KeyPathComparator<Compared> {
.init(keyPath, order: order)
}

static func keyPath<Compared, Value: Comparable>(
_ keyPath: KeyPath<Compared, Value?>,
order: SortOrder = .forward
) -> KeyPathComparator<Compared> where Self == KeyPathComparator<Compared> {
.init(keyPath, order: order)
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The macOS color picker as an app with lots of extra features.

## Download

[![](https://tools.applemediaservices.com/api/badges/download-on-the-mac-app-store/black/en-us?size=250x83&releaseDate=1615852800)](https://apps.apple.com/app/id1545870783)
[![](https://sindresorhus.com/assets/download-on-app-store-badge.svg)](https://apps.apple.com/app/id1545870783)

Requires macOS 14 or later.

Expand Down Expand Up @@ -66,7 +66,7 @@ You can use the following keyboard shortcuts in the app:

The built-in color picker supports plugins:

- [Scala Color](https://bjango.com/mac/skalacolor/)
- [Skala Color](https://bjango.com/mac/skalacolor/)
- [Pro Picker](https://formulae.brew.sh/cask/colorpicker-propicker)
- [Material Design](https://github.com/johnyanarella/MaterialDesignColorPicker)
- [Color Picker Plus](https://github.com/viktorstrate/color-picker-plus)
Expand Down

0 comments on commit 04b4f5a

Please sign in to comment.