Skip to content

Commit

Permalink
Add support for fetching donation progress from github
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlaubischlump committed Nov 28, 2022
1 parent c96f9cc commit be9ef79
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Help
2 changes: 1 addition & 1 deletion LocationSimulator/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
private func openInfoViewOnVersionUpdate() {
let defaults = UserDefaults.standard
if defaults.lastAppVersion != kAppVersion {
// Segue would be nicer, but does not work
// FIXME: Segue would be nicer, but does not work
AppMenubarItem.preferences.triggerAction()
// Update the last app version
defaults.lastAppVersion = kAppVersion
Expand Down
2 changes: 2 additions & 0 deletions LocationSimulator/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ let kProjectWebsite = "https://\(kUser.lowercased()).github.io/\(kRepo)/"
let kGithubWebsite = "https://github.com/\(kUser)/\(kRepo)"
// let kGithubStatsWebsite = "https://api.github.com/ repos/\(kUser)/\(kRepo)/releases"

let kDonationInfo = "\(kGithubWebsite)/raw/info/donation.json"

// The variance to add to the movement speed. The lower bound is the minimum factor, the upper bounds the maximum
// factor to apply to the current speed. See LocationSpoofer for more details.
let kDefaultMovementSpeedVariance = 0.8..<1.2
2 changes: 1 addition & 1 deletion LocationSimulator/Donate/DonateButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DonateButton: NSButton {
self.wantsLayer = true
self.layer?.masksToBounds = false

self.font = .systemFont(ofSize: 16, weight: .medium)
self.font = .systemFont(ofSize: 16, weight: .semibold)
self.contentTintColor = kDonateTextBlue
self.backgroundColor = kDonateYellow
}
Expand Down
36 changes: 18 additions & 18 deletions LocationSimulator/Preferences/Groups/InfoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,21 @@ extension UserDefaults {
}
}

struct DonateInfo : Codable {
var supporter: Int
var donations: Double
var donationTarget: Double
var targetName: String
}

class InfoViewController: PreferenceViewControllerBase {
let donateProgress = DonateProgress()

var progressData: [String: Any]? {
var progressData: DonateInfo? {
didSet {
self.applyProgressData()
DispatchQueue.main.async {
self.applyProgressData()
}
}
}

Expand Down Expand Up @@ -95,19 +104,10 @@ class InfoViewController: PreferenceViewControllerBase {
private func loadProgressData() {
self.donateProgress.startWaitAnimation()

DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
// TODO: Load json values from server
// TODO: Add localization strings
self.progressData = [
"hasAmount": 9.81,
"goalAmount": 99.0,
"goal": "Apple Developer License",
"supporter": 2
]
DispatchQueue.main.async {
self.applyProgressData()
}
}
URLSession.shared.dataTask(with: URL(string: kDonationInfo)!) { (data, _, _) in
guard let data = data else { return }
self.progressData = try? JSONDecoder().decode(DonateInfo.self, from: data)
}.resume()
}

private func applyProgressData() {
Expand All @@ -118,9 +118,9 @@ class InfoViewController: PreferenceViewControllerBase {

self.isProgressLoaded = true
self.donateProgress.stopWaitAnimation()
self.donateProgress.hasAmount = (data["hasAmount"] as? Double) ?? 0
self.donateProgress.goalAmount = (data["goalAmount"] as? Double) ?? 0
self.donateProgress.goal = (data["goal"] as? String) ?? ""
self.donateProgress.hasAmount = data.donations
self.donateProgress.goalAmount = data.donationTarget
self.donateProgress.goal = data.targetName
}

@objc private func openDonateWindow(_ sender: NSButton) {
Expand Down

0 comments on commit be9ef79

Please sign in to comment.