Skip to content

Commit

Permalink
feat/refactor: API to handle image loading asynchronously and safely.
Browse files Browse the repository at this point in the history
fix: Resolved OpenGL context errors by scheduling texture creation on the main thread.
refactor: Updated GuiCapeManager.kt to utilize the non-suspending callImage() function from APIConnectorUtils.
feat: Implemented error handling in GuiUpdate.kt to display error messages when API reload fails.
feat: Added a loading bar and progress updates in GuiUpdate.kt to enhance user feedback during API reload.
chore: Improved logging in APIConnectorUtils.kt for better debugging of image loading processes.
fix: Ensured that all OpenGL-related operations are performed on the main thread to prevent crashes.
feat: Scheduled API checks and image loading during client startup to ensure all resources are ready before GUI initialization.
  • Loading branch information
opZywl committed Dec 30, 2024
1 parent eced4cc commit 7657156
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 138 deletions.
11 changes: 5 additions & 6 deletions src/main/java/net/ccbluex/liquidbounce/FDPClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package net.ccbluex.liquidbounce

import com.formdev.flatlaf.themes.FlatMacLightLaf
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.ccbluex.liquidbounce.event.ClientShutdownEvent
import net.ccbluex.liquidbounce.event.EventManager
import net.ccbluex.liquidbounce.event.StartupEvent
Expand Down Expand Up @@ -53,7 +54,7 @@ import net.ccbluex.liquidbounce.utils.inventory.InventoryManager
import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes
import net.ccbluex.liquidbounce.utils.inventory.InventoryUtils
import net.ccbluex.liquidbounce.utils.inventory.SilentHotbar
import net.ccbluex.liquidbounce.utils.io.APIConnectorUtils
import net.ccbluex.liquidbounce.utils.io.APIConnectorUtils.performAllChecksAsync
import net.ccbluex.liquidbounce.utils.movement.BPSUtils
import net.ccbluex.liquidbounce.utils.movement.MovementUtils
import net.ccbluex.liquidbounce.utils.movement.TimerBalanceUtils
Expand Down Expand Up @@ -202,11 +203,9 @@ object FDPClient {
registerModules()

// API Connecter
APIConnectorUtils.checkStatus()
APIConnectorUtils.checkChangelogs()
APIConnectorUtils.checkBugs()
APIConnectorUtils.loadPictures()

runBlocking {
performAllChecksAsync()
}
runCatching {
// Remapper
loadSrg()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object GuiCapeManager : AbstractScreen() {
}

override fun onGuiClosed() {

// Implement any necessary cleanup when the GUI is closed
}

override fun initGui() {
Expand All @@ -76,7 +76,7 @@ object GuiCapeManager : AbstractScreen() {
}

private fun updateCapeStyle() {
nowCape = CapeStyle.valueOf(styleValue.value.uppercase(Locale.getDefault()))
nowCape = CapeStyle.valueOf(styleValue.value.uppercase(Locale.getDefault()))
}

override fun actionPerformed(button: GuiButton) {
Expand All @@ -90,7 +90,7 @@ object GuiCapeManager : AbstractScreen() {
chooseIndex = styleValue.values.size - 1
}

styleValue.value = styleValue.values[chooseIndex]
styleValue.value = styleValue.values[chooseIndex]
updateCapeStyle()
}

Expand Down Expand Up @@ -193,4 +193,4 @@ object GuiCapeManager : AbstractScreen() {
}

override fun doesGuiPauseGame() = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
*/
package net.ccbluex.liquidbounce.ui.client.gui

import kotlinx.coroutines.launch
import net.ccbluex.liquidbounce.FDPClient.IN_DEV
import net.ccbluex.liquidbounce.features.module.modules.client.HUDModule.guiColor
import net.ccbluex.liquidbounce.handler.api.ClientUpdate
import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile
import net.ccbluex.liquidbounce.ui.font.Fonts
import net.ccbluex.liquidbounce.utils.io.APIConnectorUtils.checkBugs
import net.ccbluex.liquidbounce.utils.io.APIConnectorUtils.checkChangelogs
import net.ccbluex.liquidbounce.utils.io.APIConnectorUtils.checkStatus
import net.ccbluex.liquidbounce.utils.io.APIConnectorUtils.loadPictures
import net.ccbluex.liquidbounce.utils.io.APIConnectorUtils.performAllChecksAsync
import net.ccbluex.liquidbounce.utils.io.MiscUtils
import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawBloom
import net.ccbluex.liquidbounce.utils.ui.AbstractScreen
import net.minecraft.client.gui.GuiButton
Expand Down Expand Up @@ -128,17 +126,16 @@ class GuiUpdate : AbstractScreen() {
loadProgress = 0
errorMessage = null

SharedScopes.IO.launch {
try {
checkStatus()
checkChangelogs()
checkBugs()
loadPictures()
performAllChecksAsync()
} catch (e: Exception) {
errorMessage = "Failed to reload API: ${e.message}"
} finally {
isLoading = false
loadProgress = 100
}
}
}
}
}
Expand Down
Loading

0 comments on commit 7657156

Please sign in to comment.