<commit_before>//
//  ArticleExtractorButton.swift
//  NetNewsWire
//
//  Created by <NAME> on 9/18/19.
//  Copyright © 2019 Ranchero Software. All rights reserved.
//

import Foundation

class LegacyArticleExtractorButton: NSButton {
	
	var isError = false {
		didSet {
			if isError != oldValue {
				needsDisplay = true
			}
		}
	}
	
	var isInProgress = false {
		didSet {
			if isInProgress != oldValue {
				needsDisplay = true
			}
		}
	}
	
	override init(frame frameRect: NSRect) {
		super.init(frame: frameRect)
		wantsLayer = true
	}
	
	required init?(coder: NSCoder) {
		super.init(coder: coder)
		wantsLayer = true
	}

	override func draw(_ dirtyRect: NSRect) {
		super.draw(dirtyRect)
		
		guard let hostedLayer = self.layer else {
			return
		}

		if let imageLayer = hostedLayer.sublayers?[0] {
			if needsToDraw(imageLayer.bounds) {
				imageLayer.removeFromSuperlayer()
			} else {
				return
			}
		}

		let opacity: Float = isEnabled ? 1.0 : 0.5
		
		switch true {
		case isError:
			addImageSublayer(to: hostedLayer, image: AppAssets.articleExtractorError, opacity: opacity)
		case isInProgress:
			addAnimatedSublayer(to: hostedLayer)
		default:
			if NSApplication.shared.isActive {
				addImageSublayer(to: hostedLayer, image: AppAssets.legacyArticleExtractor, opacity: opacity)
			} else {
				if NSApplication.shared.effectiveAppearance.isDarkMode {
					addImageSublayer(to: hostedLayer, image: AppAssets.legacyArticleExtractorInactiveDark, opacity: opacity)
				} else {
					addImageSublayer(to: hostedLayer, image: AppAssets.legacyArticleExtractorInactiveLight, opacity: opacity)
				}
			}
		}
	}
	
	private func makeLayerForImage(_ image: NSImage) -> CALayer {
		let imageLayer = CALayer()
		imageLayer.bounds = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)<commit_msg>Use the correct error asset.<commit_after>//
//  ArticleExtractorButton.swift
//  NetNewsWire
//
//  Created by <NAME> on 9/18/19.
//  Copyright © 2019 Ranchero Software. All rights reserved.
//

import Foundation

class LegacyArticleExtractorButton: NSButton {
	
	var isError = false {
		didSet {
			if isError != oldValue {
				needsDisplay = true
			}
		}
	}
	
	var isInProgress = false {
		didSet {
			if isInProgress != oldValue {
				needsDisplay = true
			}
		}
	}
	
	override init(frame frameRect: NSRect) {
		super.init(frame: frameRect)
		wantsLayer = true
	}
	
	required init?(coder: NSCoder) {
		super.init(coder: coder)
		wantsLayer = true
	}

	override func draw(_ dirtyRect: NSRect) {
		super.draw(dirtyRect)
		
		guard let hostedLayer = self.layer else {
			return
		}

		if let imageLayer = hostedLayer.sublayers?[0] {
			if needsToDraw(imageLayer.bounds) {
				imageLayer.removeFromSuperlayer()
			} else {
				return
			}
		}

		let opacity: Float = isEnabled ? 1.0 : 0.5
		
		switch true {
		case isError:
			addImageSublayer(to: hostedLayer, image: AppAssets.legacyArticleExtractorError, opacity: opacity)
		case isInProgress:
			addAnimatedSublayer(to: hostedLayer)
		default:
			if NSApplication.shared.isActive {
				addImageSublayer(to: hostedLayer, image: AppAssets.legacyArticleExtractor, opacity: opacity)
			} else {
				if NSApplication.shared.effectiveAppearance.isDarkMode {
					addImageSublayer(to: hostedLayer, image: AppAssets.legacyArticleExtractorInactiveDark, opacity: opacity)
				} else {
					addImageSublayer(to: hostedLayer, image: AppAssets.legacyArticleExtractorInactiveLight, opacity: opacity)
				}
			}
		}
	}
	
	private func makeLayerForImage(_ image: NSImage) -> CALayer {
		let imageLayer = CALayer()
		imageLayer.bounds = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
{'fraction_non_alphanumeric': 0.09893704006541292, 'fraction_numerical': 0.00872172254020169, 'mean_word_length': 3.553349875930521, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6713190', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1203, 'n_words': 279}