     }
     
     private func loadVersionNumber() {
-        self.versionLabel.stringValue = appVersion
+        self.versionLabel.stringValue = GeneralPreferencePane.appVersion
     }
     
     private func populatePopUpButton() {

    @IBOutlet weak var checkForUpdatesButton:              NSButton!
    
    /// Core
    private var appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String ?? "Unknown"
    
    /// Preferenceable
    let toolbarItemTitle: String   = "General"

        self.checkForUpdatesButton.isEnabled = false
        self.checkForUpdatesButton.title     = "Checking..."
        
        GeneralPreferencePane.hasLatestVersion(completion: { [weak self] latestVersion, latestVersionDownloadURL in
            guard let _self = self else { return }
            DispatchQueue.main.async {
                
                let alert: NSAlert = NSAlert()
                alert.alertStyle = NSAlert.Style.informational
                if let latestVersion = latestVersion, let latestVersionDownloadURL = latestVersionDownloadURL {
                    alert.messageText     = "New version available!"
                    alert.informativeText = "Do you want to download version \"\(latestVersion)\" now?"
                    alert.addButton(withTitle: "Download")
                    alert.addButton(withTitle: "Later")
                    alert.beginSheetModal(for: _self.view.window!, completionHandler: { modalResponse in
                        if modalResponse == .alertFirstButtonReturn {
                            NSWorkspace.shared.open(latestVersionDownloadURL)
                        }
                    })
                }else {
                    alert.messageText     = "Installed version: \(GeneralPreferencePane.appVersion)"
                    alert.informativeText = "Already on latest version"
                    alert.addButton(withTitle: "Ok")
                    alert.beginSheetModal(for: _self.view.window!, completionHandler: nil)
                }
                
                self?.checkForUpdatesButton.isEnabled = true
                self?.checkForUpdatesButton.title     = "Check for updates"
                
            }
        })
        
    }
}

extension GeneralPreferencePane {
    
    class func hasLatestVersion(completion: @escaping (String?, URL?) -> Void) {
        let latestVersionURL: URL = URL(string: "http://pock.pigigaldi.com/api/latestRelease.json")!
        URLSession.shared.dataTask(with: latestVersionURL, completionHandler: { data, response, error in
            guard let json                = try? JSONSerialization.jsonObject(with: data!, options: []) as? [String: String],
                  let latestVersionNumber = json?["version_number"], GeneralPreferencePane.appVersion < latestVersionNumber,
                  let downloadLink        = json?["download_link"],
                  let downloadURL         = URL(string: downloadLink) else {
                    completion(nil, nil)
                    return
            }
            completion(latestVersionNumber, downloadURL)
        }).resume()
    }
    
}
