mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
- add beta mechanism to the updater (miss beta version if stable installed; install a new beta version if the oldest beta installed)
This commit is contained in:
@@ -834,19 +834,76 @@ public func IsNewestVersion(currentVersion: String, latestVersion: String) -> Bo
|
||||
let currentArray = currentNumber.condenseWhitespace().split(separator: ".")
|
||||
let latestArray = latestNumber.condenseWhitespace().split(separator: ".")
|
||||
|
||||
let current = Version(major: Int(currentArray[0]) ?? 0, minor: Int(currentArray[1]) ?? 0, patch: Int(currentArray[2]) ?? 0)
|
||||
let latest = Version(major: Int(latestArray[0]) ?? 0, minor: Int(latestArray[1]) ?? 0, patch: Int(latestArray[2]) ?? 0)
|
||||
var current = Version(major: Int(currentArray[0]) ?? 0, minor: Int(currentArray[1]) ?? 0, patch: Int(currentArray[2]) ?? 0)
|
||||
var latest = Version(major: Int(latestArray[0]) ?? 0, minor: Int(latestArray[1]) ?? 0, patch: Int(latestArray[2]) ?? 0)
|
||||
|
||||
if latest.major > current.major {
|
||||
return true
|
||||
if let patch = currentArray.last, patch.contains("-") {
|
||||
let arr = patch.split(separator: "-")
|
||||
if let patchNumber = arr.first {
|
||||
current.patch = Int(patchNumber) ?? 0
|
||||
}
|
||||
if let beta = arr.last {
|
||||
current.beta = Int(beta.replacingOccurrences(of: "beta", with: "")) ?? 0
|
||||
}
|
||||
}
|
||||
|
||||
if latest.minor > current.minor && latest.major >= current.major {
|
||||
return true
|
||||
if let patch = latestArray.last, patch.contains("-") {
|
||||
let arr = patch.split(separator: "-")
|
||||
if let patchNumber = arr.first {
|
||||
latest.patch = Int(patchNumber) ?? 0
|
||||
}
|
||||
if let beta = arr.last {
|
||||
latest.beta = Int(beta.replacingOccurrences(of: "beta", with: "")) ?? 0
|
||||
}
|
||||
}
|
||||
|
||||
if latest.patch > current.patch && latest.minor >= current.minor && latest.major >= current.major {
|
||||
return true
|
||||
// current is not beta + latest is not beta
|
||||
if current.beta == nil && latest.beta == nil {
|
||||
if latest.major > current.major {
|
||||
return true
|
||||
}
|
||||
|
||||
if latest.minor > current.minor && latest.major >= current.major {
|
||||
return true
|
||||
}
|
||||
|
||||
if latest.patch > current.patch && latest.minor >= current.minor && latest.major >= current.major {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// current version is beta + last version is not beta
|
||||
if current.beta != nil && latest.beta == nil {
|
||||
if latest.major > current.major {
|
||||
return true
|
||||
}
|
||||
|
||||
if latest.minor > current.minor && latest.major >= current.major {
|
||||
return true
|
||||
}
|
||||
|
||||
if latest.patch >= current.patch && latest.minor >= current.minor && latest.major >= current.major {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// current version is beta + last version is beta
|
||||
if current.beta != nil && latest.beta != nil {
|
||||
if latest.major > current.major {
|
||||
return true
|
||||
}
|
||||
|
||||
if latest.minor > current.minor && latest.major >= current.major {
|
||||
return true
|
||||
}
|
||||
|
||||
if latest.patch >= current.patch && latest.minor >= current.minor && latest.major >= current.major {
|
||||
return true
|
||||
}
|
||||
|
||||
if latest.beta! > current.beta! && latest.patch >= current.patch && latest.minor >= current.minor && latest.major >= current.major {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
@@ -30,6 +30,8 @@ public struct Version {
|
||||
var major: Int = 0
|
||||
var minor: Int = 0
|
||||
var patch: Int = 0
|
||||
|
||||
var beta: Int? = nil
|
||||
}
|
||||
|
||||
public class macAppUpdater {
|
||||
|
||||
Reference in New Issue
Block a user