<commit_before>//
//  LoadingIndicatorViewController.swift
//  Hipstapaper
//
//  Created by <NAME> on 2/2/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Common
import Aspects

//
////
////// Ok, this is a pile of hacks, so lets get started
////
//

// swiftlint:disable:next type_name
class AppearanceObservingLoadingIndicatorViewController: LoadingIndicatorViewController {

    private var viewDidMoveToWindowToken: AspectToken?
    private var appearanceKVOToken: NSKeyValueObservation?

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //
        // We need to wait for the view to move into the window.
        // NSViewController has no override for this but NSView does 🙄.
        //
        let viewDidMoveToWindowClosure: @convention(block) () -> Void = { [unowned self] in
            //
            // Once the view is in the window we'll update the appearance manually
            //
            self.updateAppearance()

            //
            // Now we need to make sure the window is set
            // The view could be moved out of the window as well
            //
            guard let window = self.view.window else {
                // If we move it out, we clear our KVO token to break the relationship
                self.appearanceKVOToken = nil
                return
            }

            //
            // Now we observe whenever the effective appearance changes
            // When that happens, we can update the appearance
            //
            self.appearanceKVOToken = window.observe(\.effectiveAppearance) { _, _ in
                self.updateAppearance()<commit_msg>fixed dark mode for old OS’s<commit_after>//
//  LoadingIndicatorViewController.swift
//  Hipstapaper
//
//  Created by <NAME> on 2/2/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Common
import Aspects

//
////
////// Ok, this is a pile of hacks, so lets get started
////
//

// swiftlint:disable:next type_name
class AppearanceObservingLoadingIndicatorViewController: LoadingIndicatorViewController {

    private var viewDidMoveToWindowToken: AspectToken?
    private var appearanceKVOToken: NSKeyValueObservation?

    override func viewDidLoad() {
        super.viewDidLoad()

        //
        // We need to wait for the view to move into the window.
        // NSViewController has no override for this but NSView does 🙄.
        //
        let viewDidMoveToWindowClosure: @convention(block) () -> Void = { [unowned self] in
            //
            // Once the view is in the window we'll update the appearance manually
            //
            self.updateAppearance()

            //
            // Now we need to make sure the window is set
            // The view could be moved out of the window as well
            //
            guard let window = self.view.window else {
                // If we move it out, we clear our KVO token to break the relationship
                self.appearanceKVOToken = nil
                return
            }

            //
            // Now we observe whenever the effective appearance changes
            // When that happens, we can update the appearance
            //
            // For some reason, on old macOS regular `appearance`
            // fires the KVO when changing.
            // But on 10.14, `effectiveAppearance` fires the KVO instead.
            //
            if #available(macOS 10.14, *) {
                self.appearanceKVOToken
                    = window.observe(\.effectiveAppearance)
                    { _, _ in self.updateAppearance() }
            } else {
                self.appearanceKVOToken
                    = window.observe(\.appearance)
                    { _, _ in self.updateAppearance() }
{'fraction_non_alphanumeric': 0.0829358770535241, 'fraction_numerical': 0.006359300476947536, 'mean_word_length': 1.662200282087447, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5047201', 'n_tokens_mistral': 984, 'n_tokens_neox': 939, 'n_words': 337}