Skip to content

Commit

Permalink
adds screen load delay (1s) based on version sum (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
kahest authored Jan 18, 2024
1 parent d5d0c8d commit 30bb896
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions EmpowerPlant/CartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class CartViewController: UIViewController, UITableViewDelegate, UITableViewData
])

configureNavigationItems()
checkRelease()

// TODO: make this 'total' appear in a UI element
print("CartViewController | TOTAL", ShoppingCart.instance.total)
Expand Down
3 changes: 2 additions & 1 deletion EmpowerPlant/EmpowerPlantViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class EmpowerPlantViewController: UIViewController {
readCurrentDirectory()
performLongFileOperation()
processProducts()

checkRelease()


NotificationCenter.default.addObserver(forName: modifiedDBNotificationName, object: nil, queue: nil) { _ in
self.getAllProductsFromDb()
Expand Down
17 changes: 17 additions & 0 deletions EmpowerPlant/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,20 @@ public func wipeDB() {
return
}
}

/** Add a delay based on current version. */
public func checkRelease() {
guard let versionString = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String else {
print("failed to read bundle version, not sleeping")
return
}

// as a workaround to auto-incremented build numbers, we just calculate the integer sum of all segments
// of the semantic version, e.g. 0.0.28 -> 0+0+28 = 28 -> sleep, 0.0.29 -> 0+0+29 = 29 -> no sleep
let versionSum = versionString.components(separatedBy: ".").compactMap { Int($0) }.reduce(0, +)

if versionSum % 2 == 0 {
print("version sum is even, adding 1s sleep")
sleep(1) // sleep takes seconds, not ms
}
}

0 comments on commit 30bb896

Please sign in to comment.