Remove DB5 dependency in AppDelegate, UnreadCountView, UnreadIndicatorView.

This commit is contained in:
Brent Simmons 2019-04-13 12:11:44 -07:00
parent 0fbab99f9a
commit e1b3bda814
5 changed files with 64 additions and 32 deletions

View File

@ -7,7 +7,6 @@
// //
import AppKit import AppKit
import DB5
import Articles import Articles
import RSTree import RSTree
import RSWeb import RSWeb
@ -19,7 +18,6 @@ var appDelegate: AppDelegate!
@NSApplicationMain @NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UnreadCountProvider { class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UnreadCountProvider {
var currentTheme: VSTheme!
var faviconDownloader: FaviconDownloader! var faviconDownloader: FaviconDownloader!
var imageDownloader: ImageDownloader! var imageDownloader: ImageDownloader!
var authorAvatarDownloader: AuthorAvatarDownloader! var authorAvatarDownloader: AuthorAvatarDownloader!
@ -58,7 +56,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
private var inspectorWindowController: InspectorWindowController? private var inspectorWindowController: InspectorWindowController?
private var crashReportWindowController: CrashReportWindowController? // For testing only private var crashReportWindowController: CrashReportWindowController? // For testing only
private let log = Log() private let log = Log()
private let themeLoader = VSThemeLoader()
private let appNewsURLString = "https://nnw.ranchero.com/feed.json" private let appNewsURLString = "https://nnw.ranchero.com/feed.json"
override init() { override init() {
@ -124,8 +121,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
let localAccount = AccountManager.shared.localAccount let localAccount = AccountManager.shared.localAccount
DefaultFeedsImporter.importIfNeeded(isFirstRun, account: localAccount) DefaultFeedsImporter.importIfNeeded(isFirstRun, account: localAccount)
currentTheme = themeLoader.defaultTheme
let tempDirectory = NSTemporaryDirectory() let tempDirectory = NSTemporaryDirectory()
let bundleIdentifier = (Bundle.main.infoDictionary!["CFBundleIdentifier"]! as! String) let bundleIdentifier = (Bundle.main.infoDictionary!["CFBundleIdentifier"]! as! String)
let cacheFolder = (tempDirectory as NSString).appendingPathComponent(bundleIdentifier) let cacheFolder = (tempDirectory as NSString).appendingPathComponent(bundleIdentifier)

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0.000",
"alpha" : "0.500",
"blue" : "0.000",
"green" : "0.000"
}
}
}
]
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "1.000",
"alpha" : "0.900",
"blue" : "1.000",
"green" : "1.000"
}
}
}
]
}

View File

