Skip to content

Commit 2ef2f13

Browse files
Merge pull request #30 from perseusrealdeal/1.1.5
Release 1.1.5
2 parents c168ed4 + 332e9cd commit 2ef2f13

6 files changed

Lines changed: 169 additions & 40 deletions

File tree

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// swift-tools-version:4.2
22

33
/* Package.swift
4-
Version: 1.1.4
4+
Version: 1.1.5
55

66
Created by Mikhail Zhigulin in 7530.
77

PerseusDarkMode.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Pod::Spec.new do |p|
22

33
p.name = "PerseusDarkMode"
4-
p.version = "1.1.3"
5-
p.summary = "It gives an accessible variable of Dark Mode."
4+
p.version = "1.1.4"
5+
p.summary = "Variable for changing Dark Mode."
66
p.description = "Designed for constructing Dark Mode sensitive features."
77
p.homepage = "https://github.com/perseusrealdeal/PerseusDarkMode"
88

PerseusDarkModeSingle.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// PerseusDarkModeSingle.swift
3-
// Version: 1.1.4
3+
// Version: 1.1.5
44
//
55
// Created by Mikhail Zhigulin in 7530.
66
//
@@ -196,7 +196,7 @@ public class AppearanceService {
196196
nCenter.post(name: .MakeAppearanceUpNotification, object: nil)
197197
}
198198

199-
internal static func recalculateStyleIfNeeded() {
199+
public static func recalculateStyleIfNeeded() {
200200
let actualStyle = DarkModeDecision.calculate(DarkModeUserChoice, shared.systemStyle)
201201

202202
if shared.hidden_style != actualStyle { shared.hidden_style = actualStyle }

README.md

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Perseus Dark Mode
22

33
[![Actions Status](https://github.com/perseusrealdeal/DarkMode/actions/workflows/main.yml/badge.svg)](https://github.com/perseusrealdeal/PerseusDarkMode/actions)
4-
![Version](https://img.shields.io/badge/Version-1.1.4-informational.svg)
5-
[![Pod](https://img.shields.io/badge/Pod-1.1.3-informational.svg)](/PerseusDarkMode.podspec)
4+
![Version](https://img.shields.io/badge/Version-1.1.5-informational.svg)
5+
[![Pod](https://img.shields.io/badge/Pod-1.1.4-informational.svg)](/PerseusDarkMode.podspec)
66
![Platforms](https://img.shields.io/badge/Platforms-iOS%209.3+,%20macOS%2010.9+-orange.svg)
77
[![Swift 4.2](https://img.shields.io/badge/Swift-4.2-red.svg)](https://docs.swift.org/swift-book/RevisionHistory/RevisionHistory.html)
88
[![License](http://img.shields.io/:License-MIT-blue.svg)](/LICENSE)
99

1010
## Integration Capabilities
1111

12-
[![Standalone File](https://img.shields.io/badge/Standalone%20File-available-informational.svg)](/PerseusDarkModeSingle.swift)
12+
[![Standalone](https://img.shields.io/badge/Standalone-available-informational.svg)](/PerseusDarkModeSingle.swift)
1313
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg)](https://github.com/Carthage/Carthage)
14-
[![CocoaPods manager](https://img.shields.io/badge/CocoaPods-compatible-4BC51D.svg)](https://cocoapods.org)
15-
[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-4BC51D.svg)](https://github.com/apple/swift-package-manager)
14+
[![CocoaPods manager](https://img.shields.io/badge/CocoaPods-compatible-4BC51D.svg)](/PerseusDarkMode.podspec)
15+
[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-4BC51D.svg)](/Package.swift)
1616

1717
## Demo Apps and Others
1818

@@ -23,67 +23,80 @@
2323

2424
# In Brief
2525

26-
> This library lets a developer being awared of Dark Mode via a variable `DarkMode.style`. Also, with this library it is possible to change the value of Dark Mode in runtime easily.
26+
> This library lets a developer being awared of Dark Mode via a variable `DarkMode.style`. Also, with this library it is possible to change the value of Dark Mode in runtime easily with standalone lib [DarkModeSwitching](https://gist.github.com/perseusrealdeal/11b1bab47f13134832b859f49d9af706).
2727
28-
## Reqirements
28+
```swift
29+
changeDarkModeManually(.off) // .on or .auto
30+
```
31+
Sample screen for changing Dark Mode option [here for macOS](https://github.com/perseusrealdeal/macos.darkmode.discovery) and [here for iOS](https://github.com/perseusrealdeal/ios.darkmode.discovery).
32+
33+
# Reqirements
2934

3035
- Xcode 10.1+
3136
- Swift 4.2+
3237
- iOS: 9.3+, UIKit SDK
3338
- macOS: 10.9+, AppKit SDK
3439

35-
## Third-party software
40+
# First-party software
41+
42+
- [PerseusLogger](https://gist.github.com/perseusrealdeal/df456a9825fcface44eca738056eb6d5)
43+
44+
# Third-party software
3645

3746
- [SwiftLint Shell Script Runner](/SucceedsPostAction.sh)
47+
- [SwiftLint](https://github.com/realm/SwiftLint) / [0.31.0: Busy Laundromat](https://github.com/realm/SwiftLint/releases/tag/0.31.0) for macOS High Sierra
48+
49+
# Installation
3850

39-
## Installation
51+
> ***Using "Exact" with the Version field is strongly recommended.***
4052
41-
### Step 1: Add PerseusDarkMode to a host project tree
53+
## Step 1: Add PerseusDarkMode to a host project tree
4254

43-
#### Standalone
55+
### Standalone
4456

4557
Make a copy of the file [`PerseusDarkModeSingle.swift`](/PerseusDarkModeSingle.swift) then put it into a place required of a host project.
4658

47-
#### CocoaPods
59+
### Carthage
60+
61+
Cartfile should contain:
62+
63+
```carthage
64+
github "perseusrealdeal/PerseusDarkMode" == 1.1.5
65+
```
66+
67+
Some Carthage usage tips placed [here](https://gist.github.com/perseusrealdeal/8951b10f4330325df6347aaaa79d3cf2).
68+
69+
### CocoaPods
4870

4971
Podfile should contain:
5072

5173
```ruby
5274
target "ProjectTarget" do
5375
use_frameworks!
54-
pod 'PerseusDarkMode', '1.1.3'
76+
pod 'PerseusDarkMode', '1.1.4'
5577
end
5678
```
57-
#### Carthage
5879

59-
Cartfile should contain:
60-
61-
```carthage
62-
github "perseusrealdeal/PerseusDarkMode" == 1.1.4
63-
```
64-
65-
Some Carthage usage tips placed [here](https://gist.github.com/perseusrealdeal/8951b10f4330325df6347aaaa79d3cf2).
66-
67-
#### Swift Package Manager
80+
### Swift Package Manager
6881

6982
- As a package dependency so Package.swift should contain the following statements:
7083

7184
```swift
7285
dependencies: [
7386
.package(url: "https://github.com/perseusrealdeal/PerseusDarkMode.git",
74-
.exact("1.1.4"))
87+
.exact("1.1.5"))
7588
],
7689
```
7790

7891
- As an Xcode project dependency:
7992

8093
`Project in the Navigator > Package Dependencies > Add Package Dependency`
8194

82-
Using "Exact" with the Version field is strongly recommended.
95+
> ***Using "Exact" with the Version field is strongly recommended.***
8396
84-
### Step 2: Make DarkMode ready for using
97+
## Step 2: Make DarkMode ready for using
8598

86-
#### iOS
99+
### iOS
87100

88101
Override the following method of the first screen to let Perseus know that system's appearance changed:
89102

@@ -118,7 +131,7 @@ extension AppDelegate: UIApplicationDelegate {
118131
```
119132
Used functions are distributed via standalone file [`DarkModeSwitching.swift`](https://gist.github.com/perseusrealdeal/11b1bab47f13134832b859f49d9af706).
120133

121-
#### iOS and macOS
134+
### iOS and macOS
122135

123136
Call the method `AppearanceService.makeUp()` with the app's delegate if appearance changing is going to take place:
124137

@@ -142,7 +155,7 @@ extension AppDelegate: UIApplicationDelegate {
142155
```
143156
Copy the file [`DarkModeSwitching.swift`](https://gist.github.com/perseusrealdeal/11b1bab47f13134832b859f49d9af706) into a host project for having fun with manual changing Dark Mode value.
144157

145-
## Usage
158+
# Usage
146159

147160
Each time if Dark Mode changed the mentioned method `#selector(makeUp)` called, but registering is required:
148161
```swift
@@ -171,19 +184,21 @@ class MainViewController: UIViewController {
171184
}
172185
```
173186

174-
There is another way to be notified of Dark Mode—KVO. To learn have a look at [sample](https://github.com/perseusrealdeal/macos.darkmode.discovery) directly.
187+
There is another way to be notified of Dark Mode—KVO.
188+
189+
> [`DarkModeImageView`](https://github.com/perseusrealdeal/PerseusUISystemKit/blob/master/Sources/PerseusUISystemKit/Classes/DarkModeImageView.swift) class is an expressive sample of Dark Mode KVO usage for both macOS and iOS as well.
175190

176-
## License MIT
191+
# License MIT
177192

178193
Copyright © 7530 - 7531 Mikhail Zhigulin of Novosibirsk.
179194

180195
- The year starts from the creation of the world according to a Slavic calendar.
181196
- September, the 1st of Slavic year.
182197

183-
Have a look at [LICENSE](/LICENSE) for details.
198+
[LICENSE](/LICENSE) for details.
184199

185-
## Author and Acknowledgments
200+
# Author
186201

187-
`PerseusDarkMode` was written at Novosibirsk by Mikhail Zhigulin i.e. me, mzhigulin@gmail.com.
202+
> `PerseusDarkMode` was written at Novosibirsk by Mikhail Zhigulin i.e. me, mzhigulin@gmail.com.
188203

189204
> Mostly I'd like thank my lovely parents for supporting me in all my ways.

Sources/PerseusDarkMode/AppearanceService/AppearanceService.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class AppearanceService {
5454

5555
private(set) static var it = { AppearanceService() }()
5656
private init() {
57+
log.message("[\(type(of: self))].\(#function)")
5758
#if os(macOS)
5859
AppearanceService.distributedNCenter.addObserver(
5960
self,
@@ -206,7 +207,7 @@ public class AppearanceService {
206207
}
207208

208209
/// Updates the app's appearance style value.
209-
internal static func recalculateStyleIfNeeded() {
210+
public static func recalculateStyleIfNeeded() {
210211
let actualStyle = DarkModeDecision.calculate(DarkModeUserChoice, shared.systemStyle)
211212

212213
if shared.hidden_style != actualStyle { shared.hidden_style = actualStyle }
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//
2+
// PerseusLogger.swift
3+
// PerseusRealDeal
4+
//
5+
// Created by Mikhail Zhigulin in 7531.
6+
//
7+
// Copyright © 7531 Mikhail Zhigulin of Novosibirsk.
8+
// Copyright © 7531 PerseusRealDeal.
9+
// All rights reserved.
10+
//
11+
//
12+
// MIT License
13+
//
14+
// Copyright © 7531 Mikhail Zhigulin of Novosibirsk
15+
// Copyright © 7531 PerseusRealDeal
16+
//
17+
// The year starts from the creation of the world according to a Slavic calendar.
18+
// September, the 1st of Slavic year.
19+
//
20+
// Permission is hereby granted, free of charge, to any person obtaining a copy
21+
// of this software and associated documentation files (the "Software"), to deal
22+
// in the Software without restriction, including without limitation the rights
23+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24+
// copies of the Software, and to permit persons to whom the Software is
25+
// furnished to do so, subject to the following conditions:
26+
//
27+
// The above copyright notices and this permission notice shall be included in all
28+
// copies or substantial portions of the Software.
29+
//
30+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
// SOFTWARE.
37+
//
38+
39+
// DESC: USE LOGGER LIKE A VARIABLE ANYWHERE YOU WANT
40+
//
41+
// By default logger is turned on in DEBUG, but it's off in RELEASE.
42+
//
43+
// log.message("[\(type(of: self))].\(#function)")
44+
//
45+
46+
/* To disable debug messaging of the module use the following statements in the start point.
47+
48+
import class OpenWeatherFreeClient.PerseusLogger
49+
typealias FreeClientLogger = OpenWeatherFreeClient.PerseusLogger
50+
51+
FreeClientLogger.turned = .off
52+
53+
*/
54+
55+
import Foundation
56+
57+
// swiftlint:disable type_name
58+
typealias log = PerseusLogger
59+
// swiftlint:enable type_name
60+
61+
public class PerseusLogger {
62+
63+
public enum Status {
64+
case on
65+
case off
66+
}
67+
68+
public enum Level: Int, CustomStringConvertible {
69+
70+
public var description: String {
71+
switch self {
72+
case .info:
73+
return "INFO"
74+
case .debug:
75+
return "DEBUG"
76+
case .error:
77+
return "ERROR"
78+
}
79+
}
80+
81+
case info = 3
82+
case debug = 2 // Default.
83+
case error = 1
84+
}
85+
86+
#if DEBUG
87+
public static var turned = Status.on
88+
#else
89+
public static var turned = Status.off
90+
#endif
91+
92+
public static var level = Level.debug
93+
public static var short = true
94+
95+
public static func message(_ text: @autoclosure () -> String,
96+
_ type: Level = .debug,
97+
_ file: StaticString = #file,
98+
_ line: UInt = #line) {
99+
100+
guard turned == .on, type.rawValue <= level.rawValue else { return }
101+
102+
var message = ""
103+
104+
if short {
105+
message = "\(type): \(text())"
106+
} else {
107+
let fileName = (file.description as NSString).lastPathComponent
108+
message = "\(type): \(text()), file: \(fileName), line: \(line)"
109+
}
110+
111+
print(message) // DispatchQueue.main.async { print(message) }
112+
}
113+
}

0 commit comments

Comments
 (0)