File tree Expand file tree Collapse file tree 3 files changed +20
-6
lines changed
Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,12 @@ import kotlin.time.Duration.Companion.seconds
1414
1515private 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 )
1823val gtaKillErrors = _events .asSharedFlow()
1924
2025suspend 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}
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import androidx.navigation.compose.NavHost
2121import androidx.navigation.compose.composable
2222import androidx.navigation.compose.rememberNavController
2323import dev.schlaubi.gtakiller.common.KillGtaEvent
24+ import dev.schlaubi.mastermind.core.Event
2425import dev.schlaubi.mastermind.core.currentApi
2526import dev.schlaubi.mastermind.core.gtaKillErrors
2627import 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments