Skip to content

Commit

Permalink
Support Mojave dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 14, 2018
1 parent 75a9506 commit ff7a662
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 52 deletions.
4 changes: 3 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ disabled_rules:
- file_length
- line_length
- identifier_name
- todo # Enabled this again!
- vertical_whitespace
- force_cast
- force_try
- large_tuple
- function_body_length
- nesting # Disabled because of https://github.com/realm/SwiftLint/issues/1151
- type_body_length
opt_in_rules:
- empty_count
- prohibited_super_call
Expand All @@ -20,7 +22,6 @@ opt_in_rules:
- explicit_init
- switch_case_on_newline
- number_separator
- extension_access_modifier
- closure_end_indentation
- closure_spacing
- operator_usage_whitespace
Expand Down Expand Up @@ -53,6 +54,7 @@ opt_in_rules:
- multiline_arguments
- anyobject_protocol
- redundant_type_annotation
- no_extension_access_modifier
force_cast: warning
force_unwrapping: warning
number_separator:
Expand Down
13 changes: 8 additions & 5 deletions Gifski/MainWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ final class MainWindowController: NSWindowController {

with(window) {
$0.delegate = self
$0.appearance = NSAppearance(named: .vibrantLight)
$0.titleVisibility = .hidden
$0.styleMask = [.titled, .closable, .miniaturizable, .fullSizeContentView]
$0.styleMask = [
.titled,
.closable,
.miniaturizable,
.fullSizeContentView
]
$0.tabbingMode = .disallowed
$0.collectionBehavior = .fullScreenNone
$0.titlebarAppearsTransparent = true
$0.isMovableByWindowBackground = true
$0.isRestorable = false

let vibrancyView = $0.contentView?.insertVibrancyView()
vibrancyView?.state = .active
$0.makeVibrant()
}

view?.addSubview(circularProgress)
Expand Down
22 changes: 13 additions & 9 deletions Gifski/Vendor/CircularProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public final class CircularProgress: NSView {

@IBInspectable public var color: NSColor = .systemBlue {
didSet {
backgroundCircle.strokeColor = color.with(alpha: 0.5).cgColor
progressCircle.strokeColor = color.cgColor
progressLabel.foregroundColor = color.cgColor
needsDisplay = true
}
}

Expand Down Expand Up @@ -70,6 +68,12 @@ public final class CircularProgress: NSView {
commonInit()
}

override public func updateLayer() {
backgroundCircle.strokeColor = color.with(alpha: 0.5).cgColor
progressCircle.strokeColor = color.cgColor
progressLabel.foregroundColor = color.cgColor
}

private func commonInit() {
wantsLayer = true
layer?.addSublayer(backgroundCircle)
Expand All @@ -93,7 +97,7 @@ public final class CircularProgress: NSView {
/// util.swift
///

private extension CALayer {
extension CALayer {
static func animate(
duration: TimeInterval = 1,
delay: TimeInterval = 0,
Expand Down Expand Up @@ -160,7 +164,7 @@ extension CALayer {
}


private extension NSFont {
extension NSFont {
static let helveticaNeueLight = NSFont(name: "HelveticaNeue-Light", size: 0)
}

Expand All @@ -172,7 +176,7 @@ private extension NSFont {
//}


private extension NSBezierPath {
extension NSBezierPath {
static func circle(radius: Double, center: CGPoint) -> NSBezierPath {
let path = NSBezierPath()
path.appendArc(
Expand Down Expand Up @@ -200,7 +204,7 @@ private extension NSBezierPath {
}


private extension CAShapeLayer {
extension CAShapeLayer {
static func circle(radius: Double, center: CGPoint) -> CAShapeLayer {
return CAShapeLayer(path: NSBezierPath.circle(radius: radius, center: center))
}
Expand All @@ -212,7 +216,7 @@ private extension CAShapeLayer {
}


private extension CATextLayer {
extension CATextLayer {
/// Initializer with better defaults
convenience init(text: String, fontSize: Double? = nil, color: NSColor? = nil) {
self.init()
Expand All @@ -239,7 +243,7 @@ private extension CATextLayer {
}


private final class ProgressCircleShapeLayer: CAShapeLayer {
final class ProgressCircleShapeLayer: CAShapeLayer {
convenience init(radius: Double, center: CGPoint) {
self.init()
fillColor = nil
Expand Down
2 changes: 1 addition & 1 deletion Gifski/Vendor/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class Defaults {
// Has to be `defaults` lowercase until Swift supports static subscripts…
public let defaults = Defaults()

public extension UserDefaults {
extension UserDefaults {
private func _get<T: Codable>(_ key: String) -> T? {
if isNativelySupportedType(T.self) {
return object(forKey: key) as? T
Expand Down
62 changes: 31 additions & 31 deletions Gifski/Vendor/DockProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,39 +127,39 @@ let label = with(NSTextField()) {
//}


private extension NSBezierPath {
static func progressCircle(radius: Double, center: CGPoint) -> NSBezierPath {
let startAngle: CGFloat = 90
let path = NSBezierPath()
path.appendArc(
withCenter: center,
radius: CGFloat(radius),
startAngle: startAngle,
endAngle: startAngle - 360,
clockwise: true
)
return path
}
}

//extension NSBezierPath {
// static func progressCircle(radius: Double, center: CGPoint) -> NSBezierPath {
// let startAngle: CGFloat = 90
// let path = NSBezierPath()
// path.appendArc(
// withCenter: center,
// radius: CGFloat(radius),
// startAngle: startAngle,
// endAngle: startAngle - 360,
// clockwise: true
// )
// return path
// }
//}

private final class ProgressCircleShapeLayer: CAShapeLayer {
convenience init(radius: Double, center: CGPoint) {
self.init()
fillColor = nil
lineCap = .round
path = NSBezierPath.progressCircle(radius: radius, center: center).cgPath
}

var progress: Double {
get {
return Double(strokeEnd)
}
set {
strokeEnd = CGFloat(newValue)
}
}
}
//final class ProgressCircleShapeLayer: CAShapeLayer {
// convenience init(radius: Double, center: CGPoint) {
// self.init()
// fillColor = nil
// lineCap = .round
// path = NSBezierPath.progressCircle(radius: radius, center: center).cgPath
// }
//
// var progress: Double {
// get {
// return Double(strokeEnd)
// }
// set {
// strokeEnd = CGFloat(newValue)
// }
// }
//}


//private extension NSColor {
Expand Down
2 changes: 1 addition & 1 deletion Gifski/VideoDropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DropView: SSView {
}

private let dropLabel = with(Label()) {
$0.textColor = NSColor.textColor.with(alpha: 0.5)
$0.textColor = NSColor.secondaryLabelColor
}

var highlightColor: NSColor {
Expand Down
24 changes: 20 additions & 4 deletions Gifski/util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ extension NSWindow {
}
}


extension NSWindowController {
/// Expose the `view` like in NSViewController
var view: NSView? {
Expand All @@ -172,20 +173,35 @@ extension NSWindowController {
extension NSView {
@discardableResult
func insertVibrancyView(
withAppearance appearance: NSAppearance.Name = .vibrantLight,
material: NSVisualEffectView.Material = .appearanceBased
material: NSVisualEffectView.Material = .appearanceBased,
blendingMode: NSVisualEffectView.BlendingMode = .behindWindow,
appearanceName: NSAppearance.Name? = nil
) -> NSVisualEffectView {
let view = NSVisualEffectView(frame: bounds)
view.autoresizingMask = [.width, .height]
view.blendingMode = .behindWindow
view.appearance = NSAppearance(named: appearance)
view.material = material
view.blendingMode = blendingMode

if let appearanceName = appearanceName {
view.appearance = NSAppearance(named: appearanceName)
}

addSubview(view, positioned: .below, relativeTo: nil)

return view
}
}


extension NSWindow {
func makeVibrant() {
if #available(OSX 10.14, *) {
contentView?.insertVibrancyView(material: .underWindowBackground)
}
}
}


extension NSWindow {
var toolbarView: NSView? {
return standardWindowButton(.closeButton)?.superview
Expand Down

0 comments on commit ff7a662

Please sign in to comment.