Skip to content

Commit

Permalink
Make access open for mocking/subclassing (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonm23 authored Oct 10, 2023
1 parent 90639ed commit 4fa210c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Lib/Sauce/InputSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import Foundation
import Carbon

public final class InputSource {
open class InputSource {

// MARK: - Properties
public let id: String
Expand Down
6 changes: 3 additions & 3 deletions Lib/Sauce/ModifierTransformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import Foundation
import Carbon
import AppKit

final class ModifierTransformer {}
open class ModifierTransformer {}

// MARK: - Cocoa & Carbon
extension ModifierTransformer {
func carbonFlags(from cocoaFlags: NSEvent.ModifierFlags) -> Int {
public func carbonFlags(from cocoaFlags: NSEvent.ModifierFlags) -> Int {
var carbonFlags: Int = 0
if cocoaFlags.contains(.command) {
carbonFlags |= cmdKey
Expand All @@ -33,7 +33,7 @@ extension ModifierTransformer {
return carbonFlags
}

func convertCharactorSupportCarbonModifiers(from carbonModifiers: Int) -> Int {
public func convertCharactorSupportCarbonModifiers(from carbonModifiers: Int) -> Int {
var convertedCarbonModifiers: Int = 0
if (carbonModifiers & optionKey) != 0 {
convertedCarbonModifiers |= optionKey
Expand Down
46 changes: 23 additions & 23 deletions Lib/Sauce/Sauce.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import Foundation
import AppKit

public extension NSNotification.Name {
extension NSNotification.Name {
static let SauceSelectedKeyboardInputSourceChanged = Notification.Name("SauceSelectedKeyboardInputSourceChanged")
static let SauceEnabledKeyboardInputSourcesChanged = Notification.Name("SauceEnabledKeyboardInputSourcesChanged")
static let SauceSelectedKeyboardKeyCodesChanged = Notification.Name("SauceSelectedKeyboardKeyCodesChanged")
}

public final class Sauce {
open class Sauce {

// MARK: - Properties
public static let shared = Sauce()
Expand All @@ -34,81 +34,81 @@ public final class Sauce {
}

// MARK: - Input Sources
public extension Sauce {
func currentInputSources() -> [InputSource] {
extension Sauce {
public func currentInputSources() -> [InputSource] {
return layout.inputSources
}
}

// MARK: - KeyCodes
public extension Sauce {
func keyCode(for key: Key) -> CGKeyCode {
extension Sauce {
public func keyCode(for key: Key) -> CGKeyCode {
return currentKeyCode(for: key) ?? key.QWERTYKeyCode
}

func currentKeyCode(for key: Key) -> CGKeyCode? {
public func currentKeyCode(for key: Key) -> CGKeyCode? {
return layout.currentKeyCode(for: key)
}

func currentKeyCodes() -> [Key: CGKeyCode]? {
public func currentKeyCodes() -> [Key: CGKeyCode]? {
return layout.currentKeyCodes()
}

func keyCode(with source: InputSource, key: Key) -> CGKeyCode? {
public func keyCode(with source: InputSource, key: Key) -> CGKeyCode? {
return layout.keyCode(with: source, key: key)
}

func keyCodes(with source: InputSource) -> [Key: CGKeyCode]? {
public func keyCodes(with source: InputSource) -> [Key: CGKeyCode]? {
return layout.keyCodes(with: source)
}
}

// MARK: - Key
public extension Sauce {
func key(for keyCode: Int) -> Key? {
extension Sauce {
public func key(for keyCode: Int) -> Key? {
return currentKey(for: keyCode) ?? Key(QWERTYKeyCode: keyCode)
}

func currentKey(for keyCode: Int) -> Key? {
public func currentKey(for keyCode: Int) -> Key? {
return layout.currentKey(for: keyCode)
}

func key(with source: InputSource, keyCode: Int) -> Key? {
public func key(with source: InputSource, keyCode: Int) -> Key? {
return layout.key(with: source, keyCode: keyCode)
}
}

// MARK: - Characters
public extension Sauce {
func character(for keyCode: Int, carbonModifiers: Int) -> String? {
extension Sauce {
public func character(for keyCode: Int, carbonModifiers: Int) -> String? {
return currentCharacter(for: keyCode, carbonModifiers: carbonModifiers) ?? currentASCIICapableCharacter(for: keyCode, carbonModifiers: carbonModifiers)
}

func character(for keyCode: Int, cocoaModifiers: NSEvent.ModifierFlags) -> String? {
public func character(for keyCode: Int, cocoaModifiers: NSEvent.ModifierFlags) -> String? {
return character(for: keyCode, carbonModifiers: modifierTransformar.carbonFlags(from: cocoaModifiers))
}

func currentCharacter(for keyCode: Int, carbonModifiers: Int) -> String? {
public func currentCharacter(for keyCode: Int, carbonModifiers: Int) -> String? {
return layout.currentCharacter(for: keyCode, carbonModifiers: carbonModifiers)
}

func currentCharacter(for keyCode: Int, cocoaModifiers: NSEvent.ModifierFlags) -> String? {
public func currentCharacter(for keyCode: Int, cocoaModifiers: NSEvent.ModifierFlags) -> String? {
return currentCharacter(for: keyCode, carbonModifiers: modifierTransformar.carbonFlags(from: cocoaModifiers))
}

func currentASCIICapableCharacter(for keyCode: Int, carbonModifiers: Int) -> String? {
public func currentASCIICapableCharacter(for keyCode: Int, carbonModifiers: Int) -> String? {
return layout.currentASCIICapableCharacter(for: keyCode, carbonModifiers: carbonModifiers)
}

func currentASCIICapableCharacter(for keyCode: Int, cocoaModifiers: NSEvent.ModifierFlags) -> String? {
public func currentASCIICapableCharacter(for keyCode: Int, cocoaModifiers: NSEvent.ModifierFlags) -> String? {
return currentASCIICapableCharacter(for: keyCode, carbonModifiers: modifierTransformar.carbonFlags(from: cocoaModifiers))
}

func character(with source: InputSource, keyCode: Int, carbonModifiers: Int) -> String? {
public func character(with source: InputSource, keyCode: Int, carbonModifiers: Int) -> String? {
return layout.character(with: source, keyCode: keyCode, carbonModifiers: carbonModifiers)
}

func character(with source: InputSource, keyCode: Int, cocoaModifiers: NSEvent.ModifierFlags) -> String? {
public func character(with source: InputSource, keyCode: Int, cocoaModifiers: NSEvent.ModifierFlags) -> String? {
return character(with: source, keyCode: keyCode, carbonModifiers: modifierTransformar.carbonFlags(from: cocoaModifiers))
}
}

0 comments on commit 4fa210c

Please sign in to comment.