fix: 修复显示更新日志计数异常

This commit is contained in:
icyleaf
2022-08-04 11:51:53 +08:00
parent 5f18098802
commit 76e6062fa7
2 changed files with 23 additions and 21 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = 'Zealot'
s.version = '0.2.0'
s.version = '0.2.1'
s.summary = 'App new beta version check for zealot. Learn more at https://zealot.ews.im'
s.homepage = 'https://zealot.ews.im'
s.license = { :type => 'MIT', :file => 'LICENSE' }
+22 -20
View File
@@ -13,21 +13,21 @@ public final class Zealot: NSObject {
public var enviroment: String
public var endpoint: String
public var channelKeys: [String: String] = [:]
public init(endpoint: String, channelKey: String) {
self.endpoint = endpoint
self.enviroment = defaultEnvironment
self.channelKeys[enviroment] = channelKey
super.init()
}
public init(endpoint: String, channelKey: String, enviroment: String) {
self.endpoint = endpoint
self.enviroment = enviroment
self.channelKeys[enviroment] = channelKey
super.init()
}
public init(endpoint: String, channelKeys: [String: String], default_enviroment: String) {
self.endpoint = endpoint
self.enviroment = default_enviroment
@@ -38,11 +38,11 @@ public final class Zealot: NSObject {
// MARK: - Public methods
public extension Zealot {
func setChannelKey(channelKey: String, environment: String) {
self.channelKeys[environment] = channelKey
}
func checkVersion() {
let client = try! Client(endpoint: endpoint, channelKey: useChannelKey())
client.checkVersion { (result) in
@@ -64,7 +64,7 @@ private extension Zealot {
let alertController = createAlertVC(releases: channel.releases)
WindowHandler.shared.present(viewController: alertController)
}
func updateAlertAction(url: String) -> UIAlertAction {
return UIAlertAction(title: "立即更新", style: .default) { (UIAlertAction) in
guard let installUrl = URL(string: url) else { return }
@@ -78,31 +78,31 @@ private extension Zealot {
}
}
}
func cancelAlertAction() -> UIAlertAction {
return UIAlertAction(title: "下次再说", style: .cancel) { (UIAlertAction) in
WindowHandler.shared.dismiss()
}
}
func createAlertVC(releases: [Channel.Release]) -> UIAlertController {
let release = releases[0]
let title = "⭐️发现新版本⭐️"
let message = "\(release.releaseVersion) (\(release.buildVersion))"
let changelog = generateChangelog(releases: releases)
let alert = UIAlertController(title: title,
message: message,
preferredStyle: .alert)
alert.setMaxHeight(UIScreen.main.bounds.height / 2)
alert.addTextView(text: changelog)
alert.addAction(updateAlertAction(url: release.installUrl))
alert.addAction(cancelAlertAction())
return alert
}
}
@@ -111,14 +111,16 @@ private extension Zealot {
private extension Zealot {
func generateChangelog(releases: [Channel.Release]) -> String {
var changelogMessage = [String]()
var number = 1
for release in releases {
for (index, changelog) in release.changelog.enumerated() {
for changelog in release.changelog {
if changelog.message.isEmpty { continue }
changelogMessage.append("\(index + 1). \(changelog.message)")
changelogMessage.append("\(number). \(changelog.message)")
number += 1
}
}
return changelogMessage.joined(separator: "\n")
}
@@ -128,10 +130,10 @@ private extension Zealot {
if defaultChannelkey != nil {
return defaultChannelkey!
}
throw ZealotError.notFoundChannelKey
}
return channelKey
}
}