From 771f7bd9f09fb26b94f7bc708e232f8492ae60be Mon Sep 17 00:00:00 2001 From: crschnick Date: Thu, 28 May 2026 00:35:35 +0000 Subject: [PATCH] Rework --- .../io/xpipe/app/beacon/BeaconInterface.java | 10 +-- .../xpipe/app/core/mode/AppOperationMode.java | 70 +++++++++---------- dist/jpackage.gradle | 14 ++-- 3 files changed, 45 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/beacon/BeaconInterface.java b/app/src/main/java/io/xpipe/app/beacon/BeaconInterface.java index 0331613ed..344a18b47 100644 --- a/app/src/main/java/io/xpipe/app/beacon/BeaconInterface.java +++ b/app/src/main/java/io/xpipe/app/beacon/BeaconInterface.java @@ -31,16 +31,14 @@ public abstract class BeaconInterface { @SuppressWarnings("unchecked") @SneakyThrows public Class getRequestClass() { - var c = getClass().getSuperclass(); - var name = (c.getSuperclass().equals(BeaconInterface.class) ? c : getClass()).getName() + "$Request"; + var name = getClass().getName() + "$Request"; return (Class) Class.forName(name); } @SuppressWarnings("unchecked") @SneakyThrows public Class getResponseClass() { - var c = getClass().getSuperclass(); - var name = (c.getSuperclass().equals(BeaconInterface.class) ? c : getClass()).getName() + "$Response"; + var name = getClass().getName() + "$Response"; return (Class) Class.forName(name); } @@ -83,10 +81,6 @@ public abstract class BeaconInterface { .map(ServiceLoader.Provider::get) .map(beaconInterface -> (BeaconInterface) beaconInterface) .collect(Collectors.toList()); - // Remove parent classes - ALL.removeIf(beaconInterface -> ALL.stream() - .anyMatch(other -> !other.equals(beaconInterface) - && beaconInterface.getClass().isAssignableFrom(other.getClass()))); } @Override diff --git a/app/src/main/java/io/xpipe/app/core/mode/AppOperationMode.java b/app/src/main/java/io/xpipe/app/core/mode/AppOperationMode.java index c9889a898..96b1e5d53 100644 --- a/app/src/main/java/io/xpipe/app/core/mode/AppOperationMode.java +++ b/app/src/main/java/io/xpipe/app/core/mode/AppOperationMode.java @@ -69,49 +69,49 @@ public abstract class AppOperationMode { private static void setup(String[] args) { try { - // Only for handling SIGTERM - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - externalShutdown(); - })); + if (AppProperties.get().isDaemon()) { + // Only for handling SIGTERM + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + externalShutdown(); + })); - // Handle uncaught exceptions - Thread.setDefaultUncaughtExceptionHandler((thread, ex) -> { - // It seems like a few exceptions are thrown in the quantum renderer - // when in shutdown. We can ignore these - if (AppOperationMode.isInShutdown() - && Platform.isFxApplicationThread() - && ex instanceof NullPointerException) { - return; - } + // Handle uncaught exceptions + Thread.setDefaultUncaughtExceptionHandler((thread, ex) -> { + // It seems like a few exceptions are thrown in the quantum renderer + // when in shutdown. We can ignore these + if (AppOperationMode.isInShutdown() && Platform.isFxApplicationThread() && ex instanceof NullPointerException) { + return; + } - // It seems like a few exceptions are thrown in the quantum renderer - // when the screen configuration changes - if (Platform.isFxApplicationThread() - && ex instanceof IllegalArgumentException - && ex.getStackTrace()[0].toString().contains("Rectangle2D")) { - return; - } + // It seems like a few exceptions are thrown in the quantum renderer + // when the screen configuration changes + if (Platform.isFxApplicationThread() && ex instanceof IllegalArgumentException && ex.getStackTrace()[0].toString().contains( + "Rectangle2D")) { + return; + } - // Some random AWT errors are thrown sometimes - if (ex instanceof AWTError) { - return; - } + // Some random AWT errors are thrown sometimes + if (ex instanceof AWTError) { + return; + } - // Handle any startup uncaught errors - if (AppOperationMode.isInStartup() && thread.threadId() == 1) { - ex.printStackTrace(); - AppOperationMode.halt(1); - } + // Handle any startup uncaught errors + if (AppOperationMode.isInStartup() && thread.threadId() == 1) { + ex.printStackTrace(); + AppOperationMode.halt(1); + } - if (ex instanceof OutOfMemoryError) { - ex.printStackTrace(); - AppOperationMode.halt(1); - } + if (ex instanceof OutOfMemoryError) { + ex.printStackTrace(); + AppOperationMode.halt(1); + } - ErrorEventFactory.fromThrowable(ex).unhandled(true).build().handle(); - }); + ErrorEventFactory.fromThrowable(ex).unhandled(true).build().handle(); + }); + } AppProperties.init(args); + if (AppProperties.get().isCli()) { ModuleLayerLoader.loadAll(ModuleLayer.boot(), throwable -> throwable.printStackTrace()); var cli = CliProvider.get(); diff --git a/dist/jpackage.gradle b/dist/jpackage.gradle index e0e6fbc0b..018a92fb7 100644 --- a/dist/jpackage.gradle +++ b/dist/jpackage.gradle @@ -81,12 +81,14 @@ jlink { jvmArgs = jpackageReleaseDaemonArguments } - secondaryLauncher { - moduleName = packageName(null) - mainClass = packageName('Main') - name = "xpipe" - jvmArgs = jpackageReleaseCliArguments - winConsole = true + if (os.isWindows()) { + secondaryLauncher { + moduleName = packageName(null) + mainClass = packageName('Main') + name = "xpipe" + jvmArgs = jpackageReleaseCliArguments + winConsole = true + } } jpackage {