         if now < fadeUntil {
             return
         }
+        let success = CGError(kCGErrorSuccess.value)
         var token = CGDisplayFadeReservationToken(kCGDisplayFadeReservationInvalidToken)
-        let status = CGAcquireDisplayFadeReservation(fadeTime, &token)
-        if status != CGError(kCGErrorSuccess.value) {
+        var e = CGAcquireDisplayFadeReservation(fadeTime, &token)
+        if e != success {
             return
         }
         let red: Float = go ? 0 : 1
         let blue: Float = go ? 1 : 0
-        CGDisplayFade(token, 0, CGDisplayBlendFraction(kCGDisplayBlendNormal), fadeValue, red, 0, blue, 0)
+        e = CGDisplayFade(token, 0, CGDisplayBlendFraction(kCGDisplayBlendNormal), fadeValue, red, 0, blue, 0)
+        if e != success {
+            errorLog.warn("CGError returned \(e.value)")
+        }
         fadeUntil = now + Double(fadeTime)
     }
     


@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet var item: NSStatusItem!
    
    var app: App?
    var timer: NSTimer?
    

    }

    func applicationDidFinishLaunching(aNotification: NSNotification) {
        item = NSStatusBar.systemStatusBar().statusItemWithLength(/* NSVariableStatusItemLength */ -1)
        let prompt: String = kAXTrustedCheckOptionPrompt.takeUnretainedValue()
        let trusted = AXIsProcessTrustedWithOptions([prompt: true]) != 0
        if item == nil || !trusted {
            NSApplication.sharedApplication().terminate(nil)
            return
        }
        
        let errorLog = ErrorLog()
        var root : String? = "~/Library/Application Support/Ergometer".stringByStandardizingPath
        var e : NSError?
        if !NSFileManager.defaultManager().createDirectoryAtPath(root!, withIntermediateDirectories: true, attributes: nil, error: &e) {
            root = nil
            errorLog.warn("Couldn't create <\(root)>" + (e != nil ? ": " + e!.localizedDescription : ""))
        }
        
        app = App(clock: systemClock, makeFile: makeSystemFile, root: root, errorLog: errorLog)
        tick()
        let mask : NSEventMask =
            .KeyDownMask |
            .FlagsChangedMask |
