Skip to content

Commit

Permalink
feat: 使用github获取最新的版本
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSkidder committed Jul 6, 2024
1 parent 2516b07 commit 10ccc68
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 33 deletions.
26 changes: 13 additions & 13 deletions shared/java/top/fpsmaster/FPSMaster.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package top.fpsmaster

import net.minecraft.crash.CrashReport
import top.fpsmaster.features.GlobalSubmitter
import top.fpsmaster.features.command.CommandManager
import top.fpsmaster.features.manager.ModuleManager
import top.fpsmaster.font.FontManager
import top.fpsmaster.interfaces.ProviderManager
import top.fpsmaster.modules.account.AccountManager
import top.fpsmaster.modules.client.AsyncTask
import top.fpsmaster.modules.client.PlayerManager
Expand All @@ -22,16 +20,10 @@ import top.fpsmaster.ui.custom.ComponentsManager
import top.fpsmaster.ui.screens.oobe.OOBEScreen
import top.fpsmaster.utils.GitInfo
import top.fpsmaster.utils.os.FileUtils
import top.fpsmaster.utils.os.HttpRequest
import top.fpsmaster.modules.i18n.Language
import top.fpsmaster.utils.thirdparty.github.UpdateChecker
import top.fpsmaster.websocket.client.WsClient
import top.fpsmaster.wrapper.Constants
import java.awt.Desktop
import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.io.PrintWriter
import javax.swing.JOptionPane


