diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java b/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java index 535170b5..d71907ac 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java @@ -30,7 +30,7 @@ public class BeaconConfig { public static final String BEACON_PORT_PROP = "io.xpipe.beacon.port"; - public static final int DEFAULT_PORT = 21721; + public static final int DEFAULT_PORT = System.getProperty("os.name").startsWith("Windows") ? 21721 : 21722; public static int getUsedPort() { if (System.getProperty(BEACON_PORT_PROP) != null) { diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java index dbc902c3..1391f59a 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java @@ -6,8 +6,6 @@ import lombok.experimental.UtilityClass; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.net.DatagramSocket; -import java.net.ServerSocket; import java.nio.file.Files; import java.nio.file.Path; import java.util.Optional; @@ -18,19 +16,14 @@ import java.util.Optional; @UtilityClass public class BeaconServer { - private static boolean isPortAvailable(int port) { - try (var ignored = new ServerSocket(port); var ignored1 = new DatagramSocket(port)) { + public static boolean isRunning() { + try (var socket = new BeaconClient()) { return true; - } catch (IOException e) { + } catch (Exception e) { return false; } } - public static boolean isRunning() { - var port = BeaconConfig.getUsedPort(); - return !isPortAvailable(port); - } - private static void startFork(String custom) throws IOException { boolean print = BeaconConfig.execDebugEnabled(); if (print) { @@ -72,14 +65,17 @@ public class BeaconServer { }, "daemon fork syserr").start(); } - public static boolean tryStart() throws Exception { + public static boolean tryStartFork() throws Exception { var custom = BeaconConfig.getCustomExecCommand(); if (custom != null) { System.out.println("Starting fork: " + custom); startFork(custom); return true; } + return false; + } + public static boolean tryStart() throws Exception { var daemonExecutable = getDaemonExecutable(); if (daemonExecutable.isPresent()) { if (BeaconConfig.debugEnabled()) { @@ -99,7 +95,7 @@ public class BeaconServer { public static boolean tryStop(BeaconClient client) throws Exception { client.sendRequest(StopExchange.Request.builder().build()); - StopExchange.Response res =client.receiveResponse(); + StopExchange.Response res = client.receiveResponse(); return res.isSuccess(); } diff --git a/core/src/main/java/io/xpipe/core/source/RawReadConnection.java b/core/src/main/java/io/xpipe/core/source/RawReadConnection.java index a70dd146..fda54878 100644 --- a/core/src/main/java/io/xpipe/core/source/RawReadConnection.java +++ b/core/src/main/java/io/xpipe/core/source/RawReadConnection.java @@ -18,7 +18,6 @@ public interface RawReadConnection extends DataSourceReadConnection { default void forward(DataSourceConnection con) throws Exception { try (var tCon = (RawWriteConnection) con) { - tCon.init(); byte[] b; while ((b = readBytes(BUFFER_SIZE)).length > 0) { tCon.write(b); diff --git a/core/src/main/java/io/xpipe/core/source/StructureReadConnection.java b/core/src/main/java/io/xpipe/core/source/StructureReadConnection.java index fa1725fa..32c1edce 100644 --- a/core/src/main/java/io/xpipe/core/source/StructureReadConnection.java +++ b/core/src/main/java/io/xpipe/core/source/StructureReadConnection.java @@ -11,7 +11,6 @@ public interface StructureReadConnection extends DataSourceReadConnection { default void forward(DataSourceConnection con) throws Exception { try (var tCon = (StructureWriteConnection) con) { - tCon.init(); tCon.write(read()); } } diff --git a/core/src/main/java/io/xpipe/core/source/TextReadConnection.java b/core/src/main/java/io/xpipe/core/source/TextReadConnection.java index 7081cca2..8ee5a710 100644 --- a/core/src/main/java/io/xpipe/core/source/TextReadConnection.java +++ b/core/src/main/java/io/xpipe/core/source/TextReadConnection.java @@ -28,7 +28,6 @@ public interface TextReadConnection extends DataSourceReadConnection { default void forward(DataSourceConnection con) throws Exception { try (var tCon = (TextWriteConnection) con) { - tCon.init(); for (var it = lines().iterator(); it.hasNext(); ) { tCon.writeLine(it.next()); } diff --git a/extension/src/main/java/io/xpipe/extension/DataStoreProvider.java b/extension/src/main/java/io/xpipe/extension/DataStoreProvider.java index 83dead53..380f5b12 100644 --- a/extension/src/main/java/io/xpipe/extension/DataStoreProvider.java +++ b/extension/src/main/java/io/xpipe/extension/DataStoreProvider.java @@ -78,9 +78,7 @@ public interface DataStoreProvider { return null; } - default DataStore defaultStore() { - throw new ExtensionException("CLI Dialog not implemented by provider"); - } + DataStore defaultStore(); default String display(DataStore store) { return store.toSummaryString();