Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/src/main/java/app/gamenative/ui/PluviaMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app.gamenative.ui

import android.content.Context
import android.content.Intent
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
Expand Down Expand Up @@ -1096,6 +1097,10 @@ fun PluviaMain(
}
}

BackHandler(enabled = state.loadingDialogVisible && !SteamService.keepAlive) {
// TODO: Make prelaunch/loading operations cancellable so Back can exit safely.
}
Comment thread
xXJSONDeruloXx marked this conversation as resolved.

PluviaTheme(
isDark = when (state.appTheme) {
AppTheme.AUTO -> isSystemInDarkTheme()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2533,6 +2533,7 @@ private fun shiftXEnvironmentToContext(

return environment
}

private fun setupXEnvironment(
context: Context,
appId: String,
Expand All @@ -2550,6 +2551,8 @@ private fun setupXEnvironment(
onGameLaunchError: ((String) -> Unit)? = null,
navigateBack: () -> Unit,
): XEnvironment {
ProcessHelper.hardKillStaleWineProcesses()

val gameSource = ContainerUtils.extractGameSourceFromContainerId(appId)
val lc_all = container!!.lC_ALL
val imageFs = ImageFs.find(context)
Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/com/winlator/core/ProcessHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,51 @@ public static void terminateProcess(int pid) {
// Log.d("ProcessHelper", "Process terminated with pid: " + pid);
}

public static void killProcess(int pid) {
Process.sendSignal(pid, SIGKILL);
}

public static void terminateAllWineProcesses() {
for (String process : listRunningWineProcesses()) {
terminateProcess(Integer.parseInt(process));
}
}

public static void killAllWineProcesses() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have terminateAllWineProcesses is that not enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats the whole point, sigterm seems ignored in some cases, so sigkill is more aggressive which it needs to be on anything that remains in this state

for (String process : listRunningWineProcesses()) {
killProcess(Integer.parseInt(process));
}
Comment thread
xXJSONDeruloXx marked this conversation as resolved.
}

public static void hardKillStaleWineProcesses() throws InterruptedException {
long deadlineMs = System.currentTimeMillis() + 5000;
List<String> stalePids = listRunningWineProcesses();

if (stalePids.isEmpty()) {
return;
}

Log.w("ProcessHelper", String.format(
"Found %d stale Wine process(es) before launch; hard-killing: %s",
stalePids.size(), String.join(", ", stalePids)));

killAllWineProcesses();

List<String> remaining;
do {
Thread.sleep(100);
remaining = listRunningWineProcesses();
} while (!remaining.isEmpty() && System.currentTimeMillis() < deadlineMs);

if (!remaining.isEmpty()) {
Log.w("ProcessHelper", String.format(
"Wine processes still present after hard-kill: %s",
String.join(", ", remaining)));
throw new IllegalStateException(
"Wine processes still present after hard-kill attempt: " + String.join(", ", remaining));
}
}

public static void pauseAllWineProcesses() {
for (String process : listRunningWineProcesses()) {
suspendProcess(Integer.parseInt(process));
Expand Down
Loading