IMEApp // Fix .appVersionLabel().

This commit is contained in:
ShikiSuen 2023-07-20 22:00:27 +08:00
parent 34a6f036b5
commit 417786dca0
1 changed files with 19 additions and 7 deletions

View File

@ -77,29 +77,41 @@ public enum IMEApp {
// MARK: - // MARK: -
public static let appVersionLabel: String = { public static let appVersionLabel: String = {
let maybeStrDate: String? = { let maybeDateModified: Date? = {
guard let executableURL = Bundle.main.executableURL, guard let executableURL = Bundle.main.executableURL,
let infoDate = (try? executableURL.resourceValues(forKeys: [.creationDateKey]))?.creationDate let infoDate = (try? executableURL.resourceValues(forKeys: [.contentModificationDateKey]))?.contentModificationDate
else { else {
return nil return nil
} }
return infoDate
}()
func dateStringTag(date givenDate: Date) -> String {
let dateFormatter = DateFormatter() let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd.HHmm" dateFormatter.dateFormat = "yyyyMMdd.HHmm"
dateFormatter.timeZone = .init(secondsFromGMT: +28800) ?? .current dateFormatter.timeZone = .init(secondsFromGMT: +28800) ?? .current
let strDate = dateFormatter.string(from: infoDate) let strDate = dateFormatter.string(from: givenDate)
return strDate return strDate
}() }
guard guard
let intBuild = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as? String, let intBuild = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as? String,
let strVer = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String, let strVer = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
let strDate = maybeStrDate
else { else {
return "1.14.514 - 19190810" return "1.14.514 - 19190810"
} }
return "\(strVer) Build \(intBuild) - \(strDate)" var theResults = ["\(strVer) Build \(intBuild)"]
if let theDate = Bundle.main.getCodeSignedDate() {
theResults.append(dateStringTag(date: theDate))
} else if let theDate = maybeDateModified {
theResults.append("\(dateStringTag(date: theDate)) Unsigned")
} else {
theResults.append("Unsigned")
}
return theResults.joined(separator: " - ")
}() }()
// MARK: - // MARK: -