From a24804e9a39d19e05855c50fc77ff5c2af0caf16 Mon Sep 17 00:00:00 2001 From: crschnick Date: Fri, 19 Dec 2025 14:56:37 +0000 Subject: [PATCH] Rework beacon auth file --- .../java/io/xpipe/app/beacon/AppBeaconServer.java | 3 +++ .../main/java/io/xpipe/app/process/ShellTemp.java | 12 +++++++----- .../app/terminal/ZellijTerminalMultiplexer.java | 3 ++- .../src/main/java/io/xpipe/beacon/BeaconConfig.java | 9 ++++++++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/beacon/AppBeaconServer.java b/app/src/main/java/io/xpipe/app/beacon/AppBeaconServer.java index c5be488e2..b505495a1 100644 --- a/app/src/main/java/io/xpipe/app/beacon/AppBeaconServer.java +++ b/app/src/main/java/io/xpipe/app/beacon/AppBeaconServer.java @@ -3,6 +3,7 @@ package io.xpipe.app.beacon; import io.xpipe.app.beacon.mcp.AppMcpServer; import io.xpipe.app.issue.ErrorEventFactory; import io.xpipe.app.issue.TrackEvent; +import io.xpipe.app.process.ShellTemp; import io.xpipe.app.util.DocumentationLink; import io.xpipe.beacon.BeaconConfig; import io.xpipe.beacon.BeaconInterface; @@ -120,6 +121,8 @@ public class AppBeaconServer { } private void initAuthSecret() throws IOException { + // Create temp dir and permissions for Linux + ShellTemp.getLocalTempDataDirectory(null); var file = BeaconConfig.getLocalBeaconAuthFile(); var id = UUID.randomUUID().toString(); Files.writeString(file, id); diff --git a/app/src/main/java/io/xpipe/app/process/ShellTemp.java b/app/src/main/java/io/xpipe/app/process/ShellTemp.java index bb14eb1ce..c10387109 100644 --- a/app/src/main/java/io/xpipe/app/process/ShellTemp.java +++ b/app/src/main/java/io/xpipe/app/process/ShellTemp.java @@ -1,5 +1,7 @@ package io.xpipe.app.process; +import io.xpipe.app.core.AppInstallation; +import io.xpipe.app.core.AppNames; import io.xpipe.app.core.AppProperties; import io.xpipe.app.core.AppSystemInfo; import io.xpipe.app.issue.ErrorEventFactory; @@ -16,7 +18,7 @@ import java.nio.file.attribute.PosixFilePermissions; public class ShellTemp { public static Path getLocalTempDataDirectory(String sub) { - var temp = AppSystemInfo.ofCurrent().getTemp().resolve("xpipe"); + var temp = AppSystemInfo.ofCurrent().getTemp().resolve(AppNames.ofCurrent().getKebapName()); // On Windows and macOS, we already have user specific temp directories // Even on macOS as root we will have a unique directory (in contrast to shell controls) if (OsType.ofLocal() == OsType.LINUX) { @@ -27,8 +29,8 @@ public class ShellTemp { ErrorEventFactory.fromThrowable(e).omit().expected().handle(); } - var user = System.getenv("USER"); - temp = temp.resolve(user != null ? user : "user"); + var user = AppSystemInfo.ofCurrent().getUser(); + temp = temp.resolve(user); } return sub != null ? temp.resolve(sub) : temp; @@ -40,7 +42,7 @@ public class ShellTemp { // Even on macOS as root it is technically unique as only root will use /tmp if (proc.getOsType() != OsType.WINDOWS && proc.getOsType() != OsType.MACOS) { var temp = proc.getSystemTemporaryDirectory(); - base = temp.join("xpipe"); + base = temp.join(AppNames.ofCurrent().getKebapName()); proc.view().mkdir(base); // We have to make sure that also other users can create files here // This command should work in all shells @@ -50,7 +52,7 @@ public class ShellTemp { base = base.join(user); } else { var temp = proc.getSystemTemporaryDirectory(); - base = temp.join("xpipe"); + base = temp.join(AppNames.ofCurrent().getKebapName()); } return sub != null ? base.join(sub) : base; } diff --git a/app/src/main/java/io/xpipe/app/terminal/ZellijTerminalMultiplexer.java b/app/src/main/java/io/xpipe/app/terminal/ZellijTerminalMultiplexer.java index 5a212d670..c09fe3c0f 100644 --- a/app/src/main/java/io/xpipe/app/terminal/ZellijTerminalMultiplexer.java +++ b/app/src/main/java/io/xpipe/app/terminal/ZellijTerminalMultiplexer.java @@ -81,7 +81,8 @@ public class ZellijTerminalMultiplexer implements TerminalMultiplexer { "zellij -s xpipe action write-chars -- " + escape(" " + firstCommand, true, true) + "\\;exit", "zellij -s xpipe action write 10", "zellij -s xpipe action clear", - "zellij -s xpipe action rename-tab \"" + escape(config.getColoredTitle(), false, true) + "\"", + "zellij -s xpipe action rename-tab \"" + escape(config.getColoredTitle(), false, true) + "\"", + "sleep 0.5", "zellij -s xpipe action go-to-previous-tab", "zellij -s xpipe action close-tab")); diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java b/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java index fc20e2dbb..a251ce63c 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java @@ -1,5 +1,6 @@ package io.xpipe.beacon; +import io.xpipe.core.OsType; import lombok.experimental.UtilityClass; import java.nio.file.Path; @@ -55,6 +56,12 @@ public class BeaconConfig { var staging = Optional.ofNullable(System.getProperty("io.xpipe.app.staging")) .map(Boolean::parseBoolean) .orElse(false); - return Path.of(System.getProperty("java.io.tmpdir"), staging ? "xpipe_ptb_auth" : "xpipe_auth"); + if (OsType.ofLocal() == OsType.LINUX) { + return Path.of(System.getProperty("java.io.tmpdir"), staging ? "xpipe-ptb" : "xpipe", + System.getProperty("user.name"), "beacon-auth"); + } else { + return Path.of(System.getProperty("java.io.tmpdir"), staging ? "xpipe-ptb" : "xpipe", + "beacon-auth"); + } } }