Skip to content

Commit

Permalink
Merge pull request #8 from perseusrealdeal/v1.1
Browse files Browse the repository at this point in the history
V1.1
  • Loading branch information
perseusrealdeal committed Apr 4, 2023
2 parents ff885d6 + 5c42139 commit 9e434e6
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 67 deletions.
12 changes: 8 additions & 4 deletions DarkModeDiscovery/DarkModeDiscovery.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
4B3A67E329658C0A0024077F /* CompanionListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B3A67E129658C0A0024077F /* CompanionListViewController.swift */; };
4B3A67E72965932D0024077F /* CompanionCollectionViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B3A67E52965932D0024077F /* CompanionCollectionViewItem.swift */; };
4B3A67E82965932D0024077F /* CompanionCollectionViewItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B3A67E62965932D0024077F /* CompanionCollectionViewItem.xib */; };
4B41CA3E29DC638300FF98BB /* PerseusLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B41CA3D29DC638300FF98BB /* PerseusLogger.swift */; };
4B44EDFB294661E80084C192 /* main.yml in Resources */ = {isa = PBXBuildFile; fileRef = 4B44EDFA294661E80084C192 /* main.yml */; };
4B44EE0129466A320084C192 /* DarkModeSwitching.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B44EDFE29466A320084C192 /* DarkModeSwitching.swift */; };
4B44EE0329466A320084C192 /* PerseusUISystemKitSingle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B44EE0029466A320084C192 /* PerseusUISystemKitSingle.swift */; };
Expand Down Expand Up @@ -57,6 +58,7 @@
4B3A67E129658C0A0024077F /* CompanionListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanionListViewController.swift; sourceTree = "<group>"; };
4B3A67E52965932D0024077F /* CompanionCollectionViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanionCollectionViewItem.swift; sourceTree = "<group>"; };
4B3A67E62965932D0024077F /* CompanionCollectionViewItem.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CompanionCollectionViewItem.xib; sourceTree = "<group>"; };
4B41CA3D29DC638300FF98BB /* PerseusLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerseusLogger.swift; sourceTree = "<group>"; };
4B44EDFA294661E80084C192 /* main.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.yml; path = ../.github/workflows/main.yml; sourceTree = "<group>"; };
4B44EDFE29466A320084C192 /* DarkModeSwitching.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DarkModeSwitching.swift; sourceTree = "<group>"; };
4B44EE0029466A320084C192 /* PerseusUISystemKitSingle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerseusUISystemKitSingle.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -126,6 +128,7 @@
children = (
4B44EDFE29466A320084C192 /* DarkModeSwitching.swift */,
4B44EE0029466A320084C192 /* PerseusUISystemKitSingle.swift */,
4B41CA3D29DC638300FF98BB /* PerseusLogger.swift */,
);
path = FirstPartyCode;
sourceTree = "<group>";
Expand Down Expand Up @@ -374,6 +377,7 @@
E00F83AC288A4A64000D0A01 /* main.swift in Sources */,
4B7DD3B0297D33B700172BD4 /* CustomColors.swift in Sources */,
4B26073D295DC238002813C6 /* PreferencesVC.swift in Sources */,
4B41CA3E29DC638300FF98BB /* PerseusLogger.swift in Sources */,
4B6F459C2965AD1200859528 /* CompanionViewController.swift in Sources */,
E0A29354288E70B200F467E8 /* AppDelegate.swift in Sources */,
E0A2934C288E520000F467E8 /* MainWindowController.swift in Sources */,
Expand All @@ -396,13 +400,13 @@
4B0158EB29103C0D009F1803 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = 6DRVN4F88C;
INFOPLIST_FILE = DarkModeDiscoveryTests/Configuration/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -420,13 +424,13 @@
4B0158EC29103C0D009F1803 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = 6DRVN4F88C;
INFOPLIST_FILE = DarkModeDiscoveryTests/Configuration/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -567,7 +571,6 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = 6DRVN4F88C;
ENABLE_HARDENED_RUNTIME = NO;
INFOPLIST_FILE = "$(SRCROOT)/DarkModeDiscovery/Configuration/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -576,6 +579,7 @@
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = com.perseus.lab.macos.DarkModeDiscovery;
PRODUCT_MODULE_NAME = "$(TARGET_NAME)";
PRODUCT_NAME = "Dark Mode Discovery";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.2;
Expand All @@ -591,7 +595,6 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = 6DRVN4F88C;
ENABLE_HARDENED_RUNTIME = NO;
ENABLE_TESTABILITY = YES;
INFOPLIST_FILE = "$(SRCROOT)/DarkModeDiscovery/Configuration/Info.plist";
Expand All @@ -601,6 +604,7 @@
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = com.perseus.lab.macos.DarkModeDiscovery;
PRODUCT_MODULE_NAME = "$(TARGET_NAME)";
PRODUCT_NAME = "Dark Mode Discovery";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate {

func applicationDidFinishLaunching(_ aNotification: Notification) {
#if DEBUG && true
print(">> Launching with business matter purpose")
print(">> [\(type(of: self))]." + #function)
#endif

PerseusLogger.message("Launching with business matter purpose", .info)
PerseusLogger.message("[\(type(of: self))].\(#function)")

AppearanceService.recalculateStyleIfNeeded()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// PerseusLogger.swift
// PerseusRealDeal
//
// Created by Mikhail Zhigulin in 7531.
//
// Copyright © 7531 Mikhail Zhigulin of Novosibirsk.
// Copyright © 7531 PerseusRealDeal.
// All rights reserved.
//
//
// MIT License
//
// Copyright © 7531 Mikhail Zhigulin of Novosibirsk
// Copyright © 7531 PerseusRealDeal
//
// The year starts from the creation of the world according to a Slavic calendar.
// September, the 1st of Slavic year.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notices and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

import Foundation

class PerseusLogger {

enum Status {
case on
case off
}

enum Level: Int, CustomStringConvertible {

var description: String {
switch self {
case .info:
return "INFO"
case .debug:
return "DEBUG"
case .error:
return "ERROR"
}
}

case info = 3
case debug = 2 // Default.
case error = 1
}

#if DEBUG
static var turned = Status.on
#else
static var turned = Status.off
#endif

static var level = Level.debug
static var short = true

static func message(_ text: @autoclosure () -> String,
_ type: Level = .debug,
_ file: StaticString = #file,
_ line: UInt = #line) {
guard turned == .on, type.rawValue <= level.rawValue else { return }
if short {
print("\(type.description): \(text())")
} else {
let fileName = (file.description as NSString).lastPathComponent
print("\(type.description): \(text()), file: \(fileName), line: \(line)")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// PerseusUISystemKitSingle.swift
// Version: 1.1.2
// Version: 1.1.3
//
// Contains Dependency PerseusDarkModeSingle v1.1.3
// Contains Dependency PerseusDarkModeSingle v1.1.4
//
// Created by Mikhail Zhigulin in 7530.
//
Expand Down Expand Up @@ -52,18 +52,21 @@ public typealias Responder = NSResponder
public typealias Color = NSColor
#endif

// MARK: - PerseusDarkModeSingle v1.1.3
// MARK: - PerseusDarkModeSingle v1.1.4

// 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 @@ -73,7 +76,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 @@ -107,26 +110,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 @@ -212,7 +204,6 @@ public class AppearanceService {

internal static func recalculateStyleIfNeeded() {
let actualStyle = DarkModeDecision.calculate(DarkModeUserChoice, shared.systemStyle)

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

Expand Down Expand Up @@ -254,6 +245,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 @@ -344,6 +336,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 @@ -462,33 +455,7 @@ 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 { }

// MARK: - PerseusUISystemKitSingle v1.1.2
// MARK: - PerseusUISystemKitSingle v1.1.3

// MARK: - Required Color Creator with 0 .. 255 format

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1</string>
<key>CFBundleVersion</key>
<string>0</string>
<key>LSMinimumSystemVersion</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ class CompanionListViewController: NSViewController {
private func reloadCompanionListAndSelectTheFirstIfNecessary() {

if companionList.isEmpty {
#if DEBUG && false
print("\(type(of: self)).\(#function), it's empty!")
#endif

PerseusLogger.message("[\(type(of: self))].\(#function), it's empty!")
return
}

Expand Down
4 changes: 4 additions & 0 deletions DarkModeDiscovery/DarkModeDiscovery/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

import Cocoa

// MARK: - Logger

PerseusLogger.level = .info

// MARK: - Construct the app's top elements

let app = NSApplication.shared
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
//

import XCTest
@testable import DarkModeDiscovery

// MARK: - The Testing Application Delegate

@objc(TestingAppDelegate)
class TestingAppDelegate: NSResponder, NSApplicationDelegate {

func applicationDidFinishLaunching(_ aNotification: Notification) {
print("<< Launching with testing matter purpose")
print("<< \(type(of: self)) " + #function)

PerseusLogger.message("Launching with testing matter purpose", .info)
PerseusLogger.message("[\(type(of: self))].\(#function)")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
//

import XCTest
@testable import DarkModeDiscovery

class DarkModeDiscoveryTests: XCTestCase {

// func test_zero() { XCTFail("Tests not yet implemented in \(type(of: self)).") }

func test_the_first_success() { XCTAssertTrue(true, "It's done!") }
}

0 comments on commit 9e434e6

Please sign in to comment.