From adeed8012dad1231551f13d949533c5fd0f65f15 Mon Sep 17 00:00:00 2001 From: Lauri Niskanen Date: Fri, 3 Jan 2025 13:20:24 +0200 Subject: [PATCH] Properly handle expired restore token on Wayland The previous version just gets crashes on an exception from invalid restore token and doesn't request a new valid one. This version catches the exception and starts the screen cast with a new token. I'm not sure what the purpose of the 200 ms sleep is, so I left it similar to the previous version. --- .../org/dpsoftware/managers/PipelineManager.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/dpsoftware/managers/PipelineManager.java b/src/main/java/org/dpsoftware/managers/PipelineManager.java index b7e79fadd..c0a7be270 100644 --- a/src/main/java/org/dpsoftware/managers/PipelineManager.java +++ b/src/main/java/org/dpsoftware/managers/PipelineManager.java @@ -141,11 +141,18 @@ public static XdgStreamDetails getXdgStreamDetails() { showChooseDisplayAlert(); alertShown.set(true); } - screenCastIface.Start(receivedSessionHandle, "", Collections.emptyMap()); - CommonUtility.sleepMilliseconds(200); - if (NativeExecutor.isWayland() && restoreTokenMatch.get() == false && alertShown.get() == false) { - showChooseDisplayAlert(); + try { + screenCastIface.Start(receivedSessionHandle, "", Collections.emptyMap()); + } catch (org.freedesktop.dbus.exceptions.DBusExecutionException e) { + if (NativeExecutor.isWayland() && alertShown.get() == false) { + log.info("Screen cast restore token is invalid or expired. Requesting a new one."); + showChooseDisplayAlert(); + screenCastIface.Start(receivedSessionHandle, "", Collections.emptyMap()); + } else { + throw e; + } } + CommonUtility.sleepMilliseconds(200); var c = streamIdMaybe.thenApply(streamId -> { FileDescriptor fileDescriptor = screenCastIface.OpenPipeWireRemote(receivedSessionHandle, Collections.emptyMap()); // block until stream started before calling OpenPipeWireRemote return new XdgStreamDetails(streamId, fileDescriptor);