Skip to content

Commit 26586e5

Browse files
committed
Fix runtime errors
1 parent 79e470d commit 26586e5

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

client/src/main/kotlin/core/ProcessHandler.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import kotlin.time.Duration.Companion.seconds
1414

1515
private val LOG = KotlinLogging.logger { }
1616

17-
private val _events = MutableSharedFlow<Unit>(extraBufferCapacity = Channel.UNLIMITED)
17+
sealed interface Event {
18+
object GtaProcessNotFound : Event
19+
data class RestartError(val exception: Exception) : Event
20+
}
21+
22+
private val _events = MutableSharedFlow<Event>(extraBufferCapacity = Channel.UNLIMITED)
1823
val gtaKillErrors = _events.asSharedFlow()
1924

2025
suspend fun killGta() {
@@ -31,11 +36,15 @@ suspend fun killGta() {
3136

3237
if (settings.autostartGta) {
3338
LOG.info { "Restarting GTA5.exe" }
34-
val gtaPath = WindowsAPI.readGtaLocation(version) / version.startBinary
35-
Runtime.getRuntime().exec(arrayOf(gtaPath.absolutePathString()))
39+
try {
40+
val gtaPath = WindowsAPI.readGtaLocation(version) / version.startBinary
41+
Runtime.getRuntime().exec(arrayOf(gtaPath.absolutePathString()))
42+
} catch (e: Exception) {
43+
_events.emit(Event.RestartError(e))
44+
}
3645
}
3746
} else {
3847
LOG.error { "GTA5.exe not found" }
39-
_events.emit(Unit)
48+
_events.emit(Event.GtaProcessNotFound)
4049
}
4150
}

client/src/main/kotlin/ui/GTAKiller.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import androidx.navigation.compose.NavHost
2121
import androidx.navigation.compose.composable
2222
import androidx.navigation.compose.rememberNavController
2323
import dev.schlaubi.gtakiller.common.KillGtaEvent
24+
import dev.schlaubi.mastermind.core.Event
2425
import dev.schlaubi.mastermind.core.currentApi
2526
import dev.schlaubi.mastermind.core.gtaKillErrors
2627
import dev.schlaubi.mastermind.core.settings.settings
@@ -51,7 +52,11 @@ fun GTAKiller() {
5152
LaunchedEffect(Unit) {
5253
gtaKillErrors
5354
.collect {
54-
snackbarHostState.showSnackbar("GTA5.exe is not running", withDismissAction = true)
55+
val message = when (it) {
56+
Event.GtaProcessNotFound -> "GTA5.exe is not running"
57+
is Event.RestartError -> it.exception.message ?: "An unknown error occurred"
58+
}
59+
snackbarHostState.showSnackbar(message, withDismissAction = true)
5560
}
5661
}
5762

client/src/main/kotlin/ui/ServerSelector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,6 @@ private fun String.parseUrl(): Url {
165165
return if ("://" in url) {
166166
Url(url)
167167
} else {
168-
Url("wss://$url")
168+
Url("https://$url")
169169
}
170170
}

0 commit comments

Comments
 (0)