class FPSMaster {
Expand Down Expand Up @@ -111,8 +103,12 @@ class FPSMaster {

private fun checkUpdate() {
async.runnable {
isLatest = true
val s = HttpRequest["https://fpsmaster.top/version"]
val s = UpdateChecker.getLatestVersion()
if (s == null) {
isLatest = false
updateFailed = true
return@runnable
}
val version = CLIENT_VERSION.replace("v".toRegex(), "").replace("\\.".toRegex(), "").toInt()
val newVersion = s.replace("v".toRegex(), "").replace("\\.".toRegex(), "").toInt()
if (s.isNotEmpty()) {
Expand Down Expand Up @@ -198,14 +194,18 @@ class FPSMaster {
@JvmField
var async = AsyncTask(100)


@JvmField
var debug = false

@JvmField
var isLatest = false

@JvmField
var debug = false
var updateFailed = false

@JvmField
var latest = CLIENT_VERSION
var latest = ""


@JvmStatic
Expand Down
8 changes: 4 additions & 4 deletions shared/java/top/fpsmaster/features/manager/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ open class Module {
if (ProviderManager.mcProvider.getPlayer() != null)
NotificationManager.addNotification(
FPSMaster.i18n["notification.module.enable"],
FPSMaster.i18n["notification.module.enable.desc"].replace(
"%s",
String.format(
FPSMaster.i18n["notification.module.enable.desc"],
FPSMaster.i18n[this.name.lowercase(Locale.getDefault())]
),
1f
Expand All @@ -89,8 +89,8 @@ open class Module {
if (ProviderManager.mcProvider.getPlayer() != null)
NotificationManager.addNotification(
FPSMaster.i18n["notification.module.disable"],
FPSMaster.i18n["notification.module.disable.desc"].replace(
"%s",
String.format(
FPSMaster.i18n["notification.module.disable.desc"],
FPSMaster.i18n[this.name.lowercase(Locale.getDefault())]
),
1f
Expand Down
30 changes: 18 additions & 12 deletions shared/java/top/fpsmaster/ui/screens/mainmenu/MainMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MainMenu : GuiScreen() {

private var exit: GuiButton = GuiButton("X") { mc.shutdown() }

private var latest: String = "获取版本更新失败"
private var info: String = "获取版本更新失败"
private var welcome: String = "获取版本更新失败"
private var needUpdate: Boolean = false

Expand Down Expand Up @@ -114,9 +114,11 @@ class MainMenu : GuiScreen() {
)
welcome = if (FPSMaster.INSTANCE.loggedIn) {
TextFormattingProvider.getGreen()
.toString() + FPSMaster.i18n["mainmenu.welcome"] + FPSMaster.configManager.configure.getOrCreate(
"username",
""
.toString() + String.format(
FPSMaster.i18n["mainmenu.welcome"], FPSMaster.configManager.configure.getOrCreate(
"username",
""
)
)
} else {
TextFormattingProvider.getRed()
Expand All @@ -125,14 +127,18 @@ class MainMenu : GuiScreen() {
}
FPSMaster.fontManager.s16.drawString(welcome, 4, this.height - 52, Color(255, 255, 255).rgb)

if (FPSMaster.isLatest) {
latest = TextFormattingProvider.getGreen().toString() + FPSMaster.i18n["mainmenu.latest"]
if (FPSMaster.updateFailed) {
info = TextFormattingProvider.getGreen().toString() + FPSMaster.i18n["mainmenu.failed"]
} else {
latest = TextFormattingProvider.getRed().toString() + TextFormattingProvider.getBold()
.toString() + FPSMaster.i18n["mainmenu.notlatest"] + FPSMaster.latest + FPSMaster.i18n["mainmenu.toupdate"]
needUpdate = true
if (FPSMaster.isLatest) {
info = TextFormattingProvider.getGreen().toString() + FPSMaster.i18n["mainmenu.latest"]
} else {
info = TextFormattingProvider.getRed().toString() + TextFormattingProvider.getBold()
.toString() + String.format(FPSMaster.i18n["mainmenu.notlatest"], FPSMaster.latest)
needUpdate = true
}
}
FPSMaster.fontManager.s16.drawString(latest, 4, this.height - 40, Color(255, 255, 255).rgb)
FPSMaster.fontManager.s16.drawString(info, 4, this.height - 40, Color(255, 255, 255).rgb)

Render2DUtils.drawRect(0f, 0f, 0f, 0f, -1)
FPSMaster.fontManager.s16.drawString(FPSMaster.COPYRIGHT, 4, this.height - 14, Color(255, 255, 255).rgb)
Expand Down Expand Up @@ -180,8 +186,8 @@ class MainMenu : GuiScreen() {
options.mouseClick(mouseX.toFloat(), mouseY.toFloat(), mouseButton)
exit.mouseClick(mouseX.toFloat(), mouseY.toFloat(), mouseButton)
checkNotNull(FPSMaster.fontManager)
val uw = FPSMaster.fontManager.s16.getStringWidth(latest).toFloat()
val nw = FPSMaster.fontManager.s16.getStringWidth(latest).toFloat()
val uw = FPSMaster.fontManager.s16.getStringWidth(info).toFloat()
val nw = FPSMaster.fontManager.s16.getStringWidth(info).toFloat()

if (mouseButton == 0) {
if (Render2DUtils.isHovered(4f, (this.height - 52).toFloat(), nw, 14f, mouseX, mouseY)) {
Expand Down
13 changes: 13 additions & 0 deletions shared/java/top/fpsmaster/utils/thirdparty/github/UpdateChecker.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package top.fpsmaster.utils.thirdparty.github

import org.json.JSONObject
import top.fpsmaster.utils.os.HttpRequest

object UpdateChecker {
fun getLatestVersion(): String? {
val json =
HttpRequest["https://api.github.com/repos/FPSMasterTeam/FPSMaster/releases/latest"]
val jsonObject = JSONObject(json)
return jsonObject.getString("tag_name")
}
}
8 changes: 4 additions & 4 deletions shared/resources/assets/minecraft/client/lang/zh_cn.lang
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ mainmenu.multi=多人游戏
mainmenu.proxy=网易代理
mainmenu.settings=设置
mainmenu.notlogin=您未登录,点此登录
mainmenu.latest=您使用的是最新版本
mainmenu.notlatest=您使用的不是最新版本,最新版本:
mainmenu.welcome=欢迎您,
mainmenu.toupdate=,点我前往更新
mainmenu.welcome=欢迎您,%s
mainmenu.latest=您使用的是最新版本!
mainmenu.failed=获取更新失败!
mainmenu.notlatest=检测到新版本!最新版本:%s,点此更新

music.title=音乐
music.search=搜索
Expand Down

0 comments on commit 10ccc68

Please sign in to comment.