Skip to content

Commit

Permalink
自动更新:增加"跳过当前版本"和"7天不再提示"选项
Browse files Browse the repository at this point in the history
  • Loading branch information
way-zer committed Dec 22, 2024
1 parent 8775d92 commit 8f69b9a
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/mindustryX/features/AutoUpdate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import mindustry.ui.Bar
import mindustry.ui.dialogs.BaseDialog
import mindustryX.VarsX
import mindustryX.features.ui.Format
import java.time.Duration
import java.time.Instant

object AutoUpdate {
data class Release(val tag: String, val version: String, val json: Jval) {
Expand Down Expand Up @@ -50,6 +52,9 @@ object AutoUpdate {
var latest: Release? = null
val newVersion: Release? get() = latest?.takeIf { it.version > VarsX.version }

val ignoreOnce = SettingsV2.TextPref.create("AutoUpdate.ignoreOnce", "")
val ignoreUntil = SettingsV2.TextPref.create("AutoUpdate.ignoreUntil", "")

fun checkUpdate() {
if (versions.isNotEmpty()) return
Http.get("https://api.github.com/repos/$repo/releases")
Expand All @@ -67,11 +72,15 @@ object AutoUpdate {
private fun fetchSuccess() {
val available = versions.filter { it.matchCurrent() }
latest = available.maxByOrNull { it.version } ?: return
newVersion?.takeIf { Core.settings.getBool("showUpdateDialog", true) }?.let {
if (Vars.clientLoaded) return showDialog(newVersion)
Events.on(EventType.ClientLoadEvent::class.java) {
Vars.ui.showConfirm("检测到新版MindustryX!\n打开更新列表?", ::showDialog)
}

val newVersion = newVersion ?: return
if (!Core.settings.getBool("showUpdateDialog", true) || ignoreOnce.value == newVersion.version
|| kotlin.runCatching { Instant.parse(ignoreUntil.value) > Instant.now() }.getOrNull() == true
) return

if (Vars.clientLoaded) return showDialog(newVersion)
Events.on(EventType.ClientLoadEvent::class.java) {
Vars.ui.showConfirm("检测到新版MindustryX!\n打开更新列表?", ::showDialog)
}
}

Expand Down Expand Up @@ -109,6 +118,17 @@ object AutoUpdate {
}
}.width(50f)

if (version == newVersion) {
row().check("跳过当前版本") {
if (it) ignoreOnce.value = version.version
else ignoreOnce.resetDefault()
}.checked { ignoreOnce.value == version.version }
row().check("7天不再提示") {
if (it) ignoreOnce.value = (Instant.now() + Duration.ofDays(7)).toString()
else ignoreUntil.resetDefault()
}.checked { kotlin.runCatching { Instant.parse(ignoreUntil.value) > Instant.now() }.getOrNull() == true }
}

row().button("自动下载更新") {
if (asset == null) return@button
if (!VarsX.isLoader && OS.isAndroid) {
Expand Down

0 comments on commit 8f69b9a

Please sign in to comment.