Skip to content

Commit

Permalink
Allow test/mocking of extension methods
Browse files Browse the repository at this point in the history
To facilitate tests/mocking, magnet should not use the `final` modifier.
This PR only removes the `final` keyword, and nothing else.
  • Loading branch information
jasonm23 committed Oct 6, 2023
1 parent 3a683b6 commit 9869344
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Lib/Magnet/HotKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import Cocoa
import Carbon

public final class HotKey: NSObject {
open class HotKey: NSObject {

// MARK: - Properties
public let identifier: String
Expand Down Expand Up @@ -65,7 +65,7 @@ public final class HotKey: NSObject {
}

// MARK: - Invoke
public extension HotKey {
open extension HotKey {
func invoke() {
guard let callback = self.callback else {
guard let target = self.target as? NSObject, let selector = self.action else { return }
Expand All @@ -84,7 +84,7 @@ public extension HotKey {
}

// MARK: - Register & UnRegister
public extension HotKey {
open extension HotKey {
@discardableResult
func register() -> Bool {
return HotKeyCenter.shared.register(with: self)
Expand All @@ -96,7 +96,7 @@ public extension HotKey {
}

// MARK: - override isEqual
public extension HotKey {
open extension HotKey {
override func isEqual(_ object: Any?) -> Bool {
guard let hotKey = object as? HotKey else { return false }

Expand Down
10 changes: 5 additions & 5 deletions Lib/Magnet/HotKeyCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import Cocoa
import Carbon

public final class HotKeyCenter {
open class HotKeyCenter {

// MARK: - Properties
public static let shared = HotKeyCenter()
Expand All @@ -37,7 +37,7 @@ public final class HotKeyCenter {
}

// MARK: - Register & Unregister
public extension HotKeyCenter {
open extension HotKeyCenter {
@discardableResult
func register(with hotKey: HotKey) -> Bool {
guard !hotKeys.keys.contains(hotKey.identifier) else { return false }
Expand Down Expand Up @@ -100,7 +100,7 @@ public extension HotKeyCenter {
}

// MARK: - Terminate
extension HotKeyCenter {
open extension HotKeyCenter {
private func observeApplicationTerminate() {
notificationCenter.addObserver(self,
selector: #selector(HotKeyCenter.applicationWillTerminate),
Expand All @@ -114,7 +114,7 @@ extension HotKeyCenter {
}

// MARK: - HotKey Events
private extension HotKeyCenter {
open extension HotKeyCenter {
func installHotKeyPressedEventHandler() {
var pressedEventType = EventTypeSpec()
pressedEventType.eventClass = OSType(kEventClassKeyboard)
Expand Down Expand Up @@ -151,7 +151,7 @@ private extension HotKeyCenter {
}

// MARK: - Double Tap Modifier Event
private extension HotKeyCenter {
open extension HotKeyCenter {
func installModifiersChangedEventHandlerIfNeeded() {
NSEvent.addGlobalMonitorForEvents(matching: .flagsChanged) { [weak self] event in
self?.modifierEventHandler.handleModifiersEvent(with: event.modifierFlags, timestamp: event.timestamp)
Expand Down
4 changes: 2 additions & 2 deletions Lib/Magnet/KeyCombo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Cocoa
import Carbon
import Sauce

public final class KeyCombo: NSObject, NSCopying, NSCoding, Codable {
open class KeyCombo: NSObject, NSCopying, NSCoding, Codable {

// MARK: - Properties
public let key: Key
Expand Down Expand Up @@ -175,6 +175,6 @@ public final class KeyCombo: NSObject, NSCopying, NSCoding, Codable {
}

// MARK: - Error
public extension KeyCombo {
open extension KeyCombo {
struct InitializeError: Error {}
}
4 changes: 2 additions & 2 deletions Lib/Magnet/ModifierEventHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import Cocoa

public final class ModifierEventHandler {
open class ModifierEventHandler {

// MARK: - Properties
public var doubleTapped: ((NSEvent.ModifierFlags) -> Void)?
Expand All @@ -30,7 +30,7 @@ public final class ModifierEventHandler {
}

// MARK: - Handling
public extension ModifierEventHandler {
open extension ModifierEventHandler {
func handleModifiersEvent(with modifierFlags: NSEvent.ModifierFlags, timestamp: TimeInterval) {
guard lastHandledEventTimestamp != timestamp else { return }
lastHandledEventTimestamp = timestamp
Expand Down

0 comments on commit 9869344

Please sign in to comment.