Skip to content

Commit

Permalink
Target macOS 10.15
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 20, 2024
1 parent 3b11952 commit 04b8db6
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let package = Package(
name: "KeyboardShortcuts",
defaultLocalization: "en",
platforms: [
.macOS(.v10_13)
.macOS(.v10_15)
],
products: [
.library(
Expand Down
4 changes: 0 additions & 4 deletions Sources/KeyboardShortcuts/KeyboardShortcuts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ public enum KeyboardShortcuts {
}

extension KeyboardShortcuts {
@available(macOS 10.15, *)
public enum EventType: Sendable {
case keyDown
case keyUp
Expand Down Expand Up @@ -492,7 +491,6 @@ extension KeyboardShortcuts {

- Note: This method is not affected by `.removeAllHandlers()`.
*/
@available(macOS 10.15, *)
public static func events(for name: Name) -> AsyncStream<KeyboardShortcuts.EventType> {
AsyncStream { continuation in
let id = UUID()
Expand Down Expand Up @@ -549,12 +547,10 @@ extension KeyboardShortcuts {

- Note: This method is not affected by `.removeAllHandlers()`.
*/
@available(macOS 10.15, *)
public static func events(_ type: EventType, for name: Name) -> AsyncFilterSequence<AsyncStream<EventType>> {
events(for: name).filter { $0 == type }
}

@available(macOS 10.15, *)
@available(*, deprecated, renamed: "events(_:for:)")
public static func on(_ type: EventType, for name: Name) -> AsyncStream<Void> {
AsyncStream { continuation in
Expand Down
9 changes: 1 addition & 8 deletions Sources/KeyboardShortcuts/Recorder.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if os(macOS)
import SwiftUI

@available(macOS 10.15, *)
extension KeyboardShortcuts {
private struct _Recorder: NSViewRepresentable { // swiftlint:disable:this type_name
typealias NSViewType = RecorderCocoa
Expand Down Expand Up @@ -88,7 +87,6 @@ extension KeyboardShortcuts {
}
}

@available(macOS 10.15, *)
extension KeyboardShortcuts.Recorder<EmptyView> {
/**
- Parameter name: Strongly-typed keyboard shortcut name.
Expand All @@ -106,7 +104,6 @@ extension KeyboardShortcuts.Recorder<EmptyView> {
}
}

@available(macOS 10.15, *)
extension KeyboardShortcuts.Recorder<Text> {
/**
- Parameter title: The title of the keyboard shortcut recorder, describing its purpose.
Expand All @@ -128,7 +125,6 @@ extension KeyboardShortcuts.Recorder<Text> {
}
}

@available(macOS 10.15, *)
extension KeyboardShortcuts.Recorder<Text> {
/**
- Parameter title: The title of the keyboard shortcut recorder, describing its purpose.
Expand All @@ -151,7 +147,6 @@ extension KeyboardShortcuts.Recorder<Text> {
}
}

@available(macOS 10.15, *)
extension KeyboardShortcuts.Recorder {
/**
- Parameter name: Strongly-typed keyboard shortcut name.
Expand All @@ -172,18 +167,16 @@ extension KeyboardShortcuts.Recorder {
}
}

@available(macOS 10.15, *)
#Preview {
KeyboardShortcuts.Recorder("record_shortcut", name: .init("xcodePreview"))
.environment(\.locale, .init(identifier: "en"))
}

@available(macOS 10.15, *)
#Preview {
KeyboardShortcuts.Recorder("record_shortcut", name: .init("xcodePreview"))
.environment(\.locale, .init(identifier: "zh-Hans"))
}
@available(macOS 10.15, *)

#Preview {
KeyboardShortcuts.Recorder("record_shortcut", name: .init("xcodePreview"))
.environment(\.locale, .init(identifier: "ru"))
Expand Down
2 changes: 0 additions & 2 deletions Sources/KeyboardShortcuts/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ final class ObjectAssociation<T> {
}


@available(macOS 10.15, *)
extension HorizontalAlignment {
private enum ControlAlignment: AlignmentID {
static func defaultValue(in context: ViewDimensions) -> CGFloat { // swiftlint:disable:this no_cgfloat
Expand All @@ -440,7 +439,6 @@ extension HorizontalAlignment {
fileprivate static let controlAlignment = Self(ControlAlignment.self)
}

@available(macOS 10.15, *)
extension View {
func formLabel(@ViewBuilder _ label: () -> some View) -> some View {
HStack(alignment: .firstTextBaseline) {
Expand Down
11 changes: 9 additions & 2 deletions Sources/KeyboardShortcuts/ViewModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ extension View {
- Note: This method is not affected by `.removeAllHandlers()`.
*/
@MainActor
public func onKeyboardShortcut(_ shortcut: KeyboardShortcuts.Name, perform: @escaping (KeyboardShortcuts.EventType) -> Void) -> some View {
public func onKeyboardShortcut(
_ shortcut: KeyboardShortcuts.Name,
perform: @escaping (KeyboardShortcuts.EventType) -> Void
) -> some View {
task {
for await eventType in KeyboardShortcuts.events(for: shortcut) {
perform(eventType)
Expand All @@ -31,7 +34,11 @@ extension View {
- Note: This method is not affected by `.removeAllHandlers()`.
*/
@MainActor
public func onKeyboardShortcut(_ shortcut: KeyboardShortcuts.Name, type: KeyboardShortcuts.EventType, perform: @escaping () -> Void) -> some View {
public func onKeyboardShortcut(
_ shortcut: KeyboardShortcuts.Name,
type: KeyboardShortcuts.EventType,
perform: @escaping () -> Void
) -> some View {
task {
for await _ in KeyboardShortcuts.events(type, for: shortcut) {
perform()
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ I'm happy to accept more configurability and features. PR welcome! What you see

## Requirements

macOS 10.13+
macOS 10.15+

## Install

Expand Down

0 comments on commit 04b8db6

Please sign in to comment.