Skip to content

Commit

Permalink
Require macOS 12
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 30, 2022
1 parent 89a9cb5 commit 887b65b
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 235 deletions.
9 changes: 8 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ only_rules:
- discarded_notification_center_observer
- discouraged_assert
- discouraged_direct_init
- discouraged_none_name
- discouraged_object_literal
- discouraged_optional_boolean
- discouraged_optional_collection
- duplicate_enum_cases
- duplicate_imports
- duplicated_key_in_dictionary_literal
- dynamic_inline
- empty_collection_literal
- empty_count
Expand Down Expand Up @@ -82,6 +84,7 @@ only_rules:
- operator_whitespace
- orphaned_doc_comment
- overridden_super_call
- prefer_self_in_static_references
- prefer_self_type_over_type_of_self
- prefer_zero_over_explicit_init
- private_action
Expand All @@ -102,6 +105,8 @@ only_rules:
- redundant_void_return
- required_enum_case
- return_arrow_whitespace
- return_value_from_void_function
- self_in_property_initialization
- shorthand_operator
- sorted_first_last
- statement_position
Expand All @@ -118,6 +123,7 @@ only_rules:
- trailing_newline
- trailing_semicolon
- trailing_whitespace
- unavailable_condition
- unavailable_function
- unneeded_break_in_switch
- unneeded_parentheses_in_closure_argument
Expand All @@ -142,6 +148,7 @@ analyzer_rules:
- capture_variable
- unused_declaration
- unused_import
- typesafe_array_init
number_separator:
minimum_length: 5
identifier_name:
Expand All @@ -166,7 +173,7 @@ identifier_name:
- 'y2'
- 'z2'
deployment_target:
macOS_deployment_target: '11.3'
macOS_deployment_target: '12'
custom_rules:
no_nsrect:
regex: '\bNSRect\b'
Expand Down
8 changes: 4 additions & 4 deletions Color Picker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 11.5;
MACOSX_DEPLOYMENT_TARGET = 12.3;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -477,7 +477,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 11.5;
MACOSX_DEPLOYMENT_TARGET = 12.3;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -645,7 +645,7 @@
repositoryURL = "https://github.com/sindresorhus/KeyboardShortcuts";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.5.0;
minimumVersion = 1.6.0;
};
};
E3E14060259A0D97004FC89F /* XCRemoteSwiftPackageReference "Defaults" */ = {
Expand All @@ -661,7 +661,7 @@
repositoryURL = "https://github.com/getsentry/sentry-cocoa";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 7.12.0;
minimumVersion = 7.16.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
26 changes: 10 additions & 16 deletions Color Picker/App.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import SwiftUI
import Defaults

/**
NOTES:
- The "com.apple.security.files.user-selected.read-only" entitlement is required by the "Open" menu in the "Color Palettes" pane.
*/

@main
struct AppMain: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
Expand Down Expand Up @@ -49,23 +54,12 @@ struct AppMain: App {
.disabled(NSColor.fromPasteboardGraceful(.general) == nil)
}
CommandGroup(replacing: .help) {
Button("What is LCH color?") {
"https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/".openUrl()
}
Button("FAQ") {
"https://github.com/sindresorhus/System-Color-Picker#faq".openUrl()
}
Link("What is LCH color?", destination: "https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/")
Link("FAQ", destination: "https://github.com/sindresorhus/System-Color-Picker#faq")
Divider()
// TODO: Use `Link` when targeting macOS 12.
Button("Website") {
"https://sindresorhus.com/system-color-picker".openUrl()
}
Button("Rate on the App Store") {
"macappstore://apps.apple.com/app/id1545870783?action=write-review".openUrl()
}
Button("More Apps by Me") {
"macappstore://apps.apple.com/developer/id328077650".openUrl()
}
Link("Website", destination: "https://sindresorhus.com/system-color-picker")
Link("Rate on the App Store", destination: "macappstore://apps.apple.com/app/id1545870783?action=write-review")
Link("More Apps by Me", destination: "macappstore://apps.apple.com/developer/id328077650")
Divider()
Button("Send Feedback…") {
SSApp.openSendFeedbackPage()
Expand Down
13 changes: 4 additions & 9 deletions Color Picker/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ final class AppState: ObservableObject {

let item = $0

$0.button!.onAction { [self] event in
$0.button!.onAction = { [self] event in
let isAlternative = event.isAlternativeClickForStatusItem

let showMenu = { [self] in
Expand Down Expand Up @@ -168,11 +168,6 @@ final class AppState: ObservableObject {

// Make the invisible native SwiftUI window not show up in mission control when in menu bar mode. (macOS 11.6)
SSApp.swiftUIMainWindow?.collectionBehavior = .stationary

// We hide the “View” menu as there's a macOS bug where it sometimes enables even though it doesn't work and then causes a crash when clicked. Hiding it does not work on macOS 12.
if #available(macOS 12, *) {} else {
NSApp.mainMenu?.item(withTitle: "View")?.isHidden = true
}
}

private func requestReview() {
Expand Down Expand Up @@ -208,9 +203,9 @@ final class AppState: ObservableObject {
return
}

self.colorPanel.color = color
self.addToRecentlyPickedColor(color)
self.requestReview()
colorPanel.color = color
addToRecentlyPickedColor(color)
requestReview()

if Defaults[.copyColorAfterPicking] {
color.stringRepresentation.copyToPasteboard()
Expand Down
35 changes: 16 additions & 19 deletions Color Picker/ColorPickerScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ private struct RecentlyPickedColorsButton: View {
.labelStyle(.titleAndIcon)
}
}
// Without, it becomes disabled. (macOS 12.0.1)
// Without, it becomes disabled. (macOS 12.4)
.buttonStyle(.automatic)
} label: {
Image(systemName: "clock.fill")
.controlSize(.large)
// .padding(8) // Has no effect. (macOS 12.0.1)
.contentShape(.rectangle)
}
.menuIndicatorHidden()
.menuIndicator(.hidden)
.padding(8)
.fixedSize()
.opacity(0.6) // Try to match the other buttons.
Expand Down Expand Up @@ -117,7 +117,7 @@ private struct BarView: View {
.contentShape(.rectangle)
.fixedSize()
.opacity(0.6) // Try to match the other buttons.
.menuIndicatorHidden()
.menuIndicator(.hidden)
}
}

Expand Down Expand Up @@ -162,7 +162,7 @@ struct ColorPickerScreen: View {
var hexColor = $0

if hexColor.hasPrefix("##") {
hexColor = hexColor.dropFirst().string
hexColor = hexColor.dropFirst().toString
self.hexColor = hexColor
}

Expand All @@ -178,14 +178,11 @@ struct ColorPickerScreen: View {
updateColorsFromPanel(excludeHex: true, preventUpdate: true)
}
}
Button {
Button("Copy Hex", systemImage: "doc.on.doc.fill") {
hexColor.copyToPasteboard()
} label: {
Image(systemName: "doc.on.doc.fill")
// TODO: Enable when targeting macOS 12 and remove `.fill` in the string. Also on the other buttons.
// .symbolVariant(.fill)
// .symbolRenderingMode(.hierarchical)
}
.labelStyle(.iconOnly)
.symbolRenderingMode(.hierarchical)
.buttonStyle(.borderless)
.contentShape(.rectangle)
.keyboardShortcut("h", modifiers: [.shift, .command])
Expand Down Expand Up @@ -214,11 +211,11 @@ struct ColorPickerScreen: View {
updateColorsFromPanel(excludeHSL: true, preventUpdate: true)
}
}
Button {
Button("Copy HSL", systemImage: "doc.on.doc.fill") {
hslColor.copyToPasteboard()
} label: {
Image(systemName: "doc.on.doc.fill")
}
.labelStyle(.iconOnly)
.symbolRenderingMode(.hierarchical)
.buttonStyle(.borderless)
.contentShape(.rectangle)
.keyboardShortcut("s", modifiers: [.shift, .command])
Expand Down Expand Up @@ -247,11 +244,11 @@ struct ColorPickerScreen: View {
updateColorsFromPanel(excludeRGB: true, preventUpdate: true)
}
}
Button {
Button("Copy RGB", systemImage: "doc.on.doc.fill") {
rgbColor.copyToPasteboard()
} label: {
Image(systemName: "doc.on.doc.fill")
}
.labelStyle(.iconOnly)
.symbolRenderingMode(.hierarchical)
.buttonStyle(.borderless)
.contentShape(.rectangle)
.keyboardShortcut("r", modifiers: [.shift, .command])
Expand Down Expand Up @@ -280,11 +277,11 @@ struct ColorPickerScreen: View {
updateColorsFromPanel(excludeLCH: true, preventUpdate: true)
}
}
Button {
Button("Copy LCH", systemImage: "doc.on.doc.fill") {
lchColor.copyToPasteboard()
} label: {
Image(systemName: "doc.on.doc.fill")
}
.labelStyle(.iconOnly)
.symbolRenderingMode(.hierarchical)
.buttonStyle(.borderless)
.contentShape(.rectangle)
.keyboardShortcut("l", modifiers: [.shift, .command])
Expand Down
2 changes: 2 additions & 0 deletions Color Picker/Color_Picker.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
Expand Down
14 changes: 5 additions & 9 deletions Color Picker/Events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ extension AppState {
func setUpEvents() {
Defaults.publisher(.showInMenuBar)
.receive(on: DispatchQueue.main)
.sink { [weak self] in
guard let self = self else {
return
}

.sink { [self] in
// We only set the state if it's in Dock mode or menu bar mode showing the icon.
if !$0.newValue || ($0.newValue && !Defaults[.hideMenuBarIcon]) {
self.statusItem.isVisible = $0.newValue
Expand Down Expand Up @@ -41,12 +37,12 @@ extension AppState {
}
.store(in: &cancellables)

KeyboardShortcuts.onKeyUp(for: .pickColor) { [weak self] in
self?.pickColor()
KeyboardShortcuts.onKeyUp(for: .pickColor) { [self] in
pickColor()
}

KeyboardShortcuts.onKeyUp(for: .toggleWindow) { [weak self] in
self?.colorPanel.toggle()
KeyboardShortcuts.onKeyUp(for: .toggleWindow) { [self] in
colorPanel.toggle()
}

// We use this instead of `applicationShouldHandleReopen` because of the macOS bug.
Expand Down
Loading

0 comments on commit 887b65b

Please sign in to comment.