Skip to content

Commit

Permalink
Merge pull request #29 from perseusrealdeal/v1.1.4
Browse files Browse the repository at this point in the history
V1.1.4
  • Loading branch information
perseusrealdeal committed Apr 4, 2023
2 parents 1db4f3f + acb22a9 commit c168ed4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Package.swift
@@ -1,7 +1,7 @@
// swift-tools-version:4.2

/* Package.swift
Version: 1.1.3
Version: 1.1.4
Created by Mikhail Zhigulin in 7530.
Expand Down
68 changes: 10 additions & 58 deletions PerseusDarkModeSingle.swift
@@ -1,6 +1,6 @@
//
// PerseusDarkModeSingle.swift
// Version: 1.1.3
// Version: 1.1.4
//
// Created by Mikhail Zhigulin in 7530.
//
Expand Down Expand Up @@ -48,32 +48,19 @@ public typealias Responder = UIResponder
public typealias Responder = NSResponder
#endif

/* template
#if canImport(UIKit)
#elseif canImport(Cocoa)
#endif
*/

/* template
#if os(iOS)
#elseif os(macOS)
#endif
*/

// MARK: - Constants
// MARK: - Notifications

public extension Notification.Name {
static let MakeAppearanceUpNotification = Notification.Name("MakeAppearanceUpNotification")
static let MakeAppearanceUpNotification =
Notification.Name("MakeAppearanceUpNotification")
#if os(macOS)
static let AppleInterfaceThemeChangedNotification =
Notification.Name("AppleInterfaceThemeChangedNotification")
#endif
}

// MARK: - Constants

public let DARK_MODE_USER_CHOICE_KEY = "DarkModeUserChoiceOptionKey"
public let DARK_MODE_USER_CHOICE_DEFAULT = DarkModeOption.auto
public let DARK_MODE_STYLE_DEFAULT = AppearanceStyle.light
Expand All @@ -83,7 +70,7 @@ public let OBSERVERED_VARIABLE_NAME = "styleObservable"

// swiftlint:disable identifier_name
public extension Responder {
var DarkMode: DarkModeProtocol { return AppearanceService.shared }
var DarkMode: DarkMode { return AppearanceService.shared }
}
// swiftlint:enable identifier_name

Expand Down Expand Up @@ -117,26 +104,15 @@ public class AppearanceService {

public static var isEnabled: Bool { return hidden_isEnabled }

#if DEBUG && os(macOS)
/// Used for mocking DistributedNotificationCenter in unit testing.
public static var distributedNCenter: NotificationCenterProtocol =
DistributedNotificationCenter.default
#elseif os(macOS)
#if os(macOS)
/// Default Distributed NotificationCenter.
public static var distributedNCenter = DistributedNotificationCenter.default
#endif

#if DEBUG // Isolated for unit testing
/// Used for mocking NotificationCenter in unit testing.
public static var nCenter: NotificationCenterProtocol = NotificationCenter.default
/// Used for mocking UserDefaults in unit testing.
public static var ud: UserDefaultsProtocol = UserDefaults.standard
#else
/// Default NotificationCenter.
public static var nCenter = NotificationCenter.default
/// Default UserDefaults.
public static var ud = UserDefaults.standard
#endif

public static var DarkModeUserChoice: DarkModeOption {
get {
Expand Down Expand Up @@ -264,6 +240,7 @@ public class AppearanceService {
// MARK: - Dark Mode

public class DarkMode: NSObject {

// MARK: - The App's current Appearance Style

public var style: AppearanceStyle { return hidden_style }
Expand Down Expand Up @@ -354,6 +331,7 @@ public class DarkModeDecision {
// MARK: - Appearance Style Observering

public class DarkModeObserver: NSObject {

public var action: ((_ newStyle: AppearanceStyle) -> Void)?
private(set) var objectToObserve = AppearanceService.shared

Expand Down Expand Up @@ -471,29 +449,3 @@ extension UIWindow {
}
}
#endif

// MARK: - Used only for unit testing purpose

public protocol NotificationCenterProtocol {
func addObserver(_ observer: Any,
selector aSelector: Selector,
name aName: NSNotification.Name?,
object anObject: Any?)
func post(name aName: NSNotification.Name, object anObject: Any?)
}

public protocol UserDefaultsProtocol {
func valueExists(forKey key: String) -> Bool
func integer(forKey defaultName: String) -> Int
func setValue(_ value: Any?, forKey key: String)
}

public protocol DarkModeProtocol {
var style: AppearanceStyle { get }
var systemStyle: SystemStyle { get }
var styleObservable: Int { get }
}

extension UserDefaults: UserDefaultsProtocol { }
extension NotificationCenter: NotificationCenterProtocol { }
extension DarkMode: DarkModeProtocol { }
6 changes: 3 additions & 3 deletions README.md
@@ -1,7 +1,7 @@
# Perseus Dark Mode

[![Actions Status](https://github.com/perseusrealdeal/DarkMode/actions/workflows/main.yml/badge.svg)](https://github.com/perseusrealdeal/PerseusDarkMode/actions)
![Version](https://img.shields.io/badge/Version-1.1.3-informational.svg)
![Version](https://img.shields.io/badge/Version-1.1.4-informational.svg)
[![Pod](https://img.shields.io/badge/Pod-1.1.3-informational.svg)](/PerseusDarkMode.podspec)
![Platforms](https://img.shields.io/badge/Platforms-iOS%209.3+,%20macOS%2010.9+-orange.svg)
[![Swift 4.2](https://img.shields.io/badge/Swift-4.2-red.svg)](https://docs.swift.org/swift-book/RevisionHistory/RevisionHistory.html)
Expand Down Expand Up @@ -59,7 +59,7 @@ end
Cartfile should contain:

```carthage
github "perseusrealdeal/PerseusDarkMode" == 1.1.3
github "perseusrealdeal/PerseusDarkMode" == 1.1.4
```

Some Carthage usage tips placed [here](https://gist.github.com/perseusrealdeal/8951b10f4330325df6347aaaa79d3cf2).
Expand All @@ -71,7 +71,7 @@ Some Carthage usage tips placed [here](https://gist.github.com/perseusrealdeal/8
```swift
dependencies: [
.package(url: "https://github.com/perseusrealdeal/PerseusDarkMode.git",
.exact("1.1.3"))
.exact("1.1.4"))
],
```

Expand Down

0 comments on commit c168ed4

Please sign in to comment.