Skip to content

Commit

Permalink
UI: 修复可能存在的线程阻塞问题
Browse files Browse the repository at this point in the history
  • Loading branch information
purofle committed Dec 31, 2023
1 parent cbfec06 commit b050926
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import com.github.purofle.nmsl.game.Manifest
import com.github.purofle.nmsl.game.VersionType
import com.github.purofle.nmsl.utils.getDefaultProvider
import com.github.purofle.nmsl.utils.getGameDownloader
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.time.Instant
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
Expand All @@ -46,7 +48,9 @@ class DownloadPage : Page {
var remoteManifest: Manifest? by rememberSaveable { mutableStateOf(null) }

LaunchedEffect(Unit) {
remoteManifest = GameManager.downloadManifest(DownloadProvider.getDefaultProvider())
withContext(Dispatchers.IO) {
remoteManifest = GameManager.downloadManifest(DownloadProvider.getDefaultProvider())
}
}

val scope = rememberCoroutineScope()
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/github/purofle/nmsl/pages/GamePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.github.purofle.nmsl.config.NmslConfig
import com.github.purofle.nmsl.game.GameManager
import com.github.purofle.nmsl.utils.getGameDownloader
import com.github.purofle.nmsl.utils.startGame
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.jetbrains.skiko.ClipboardManager
import org.jetbrains.skiko.URIManager
Expand Down Expand Up @@ -91,8 +92,8 @@ class GamePage : Page {
if (selectedGame.isNotBlank()) {
ExtendedFloatingActionButton(
{
scope.launch(Dispatchers.IO) {
val gameDownloader = getGameDownloader(selectedGame)
scope.launch {
startGame(selectedGame, gameDownloader.getLauncherArgument())
}

Expand Down

0 comments on commit b050926

Please sign in to comment.