@ -6,20 +6,20 @@
// Copyright © 2015 Ranchero Software, LLC. All rights reserved. // Copyright © 2015 Ranchero Software, LLC. All rights reserved.
// //
import Foundation
import AppKit import AppKit
private let padding = appDelegate.currentTheme.edgeInsets(forKey: "MainWindow.SourceList.unreadCount.padding")
private let cornerRadius = appDelegate.currentTheme.float(forKey: "MainWindow.SourceList.unreadCount.cornerRadius")
private let backgroundColor = appDelegate.currentTheme.colorWithAlpha(forKey: "MainWindow.SourceList.unreadCount.backgroundColor")
private let textColor = appDelegate.currentTheme.colorWithAlpha(forKey: "MainWindow.SourceList.unreadCount.color")
private let textSize = appDelegate.currentTheme.float(forKey: "MainWindow.SourceList.unreadCount.fontSize")
private let textFont = NSFont.systemFont(ofSize: textSize, weight: NSFont.Weight.semibold)
private var textAttributes: [NSAttributedString.Key: AnyObject] = [NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.font: textFont, NSAttributedString.Key.kern: NSNull()]
private var textSizeCache = [Int: NSSize]()
class UnreadCountView : NSView { class UnreadCountView : NSView {
struct Appearance {
static let padding = NSEdgeInsets(top: 1.0, left: 7.0, bottom: 1.0, right: 7.0)
static let cornerRadius: CGFloat = 8.0
static let backgroundColor = NSColor(named: "SidebarUnreadCountBackground")!
static let textColor = NSColor(named: "SidebarUnreadCountText")!
static let textSize: CGFloat = 11.0
static let textFont = NSFont.systemFont(ofSize: textSize, weight: NSFont.Weight.semibold)
static let textAttributes: [NSAttributedString.Key: AnyObject] = [NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.font: textFont, NSAttributedString.Key.kern: NSNull()]
}
var unreadCount = 0 { var unreadCount = 0 {
didSet { didSet {
invalidateIntrinsicContentSize() invalidateIntrinsicContentSize()
@ -38,8 +38,8 @@ class UnreadCountView : NSView {
var size = NSZeroSize var size = NSZeroSize
if unreadCount > 0 { if unreadCount > 0 {
size = textSize() size = textSize()
size.width += (padding.left + padding.right) size.width += (Appearance.padding.left + Appearance.padding.right)
size.height += (padding.top + padding.bottom) size.height += (Appearance.padding.top + Appearance.padding.bottom)
} }
_intrinsicContentSize = size _intrinsicContentSize = size
intrinsicContentSizeIsValid = true intrinsicContentSizeIsValid = true
@ -52,48 +52,45 @@ class UnreadCountView : NSView {
} }
override func invalidateIntrinsicContentSize() { override func invalidateIntrinsicContentSize() {
intrinsicContentSizeIsValid = false intrinsicContentSizeIsValid = false
} }
private func textSize() -> NSSize { private static var textSizeCache = [Int: NSSize]()
private func textSize() -> NSSize {
if unreadCount < 1 { if unreadCount < 1 {
return NSZeroSize return NSZeroSize
} }
if let cachedSize = textSizeCache[unreadCount] { if let cachedSize = UnreadCountView.textSizeCache[unreadCount] {
return cachedSize return cachedSize
} }
var size = unreadCountString.size(withAttributes: textAttributes) var size = unreadCountString.size(withAttributes: Appearance.textAttributes)
size.height = ceil(size.height) size.height = ceil(size.height)
size.width = ceil(size.width) size.width = ceil(size.width)
textSizeCache[unreadCount] = size UnreadCountView.textSizeCache[unreadCount] = size
return size return size
} }
private func textRect() -> NSRect { private func textRect() -> NSRect {
let size = textSize() let size = textSize()
var r = NSZeroRect var r = NSZeroRect
r.size = size r.size = size
r.origin.x = (NSMaxX(bounds) - padding.right) - r.size.width r.origin.x = (NSMaxX(bounds) - Appearance.padding.right) - r.size.width
r.origin.y = padding.top r.origin.y = Appearance.padding.top
return r return r
} }
override func draw(_ dirtyRect: NSRect) { override func draw(_ dirtyRect: NSRect) {
let path = NSBezierPath(roundedRect: bounds, xRadius: Appearance.cornerRadius, yRadius: Appearance.cornerRadius)
let path = NSBezierPath(roundedRect: bounds, xRadius: cornerRadius, yRadius: cornerRadius) Appearance.backgroundColor.setFill()
backgroundColor.setFill()
path.fill() path.fill()
if unreadCount > 0 { if unreadCount > 0 {
unreadCountString.draw(at: textRect().origin, withAttributes: textAttributes) unreadCountString.draw(at: textRect().origin, withAttributes: Appearance.textAttributes)
} }
} }
} }

View File

@ -10,7 +10,7 @@ import AppKit
class UnreadIndicatorView: NSView { class UnreadIndicatorView: NSView {
static let unreadCircleDimension = appDelegate.currentTheme.float(forKey: "MainWindow.Timeline.cell.unreadCircleDimension") static let unreadCircleDimension: CGFloat = 8.0
static let bezierPath: NSBezierPath = { static let bezierPath: NSBezierPath = {
let r = NSRect(x: 0.0, y: 0.0, width: unreadCircleDimension, height: unreadCircleDimension) let r = NSRect(x: 0.0, y: 0.0, width: unreadCircleDimension, height: unreadCircleDimension)