Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 30, 2023
1 parent 2ff6425 commit a4f87df
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 111 deletions.
11 changes: 7 additions & 4 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ only_rules:
- no_extension_access_modifier
- no_fallthrough_only
- no_space_in_method_call
- non_overridable_class_declaration
- notification_center_detachment
- ns_number_init_as_function_reference
- nsobject_prefer_isequal
Expand All @@ -94,6 +95,7 @@ only_rules:
- private_action
- private_outlet
- private_subject
- private_swiftui_state
- private_unit_test
- prohibited_super_call
- protocol_property_accessors_order
Expand All @@ -119,6 +121,7 @@ only_rules:
- static_operator
- strong_iboutlet
- superfluous_disable_command
- superfluous_else
- switch_case_alignment
- switch_case_on_newline
- syntactic_sugar
Expand All @@ -132,6 +135,7 @@ only_rules:
- unavailable_condition
- unavailable_function
- unneeded_break_in_switch
- unneeded_override
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
Expand Down Expand Up @@ -165,7 +169,6 @@ identifier_name:
min_length:
warning: 2
error: 2
validates_start_with_lowercase: false
allowed_symbols:
- '_'
excluded:
Expand All @@ -180,7 +183,7 @@ identifier_name:
- 'y2'
- 'z2'
deployment_target:
macOS_deployment_target: '12'
macOS_deployment_target: '13'
custom_rules:
no_nsrect:
regex: '\bNSRect\b'
Expand All @@ -202,8 +205,8 @@ custom_rules:
regex: '\bCGFloat\('
message: 'Use Double instead of CGFloat'
swiftui_state_private:
regex: '@(State|StateObject|ObservedObject|EnvironmentObject)\s+var'
message: 'SwiftUI @State/@StateObject/@ObservedObject/@EnvironmentObject properties should be private'
regex: '@(ObservedObject|EnvironmentObject)\s+var'
message: 'SwiftUI @ObservedObject/@EnvironmentObject properties should be private'
swiftui_environment_private:
regex: '@Environment\(\\\.\w+\)\s+var'
message: 'SwiftUI @Environment properties should be private'
Expand Down
14 changes: 9 additions & 5 deletions Color Picker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objectVersion = 60;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -235,7 +235,7 @@
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1420;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1500;
TargetAttributes = {
E34BFA932988F3AF002AB421 = {
CreatedOnToolsVersion = 14.2;
Expand All @@ -246,7 +246,7 @@
};
};
buildConfigurationList = E3A3B11425904E7B001B4D0C /* Build configuration list for PBXProject "Color Picker" */;
compatibilityVersion = "Xcode 14.0";
compatibilityVersion = "Xcode 15.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Expand Down Expand Up @@ -409,6 +409,7 @@
baseConfigurationReference = E3E7D7AB27218A50009D71F4 /* Config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
Expand Down Expand Up @@ -443,6 +444,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand All @@ -457,7 +459,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 13.3;
MACOSX_DEPLOYMENT_TARGET = 13.5;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand All @@ -473,6 +475,7 @@
baseConfigurationReference = E3E7D7AB27218A50009D71F4 /* Config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
Expand Down Expand Up @@ -507,6 +510,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -515,7 +519,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 13.3;
MACOSX_DEPLOYMENT_TARGET = 13.5;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
5 changes: 3 additions & 2 deletions Color Picker/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ struct AppMain: App {
Link("FAQ", destination: "https://github.com/sindresorhus/System-Color-Picker#faq")
Link("Website", destination: "https://sindresorhus.com/system-color-picker")
Divider()
Link("Rate on the App Store", destination: "macappstore://apps.apple.com/app/id1545870783?action=write-review")
Link("Rate App", destination: "macappstore://apps.apple.com/app/id1545870783?action=write-review")
// TODO: Doesn't work. (macOS 14.0)
// ShareLink("Share App", item: "https://apps.apple.com/app/id1545870783")
Link("More Apps by Me", destination: "macappstore://apps.apple.com/developer/id328077650")
Divider()
Button("Send Feedback…") {
Expand All @@ -84,7 +86,6 @@ struct AppMain: App {
}
}

@MainActor
private final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
SSApp.swiftUIMainWindow?.close()
Expand Down
7 changes: 1 addition & 6 deletions Color Picker/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ final class AppState: ObservableObject {
// We cannot enable tiling as then it doesn't show up in fullscreen spaces. (macOS 12.5)
// .fullScreenAllowsTiling
]
colorPanel.center()
colorPanel.makeMain()

let view = ColorPickerScreen(colorPanel: colorPanel)
Expand Down Expand Up @@ -77,12 +78,6 @@ final class AppState: ObservableObject {

menu.addSeparator()

menu.addCallbackItem("Send Feedback…") {
SSApp.openSendFeedbackPage()
}

menu.addSeparator()

menu.addQuitItem()

return menu
Expand Down
6 changes: 2 additions & 4 deletions Color Picker/ColorPickerScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,8 @@ struct ColorPickerScreen: View {
}
}

struct ColorPickerScreen_Previews: PreviewProvider {
static var previews: some View {
ColorPickerScreen(colorPanel: .shared)
}
#Preview {
ColorPickerScreen(colorPanel: .shared)
}

private struct BarView: View {
Expand Down
18 changes: 9 additions & 9 deletions Color Picker/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ enum ColorFormat: String, CaseIterable, Defaults.Serializable {
var title: String {
switch self {
case .hex:
return "Hex"
"Hex"
case .hsl:
return "HSL"
"HSL"
case .rgb:
return "RGB"
"RGB"
case .lch:
return "LCH"
"LCH"
}
}
}
Expand All @@ -57,20 +57,20 @@ enum MenuBarItemClickAction: String, CaseIterable, Defaults.Serializable {
var title: String {
switch self {
case .showMenu:
return "Show menu"
"Show menu"
case .showColorSampler:
return "Show color sampler"
"Show color sampler"
case .toggleWindow:
return "Toggle window"
"Toggle window"
}
}

var tip: String {
switch self {
case .showMenu:
return "Right-click to show the color sampler"
"Right-click to show the color sampler"
case .showColorSampler, .toggleWindow:
return "Right-click to show the menu"
"Right-click to show the menu"
}
}
}
22 changes: 13 additions & 9 deletions Color Picker/Events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ extension AppState {
Defaults.publisher(.stayOnTop)
.receive(on: DispatchQueue.main)
.sink { [weak self] in
self?.colorPanel.level = $0.newValue ? .floating : .normal
// We use `.utility` instead of `.floating` to ensure it's always above other windows.
// For example, the Simulator uses `.modalPane` level when "stay on top" is enabled.
self?.colorPanel.level = $0.newValue ? .utility : .normal
}
.store(in: &cancellables)

Expand All @@ -44,15 +46,17 @@ extension AppState {
colorPanel.toggle()
}

// Workaround for the color picker window not becoming active after the settings window closes. (macOS 11.3)
NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)
.sink { [self] _ in
DispatchQueue.main.async { [self] in
if colorPanel.isVisible, SSApp.settingsWindow?.isVisible != true {
colorPanel.makeKeyAndOrderFront(nil)
if #unavailable(macOS 14) {
// Workaround for the color picker window not becoming active after the settings window closes. (macOS 11.3)
NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)
.sink { [self] _ in
DispatchQueue.main.async { [self] in
if colorPanel.isVisible, SSApp.settingsWindow?.isVisible != true {
colorPanel.makeKeyAndOrderFront(nil)
}
}
}
}
.store(in: &cancellables)
.store(in: &cancellables)
}
}
}
10 changes: 4 additions & 6 deletions Color Picker/SettingsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct SettingsScreen: View {
.frame(width: 460)
.frame(maxHeight: 480)
.fixedSize()
.windowLevel(.floating + 1) // Ensure it's always above the color picker.
.windowLevel(.utility + 1) // Ensure it's always above the color picker.
}
}

Expand Down Expand Up @@ -144,7 +144,7 @@ private struct PreferredColorFormatSetting: View {
private struct ShownColorFormatsSetting: View {
var body: some View {
LabeledContent("Shown color formats") {
Defaults.MultiCheckboxPicker(
Defaults.MultiTogglePicker(
key: .shownColorFormats,
data: ColorFormat.allCases
) {
Expand All @@ -155,8 +155,6 @@ private struct ShownColorFormatsSetting: View {
}
}

struct SettingsScreen_Previews: PreviewProvider {
static var previews: some View {
SettingsScreen()
}
#Preview {
SettingsScreen()
}
Loading

0 comments on commit a4f87df

Please sign in to comment.