Probably return error on cli open command

This commit is contained in:
crschnick 2024-01-11 21:12:28 +00:00
parent 68b4cb2fcc
commit 45d3d40c6f
3 changed files with 12 additions and 6 deletions

View file

@ -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;
}

View file

@ -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<OpenExchange.Request, OpenExchange.Response> {
@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());

View file

@ -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);
}