diff --git a/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java b/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java index e378acdd..ce76cc08 100644 --- a/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java +++ b/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java @@ -138,22 +138,23 @@ public abstract class OperationMode { set(newMode); } - public static void switchToSyncIfPossible(OperationMode newMode) { + public static boolean switchToSyncIfPossible(OperationMode newMode) { TrackEvent.info("Attempting to switch mode to " + newMode.getId()); if (newMode.equals(TRAY) && !TRAY.isSupported()) { TrackEvent.info("Tray is not available, using base instead"); set(BACKGROUND); - return; + return false; } if (newMode.equals(GUI) && !GUI.isSupported()) { TrackEvent.info("Gui is not available, using base instead"); set(BACKGROUND); - return; + return false; } set(newMode); + return true; } diff --git a/app/src/main/java/io/xpipe/app/exchange/OpenExchangeImpl.java b/app/src/main/java/io/xpipe/app/exchange/OpenExchangeImpl.java index 7d6534c4..3a9730a0 100644 --- a/app/src/main/java/io/xpipe/app/exchange/OpenExchangeImpl.java +++ b/app/src/main/java/io/xpipe/app/exchange/OpenExchangeImpl.java @@ -2,16 +2,20 @@ package io.xpipe.app.exchange; import io.xpipe.app.core.mode.OperationMode; import io.xpipe.app.launcher.LauncherInput; +import io.xpipe.app.util.PlatformState; import io.xpipe.beacon.BeaconHandler; +import io.xpipe.beacon.ServerException; import io.xpipe.beacon.exchange.OpenExchange; public class OpenExchangeImpl extends OpenExchange implements MessageExchangeImpl { @Override - public Response handleRequest(BeaconHandler handler, Request msg) { + public Response handleRequest(BeaconHandler handler, Request msg) throws ServerException { if (msg.getArguments().isEmpty()) { - OperationMode.switchToAsync(OperationMode.GUI); + if (!OperationMode.switchToSyncIfPossible(OperationMode.GUI)) { + throw new ServerException(PlatformState.getLastError()); + } } LauncherInput.handle(msg.getArguments()); diff --git a/app/src/main/java/io/xpipe/app/util/PlatformState.java b/app/src/main/java/io/xpipe/app/util/PlatformState.java index eac0951e..1c6ce42c 100644 --- a/app/src/main/java/io/xpipe/app/util/PlatformState.java +++ b/app/src/main/java/io/xpipe/app/util/PlatformState.java @@ -69,10 +69,11 @@ public enum PlatformState { try { // Weird fix to ensure that macOS quit operation works while in tray. // Maybe related to https://bugs.openjdk.org/browse/JDK-8318129 as it prints the same error if not called - // The headless is not needed though but still done + // The headless check is not needed though but still done GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); } catch (HeadlessException e) { TrackEvent.warn(e.getMessage()); + PlatformState.setCurrent(PlatformState.EXITED); return Optional.of(e); }