From 78a51f5f529d07bdf5eaeba158823f1559326caa Mon Sep 17 00:00:00 2001 From: crschnick Date: Tue, 2 May 2023 18:55:35 +0000 Subject: [PATCH] Renames --- .../io/xpipe/app/browser/FileContextMenu.java | 6 +- .../xpipe/app/browser/FileSystemHelper.java | 2 +- .../app/browser/OpenFileSystemModel.java | 2 +- .../app/comp/about/BrowseDirectoryComp.java | 2 +- .../java/io/xpipe/app/ext/ActionProvider.java | 2 +- .../io/xpipe/app/launcher/LauncherInput.java | 6 +- .../app/prefs/ExternalApplicationType.java | 2 +- .../xpipe/app/prefs/ExternalTerminalType.java | 2 +- .../io/xpipe/app/update/AppInstaller.java | 8 +- .../io/xpipe/app/update/ChocoUpdater.java | 4 +- .../xpipe/app/update/XPipeInstanceHelper.java | 4 +- .../io/xpipe/app/util/ApplicationHelper.java | 2 +- .../io/xpipe/app/util/MacOsPermissions.java | 2 +- .../java/io/xpipe/beacon/BeaconClient.java | 2 +- .../java/io/xpipe/core/impl/LocalStore.java | 4 +- .../java/io/xpipe/core/process/OsType.java | 16 +-- .../io/xpipe/core/process/ShellControl.java | 8 +- .../xpipe/core/store/DelegateShellStore.java | 4 +- .../java/io/xpipe/core/store/ShellStore.java | 16 +-- .../io/xpipe/core/util/XPipeInstallation.java | 6 +- .../xpipe/core/util/XPipeTempDirectory.java | 4 +- .../ext/base/actions/AddStoreAction.java | 2 +- .../actions/DeleteStoreChildrenAction.java | 2 +- .../ext/base/actions/EditStoreAction.java | 2 +- .../ext/base/actions/FileBrowseAction.java | 2 +- .../ext/base/actions/FileEditAction.java | 2 +- .../xpipe/ext/base/actions/SampleAction.java | 120 ++++++++++++++++++ .../ext/base/actions/ShareStoreAction.java | 2 +- .../ext/base/actions/StreamExportAction.java | 2 +- 29 files changed, 179 insertions(+), 59 deletions(-) create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/actions/SampleAction.java diff --git a/app/src/main/java/io/xpipe/app/browser/FileContextMenu.java b/app/src/main/java/io/xpipe/app/browser/FileContextMenu.java index 037fc8fc4..39f27db4f 100644 --- a/app/src/main/java/io/xpipe/app/browser/FileContextMenu.java +++ b/app/src/main/java/io/xpipe/app/browser/FileContextMenu.java @@ -81,7 +81,7 @@ final class FileContextMenu extends ContextMenu { ShellControl pc = model.getFileSystem().getShell().orElseThrow(); var e = pc.getShellDialect().getMakeExecutableCommand(entry.getPath()); if (e != null) { - pc.executeBooleanSimpleCommand(e); + pc.executeSimpleBooleanCommand(e); } var cmd = pc.command("\"" + entry.getPath() + "\"").prepareTerminalOpen(); TerminalHelper.open(FilenameUtils.getBaseName(entry.getPath()), cmd); @@ -96,10 +96,10 @@ final class FileContextMenu extends ContextMenu { ShellControl pc = model.getFileSystem().getShell().orElseThrow(); var e = pc.getShellDialect().getMakeExecutableCommand(entry.getPath()); if (e != null) { - pc.executeBooleanSimpleCommand(e); + pc.executeSimpleBooleanCommand(e); } var cmd = ScriptHelper.createDetachCommand(pc, "\"" + entry.getPath() + "\""); - pc.executeBooleanSimpleCommand(cmd); + pc.executeSimpleBooleanCommand(cmd); }); event.consume(); }); diff --git a/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java b/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java index 9fd2bec85..bdf669923 100644 --- a/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java +++ b/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java @@ -24,7 +24,7 @@ public class FileSystemHelper { var current = !(model.getStore().getValue() instanceof LocalStore) ? fileSystem .getShellControl() - .executeStringSimpleCommand( + .executeSimpleStringCommand( fileSystem.getShellControl().getShellDialect().getPrintWorkingDirectoryCommand()) : fileSystem .getShell() diff --git a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java index 26bdc8b95..c32b82c98 100644 --- a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java +++ b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java @@ -275,7 +275,7 @@ final class OpenFileSystemModel { BusyProperty.execute(busy, () -> { if (store.getValue() instanceof ShellStore s) { var connection = ((ConnectionFileSystem) fileSystem).getShellControl(); - var command = s.create() + var command = s.control() .initWith(connection.getShellDialect().getCdCommand(directory)) .prepareTerminalOpen(); TerminalHelper.open(directory, command); diff --git a/app/src/main/java/io/xpipe/app/comp/about/BrowseDirectoryComp.java b/app/src/main/java/io/xpipe/app/comp/about/BrowseDirectoryComp.java index c64d465bb..91e8fb68e 100644 --- a/app/src/main/java/io/xpipe/app/comp/about/BrowseDirectoryComp.java +++ b/app/src/main/java/io/xpipe/app/comp/about/BrowseDirectoryComp.java @@ -44,7 +44,7 @@ public class BrowseDirectoryComp extends SimpleComp { "launchDebugMode", new ButtonComp(AppI18n.observable("launchDebugMode"), () -> { OperationMode.executeAfterShutdown(() -> { - try (var sc = ShellStore.createLocal().create().start()) { + try (var sc = ShellStore.createLocal().control().start()) { var script = FileNames.join( XPipeInstallation.getCurrentInstallationBasePath() .toString(), diff --git a/app/src/main/java/io/xpipe/app/ext/ActionProvider.java b/app/src/main/java/io/xpipe/app/ext/ActionProvider.java index c20f79a25..399215a8b 100644 --- a/app/src/main/java/io/xpipe/app/ext/ActionProvider.java +++ b/app/src/main/java/io/xpipe/app/ext/ActionProvider.java @@ -45,7 +45,7 @@ public interface ActionProvider { interface Action { - boolean requiresPlatform(); + boolean requiresJavaFXPlatform(); void execute() throws Exception; } diff --git a/app/src/main/java/io/xpipe/app/launcher/LauncherInput.java b/app/src/main/java/io/xpipe/app/launcher/LauncherInput.java index 672adb343..258b376f9 100644 --- a/app/src/main/java/io/xpipe/app/launcher/LauncherInput.java +++ b/app/src/main/java/io/xpipe/app/launcher/LauncherInput.java @@ -31,14 +31,14 @@ public abstract class LauncherInput { } }); - var requiresPlatform = all.stream().anyMatch(launcherInput -> launcherInput.requiresPlatform()); + var requiresPlatform = all.stream().anyMatch(launcherInput -> launcherInput.requiresJavaFXPlatform()); if (requiresPlatform) { OperationMode.switchTo(OperationMode.GUI); } var hasGui = OperationMode.get() == OperationMode.GUI; all.forEach(launcherInput -> { - if (!hasGui && launcherInput.requiresPlatform()) { + if (!hasGui && launcherInput.requiresJavaFXPlatform()) { return; } @@ -118,7 +118,7 @@ public abstract class LauncherInput { } @Override - public boolean requiresPlatform() { + public boolean requiresJavaFXPlatform() { return true; } } diff --git a/app/src/main/java/io/xpipe/app/prefs/ExternalApplicationType.java b/app/src/main/java/io/xpipe/app/prefs/ExternalApplicationType.java index 2392b42a3..dbac96cd6 100644 --- a/app/src/main/java/io/xpipe/app/prefs/ExternalApplicationType.java +++ b/app/src/main/java/io/xpipe/app/prefs/ExternalApplicationType.java @@ -77,7 +77,7 @@ public abstract class ExternalApplicationType implements PrefsChoiceValue { public boolean isAvailable() { try (ShellControl pc = LocalStore.getShell()) { - return pc.executeBooleanSimpleCommand(pc.getShellDialect().getWhichCommand(executable)); + return pc.executeSimpleBooleanCommand(pc.getShellDialect().getWhichCommand(executable)); } catch (Exception e) { ErrorEvent.fromThrowable(e).omit().handle(); return false; diff --git a/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java b/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java index 0e2a6274e..cef5b4ba6 100644 --- a/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java +++ b/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java @@ -332,7 +332,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue { public boolean isAvailable() { try (ShellControl pc = LocalStore.getShell()) { - return pc.executeBooleanSimpleCommand(pc.getShellDialect().getWhichCommand(executable)); + return pc.executeSimpleBooleanCommand(pc.getShellDialect().getWhichCommand(executable)); } catch (Exception e) { ErrorEvent.fromThrowable(e).omit().handle(); return false; diff --git a/app/src/main/java/io/xpipe/app/update/AppInstaller.java b/app/src/main/java/io/xpipe/app/update/AppInstaller.java index 1bd232aa3..a4ecd37a5 100644 --- a/app/src/main/java/io/xpipe/app/update/AppInstaller.java +++ b/app/src/main/java/io/xpipe/app/update/AppInstaller.java @@ -141,7 +141,7 @@ public class AppInstaller { @Override public void installLocal(String file) throws Exception { - var shellProcessControl = ShellStore.createLocal().create().start(); + var shellProcessControl = ShellStore.createLocal().control().start(); var exec = XPipeInstallation.getInstallationExecutable( shellProcessControl, XPipeInstallation.getDefaultInstallationBasePath(shellProcessControl, false)); @@ -187,7 +187,7 @@ public class AppInstaller { @Override public void installLocal(String file) throws Exception { var command = ShellStore.createLocal() - .create() + .control() .subShell(ShellDialects.BASH) .command(String.format( """ @@ -228,7 +228,7 @@ public class AppInstaller { @Override public void installLocal(String file) throws Exception { - var command = ShellStore.createLocal().create().subShell(ShellDialects.BASH).command(String.format( + var command = ShellStore.createLocal().control().subShell(ShellDialects.BASH).command(String.format( """ function exec { echo "+ sudo rpm -U -v --force \\"%s\\"" @@ -266,7 +266,7 @@ public class AppInstaller { @Override public void installLocal(String file) throws Exception { - var command = ShellStore.createLocal().create().subShell(ShellDialects.BASH).command(String.format( + var command = ShellStore.createLocal().control().subShell(ShellDialects.BASH).command(String.format( """ function exec { echo "+ sudo installer -verboseR -allowUntrusted -pkg \\"%s\\" -target /" diff --git a/app/src/main/java/io/xpipe/app/update/ChocoUpdater.java b/app/src/main/java/io/xpipe/app/update/ChocoUpdater.java index 46e8748de..082dcf424 100644 --- a/app/src/main/java/io/xpipe/app/update/ChocoUpdater.java +++ b/app/src/main/java/io/xpipe/app/update/ChocoUpdater.java @@ -30,8 +30,8 @@ public class ChocoUpdater extends UpdateHandler { } public AvailableRelease refreshUpdateCheckImpl() throws Exception { - try (var sc = ShellStore.createLocal().create().start()) { - var latest = sc.executeStringSimpleCommand( + try (var sc = ShellStore.createLocal().control().start()) { + var latest = sc.executeSimpleStringCommand( "choco outdated -r --nocolor").lines().filter(s -> s.startsWith("xpipe")).findAny().orElseThrow().split("\\|")[2]; var isUpdate = isUpdate(latest); var rel = new AvailableRelease( diff --git a/app/src/main/java/io/xpipe/app/update/XPipeInstanceHelper.java b/app/src/main/java/io/xpipe/app/update/XPipeInstanceHelper.java index fbc2fccc9..b992ead25 100644 --- a/app/src/main/java/io/xpipe/app/update/XPipeInstanceHelper.java +++ b/app/src/main/java/io/xpipe/app/update/XPipeInstanceHelper.java @@ -35,8 +35,8 @@ public class XPipeInstanceHelper { } public static boolean isSupported(ShellStore host) { - try (var pc = host.create().start(); - var cmd = pc.command(List.of("xpipe"))) { + try (var pc = host.control().start(); + var cmd = pc.command(List.of("xpipe"))) { cmd.discardOrThrow(); return true; } catch (Exception e) { diff --git a/app/src/main/java/io/xpipe/app/util/ApplicationHelper.java b/app/src/main/java/io/xpipe/app/util/ApplicationHelper.java index c5e7817c5..ebe572adf 100644 --- a/app/src/main/java/io/xpipe/app/util/ApplicationHelper.java +++ b/app/src/main/java/io/xpipe/app/util/ApplicationHelper.java @@ -23,7 +23,7 @@ public class ApplicationHelper { } public static boolean isInPath(ShellControl processControl, String executable) throws Exception { - return processControl.executeBooleanSimpleCommand( + return processControl.executeSimpleBooleanCommand( processControl.getShellDialect().getWhichCommand(executable)); } diff --git a/app/src/main/java/io/xpipe/app/util/MacOsPermissions.java b/app/src/main/java/io/xpipe/app/util/MacOsPermissions.java index 43fe6e269..937ba6737 100644 --- a/app/src/main/java/io/xpipe/app/util/MacOsPermissions.java +++ b/app/src/main/java/io/xpipe/app/util/MacOsPermissions.java @@ -17,7 +17,7 @@ public class MacOsPermissions { var state = new SimpleBooleanProperty(true); try (var pc = LocalStore.getShell().start()) { while (state.get()) { - var success = pc.executeBooleanSimpleCommand( + var success = pc.executeSimpleBooleanCommand( "osascript -e 'tell application \"System Events\" to keystroke \"t\"'"); if (success) { Platform.runLater(() -> { diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java b/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java index 8d76e6297..3f2d2316a 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java @@ -53,7 +53,7 @@ public class BeaconClient implements AutoCloseable { } public static BeaconClient connectProxy(ShellStore proxy) throws Exception { - var control = proxy.create().start(); + var control = proxy.control().start(); if (!ProxyManagerProvider.get().setup(control)) { throw new IOException("X-Pipe connector required to perform operation"); } diff --git a/core/src/main/java/io/xpipe/core/impl/LocalStore.java b/core/src/main/java/io/xpipe/core/impl/LocalStore.java index dfcc3bc58..0b54f98ed 100644 --- a/core/src/main/java/io/xpipe/core/impl/LocalStore.java +++ b/core/src/main/java/io/xpipe/core/impl/LocalStore.java @@ -36,7 +36,7 @@ public class LocalStore extends JacksonizedValue implements ShellStore { @Override public FileSystem createFileSystem() { - return new ConnectionFileSystem(ShellStore.createLocal().create(), LocalStore.this) { + return new ConnectionFileSystem(ShellStore.createLocal().control(), LocalStore.this) { @Override public FileSystemStore getStore() { @@ -128,7 +128,7 @@ public class LocalStore extends JacksonizedValue implements ShellStore { } @Override - public ShellControl createControl() { + public ShellControl createBasicControl() { return ProcessControlProvider.createLocal(true); } } diff --git a/core/src/main/java/io/xpipe/core/process/OsType.java b/core/src/main/java/io/xpipe/core/process/OsType.java index 02343b02b..f58c3e67b 100644 --- a/core/src/main/java/io/xpipe/core/process/OsType.java +++ b/core/src/main/java/io/xpipe/core/process/OsType.java @@ -37,7 +37,7 @@ public interface OsType { @Override public String getHomeDirectory(ShellControl pc) throws Exception { - return pc.executeStringSimpleCommand( + return pc.executeSimpleStringCommand( pc.getShellDialect().getPrintEnvironmentVariableCommand("USERPROFILE")); } @@ -48,7 +48,7 @@ public interface OsType { @Override public String getTempDirectory(ShellControl pc) throws Exception { - return pc.executeStringSimpleCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("TEMP")); + return pc.executeSimpleStringCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("TEMP")); } @Override @@ -62,13 +62,13 @@ public interface OsType { @Override public String determineOperatingSystemName(ShellControl pc) throws Exception { try { - return pc.executeStringSimpleCommand("wmic os get Caption") + return pc.executeSimpleStringCommand("wmic os get Caption") .lines() .skip(1) .collect(Collectors.joining()) .trim() + " " - + pc.executeStringSimpleCommand("wmic os get Version") + + pc.executeSimpleStringCommand("wmic os get Version") .lines() .skip(1) .collect(Collectors.joining()) @@ -84,7 +84,7 @@ public interface OsType { @Override public String getHomeDirectory(ShellControl pc) throws Exception { - return pc.executeStringSimpleCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("HOME")); + return pc.executeSimpleStringCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("HOME")); } @Override @@ -142,12 +142,12 @@ public interface OsType { @Override public String getHomeDirectory(ShellControl pc) throws Exception { - return pc.executeStringSimpleCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("HOME")); + return pc.executeSimpleStringCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("HOME")); } @Override public String getTempDirectory(ShellControl pc) throws Exception { - var found = pc.executeStringSimpleCommand(pc.getShellDialect().getPrintVariableCommand("TMPDIR")); + var found = pc.executeSimpleStringCommand(pc.getShellDialect().getPrintVariableCommand("TMPDIR")); // This variable is not defined for root users, so manually fix it. Why? ... if (found.isBlank()) { @@ -174,7 +174,7 @@ public interface OsType { @Override public String determineOperatingSystemName(ShellControl pc) throws Exception { var properties = getProperties(pc); - var name = pc.executeStringSimpleCommand( + var name = pc.executeSimpleStringCommand( "awk '/SOFTWARE LICENSE AGREEMENT FOR macOS/' '/System/Library/CoreServices/Setup " + "Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf' | " + "awk -F 'macOS ' '{print $NF}' | awk '{print substr($0, 0, length($0)-1)}'"); diff --git a/core/src/main/java/io/xpipe/core/process/ShellControl.java b/core/src/main/java/io/xpipe/core/process/ShellControl.java index caf278d3f..3e29618e1 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellControl.java +++ b/core/src/main/java/io/xpipe/core/process/ShellControl.java @@ -29,13 +29,13 @@ public interface ShellControl extends ProcessControl { public void checkRunning() throws Exception; - default String executeStringSimpleCommand(String command) throws Exception { + default String executeSimpleStringCommand(String command) throws Exception { try (CommandControl c = command(command).start()) { return c.readOrThrow(); } } - default boolean executeBooleanSimpleCommand(String command) throws Exception { + default boolean executeSimpleBooleanCommand(String command) throws Exception { try (CommandControl c = command(command).start()) { return c.discardAndCheckExit(); } @@ -55,9 +55,9 @@ public interface ShellControl extends ProcessControl { } } - default String executeStringSimpleCommand(ShellDialect type, String command) throws Exception { + default String executeSimpleStringCommand(ShellDialect type, String command) throws Exception { try (var sub = subShell(type).start()) { - return sub.executeStringSimpleCommand(command); + return sub.executeSimpleStringCommand(command); } } diff --git a/core/src/main/java/io/xpipe/core/store/DelegateShellStore.java b/core/src/main/java/io/xpipe/core/store/DelegateShellStore.java index e42aebb9b..555916b37 100644 --- a/core/src/main/java/io/xpipe/core/store/DelegateShellStore.java +++ b/core/src/main/java/io/xpipe/core/store/DelegateShellStore.java @@ -5,8 +5,8 @@ import io.xpipe.core.process.ShellControl; public interface DelegateShellStore extends ShellStore { @Override - default ShellControl createControl() { - return getDelegateHost().create(); + default ShellControl createBasicControl() { + return getDelegateHost().control(); } ShellStore getDelegateHost(); diff --git a/core/src/main/java/io/xpipe/core/store/ShellStore.java b/core/src/main/java/io/xpipe/core/store/ShellStore.java index f7cf02267..cf595c3b4 100644 --- a/core/src/main/java/io/xpipe/core/store/ShellStore.java +++ b/core/src/main/java/io/xpipe/core/store/ShellStore.java @@ -19,16 +19,16 @@ public interface ShellStore extends DataStore, StatefulDataStore, LaunchableStor @Override default FileSystem createFileSystem() { - return new ConnectionFileSystem(create(), this); + return new ConnectionFileSystem(control(), this); } @Override default String prepareLaunchCommand() throws Exception { - return create().prepareTerminalOpen(); + return control().prepareTerminalOpen(); } - default ShellControl create() { - var pc = createControl(); + default ShellControl control() { + var pc = createBasicControl(); pc.onInit(processControl -> { setState("type", processControl.getShellDialect()); setState("os", processControl.getOsType()); @@ -49,21 +49,21 @@ public interface ShellStore extends DataStore, StatefulDataStore, LaunchableStor return getState("charset", Charset.class, null); } - ShellControl createControl(); + ShellControl createBasicControl(); public default ShellDialect determineType() throws Exception { - try (var pc = create().start()) { + try (var pc = control().start()) { return pc.getShellDialect(); } } @Override default void validate() throws Exception { - try (ShellControl pc = create().start()) {} + try (ShellControl pc = control().start()) {} } public default String queryMachineName() throws Exception { - try (var pc = create().start()) { + try (var pc = control().start()) { var operatingSystem = pc.getOsType(); return operatingSystem.determineOperatingSystemName(pc); } diff --git a/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java b/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java index 28c34b58a..3e438ebdc 100644 --- a/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java +++ b/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java @@ -170,7 +170,7 @@ public class XPipeInstallation { public static String getDataBasePath(ShellControl p) throws Exception { if (p.getOsType().equals(OsType.WINDOWS)) { - var base = p.executeStringSimpleCommand(p.getShellDialect().getPrintVariableCommand("userprofile")); + var base = p.executeSimpleStringCommand(p.getShellDialect().getPrintVariableCommand("userprofile")); return FileNames.join(base, ".xpipe"); } else { return FileNames.join("~", ".xpipe"); @@ -222,7 +222,7 @@ public class XPipeInstallation { public static String getDefaultInstallationBasePath(ShellControl p, boolean acceptPortable) throws Exception { if (acceptPortable) { - var customHome = p.executeStringSimpleCommand(p.getShellDialect().getPrintVariableCommand("XPIPE_HOME")); + var customHome = p.executeSimpleStringCommand(p.getShellDialect().getPrintVariableCommand("XPIPE_HOME")); if (!customHome.isEmpty()) { return customHome; } @@ -230,7 +230,7 @@ public class XPipeInstallation { String path = null; if (p.getOsType().equals(OsType.WINDOWS)) { - var base = p.executeStringSimpleCommand(p.getShellDialect().getPrintVariableCommand("LOCALAPPDATA")); + var base = p.executeSimpleStringCommand(p.getShellDialect().getPrintVariableCommand("LOCALAPPDATA")); path = FileNames.join(base, "X-Pipe"); } else if (p.getOsType().equals(OsType.LINUX)) { path = "/opt/xpipe"; diff --git a/core/src/main/java/io/xpipe/core/util/XPipeTempDirectory.java b/core/src/main/java/io/xpipe/core/util/XPipeTempDirectory.java index f80e606db..55e2ef6fc 100644 --- a/core/src/main/java/io/xpipe/core/util/XPipeTempDirectory.java +++ b/core/src/main/java/io/xpipe/core/util/XPipeTempDirectory.java @@ -22,7 +22,7 @@ public class XPipeTempDirectory { "Unable to access or create temporary directory " + dir); if (proc.getOsType().equals(OsType.LINUX) || proc.getOsType().equals(OsType.MACOS)) { - proc.executeBooleanSimpleCommand("chmod 777 \"" + dir + "\""); + proc.executeSimpleBooleanCommand("chmod 777 \"" + dir + "\""); } } @@ -31,7 +31,7 @@ public class XPipeTempDirectory { public static void clearSubDirectory(ShellControl proc) throws Exception { var dir = getSubDirectory(proc); - if (!proc.executeBooleanSimpleCommand(proc.getShellDialect().getFileDeleteCommand(dir))) { + if (!proc.executeSimpleBooleanCommand(proc.getShellDialect().getFileDeleteCommand(dir))) { throw new IOException("Unable to delete temporary directory " + dir); } } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/actions/AddStoreAction.java b/ext/base/src/main/java/io/xpipe/ext/base/actions/AddStoreAction.java index 8d0c86f1a..4a6533e6a 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/actions/AddStoreAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/actions/AddStoreAction.java @@ -18,7 +18,7 @@ public class AddStoreAction implements ActionProvider { DataStore store; @Override - public boolean requiresPlatform() { + public boolean requiresJavaFXPlatform() { return true; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/actions/DeleteStoreChildrenAction.java b/ext/base/src/main/java/io/xpipe/ext/base/actions/DeleteStoreChildrenAction.java index 417ae5c6d..649c38541 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/actions/DeleteStoreChildrenAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/actions/DeleteStoreChildrenAction.java @@ -16,7 +16,7 @@ public class DeleteStoreChildrenAction implements ActionProvider { DataStoreEntry store; @Override - public boolean requiresPlatform() { + public boolean requiresJavaFXPlatform() { return false; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/actions/EditStoreAction.java b/ext/base/src/main/java/io/xpipe/ext/base/actions/EditStoreAction.java index 9423cfb05..cdbf6ea82 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/actions/EditStoreAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/actions/EditStoreAction.java @@ -17,7 +17,7 @@ public class EditStoreAction implements ActionProvider { DataStoreEntry store; @Override - public boolean requiresPlatform() { + public boolean requiresJavaFXPlatform() { return true; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/actions/FileBrowseAction.java b/ext/base/src/main/java/io/xpipe/ext/base/actions/FileBrowseAction.java index 8ef10a43e..678d718be 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/actions/FileBrowseAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/actions/FileBrowseAction.java @@ -19,7 +19,7 @@ public class FileBrowseAction implements ActionProvider { FileStore store; @Override - public boolean requiresPlatform() { + public boolean requiresJavaFXPlatform() { return false; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/actions/FileEditAction.java b/ext/base/src/main/java/io/xpipe/ext/base/actions/FileEditAction.java index 2195a8377..7c4db1417 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/actions/FileEditAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/actions/FileEditAction.java @@ -17,7 +17,7 @@ public class FileEditAction implements ActionProvider { FileStore store; @Override - public boolean requiresPlatform() { + public boolean requiresJavaFXPlatform() { return false; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/actions/SampleAction.java b/ext/base/src/main/java/io/xpipe/ext/base/actions/SampleAction.java new file mode 100644 index 000000000..f57696a5d --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/actions/SampleAction.java @@ -0,0 +1,120 @@ +package io.xpipe.ext.base.actions; + +import io.xpipe.app.core.AppI18n; +import io.xpipe.app.ext.ActionProvider; +import io.xpipe.app.storage.DataStorage; +import io.xpipe.app.storage.DataStoreEntry; +import io.xpipe.core.process.CommandControl; +import io.xpipe.core.process.ShellControl; +import io.xpipe.core.store.ShellStore; +import javafx.beans.value.ObservableValue; +import lombok.Value; + +import java.io.BufferedReader; +import java.io.InputStreamReader; + +public class SampleAction implements ActionProvider { + + @Value + static class Action implements ActionProvider.Action { + + DataStoreEntry entry; + + @Override + public boolean requiresJavaFXPlatform() { + // Do we require the JavaFX platform to be running? + return false; + } + + @Override + public void execute() throws Exception { + // Start a shell control from the shell connection store + try (ShellControl sc = ((ShellStore) entry.getStore()).control().start()) { + // Simple commands can be executed in one line + // The shell dialects also provide the proper command syntax for common commands like echo + String echoOut = + sc.executeSimpleStringCommand(sc.getShellDialect().getEchoCommand("hello!", false)); + + // You can also implement custom handling for more complex commands + try (CommandControl cc = sc.command("ls").start()) { + // Discard stderr + cc.discardErr(); + + // Read the stdout lines as a stream + BufferedReader reader = new BufferedReader(new InputStreamReader(cc.getStdout(), cc.getCharset())); + reader.lines().filter(s -> s != null).forEach(s -> { + System.out.println(s); + }); + + // Waits for command completion and returns exit code + if (cc.getExitCode() != 0) { + // Handle failure + } + } + + // Commands can also be more complex and span multiple lines. + // In this case, X-Pipe will internally write a command to a script file and then execute the script + try (CommandControl cc = sc.command( + """ + VAR = "value" + echo "$VAR" + """ + ).start()) { + var output = cc.readOrThrow(); + } + + // More customization options + // If the command should be run as root, the command will be executed with + // sudo and the optional sudo password automatically provided by X-Pipe. + // You can also set a custom working directory + try (CommandControl cc = sc.command("kill ").elevated().workingDirectory("/").start()) { + // Discard any output but throw an exception the exit code is not 0 + cc.discardOrThrow(); + } + + // Start a bash sub shell. Useful if the login shell is different + try (ShellControl bash = sc.subShell("bash").start()) { + // ... + } + } + } + } + + @Override + public DataStoreCallSite getDataStoreCallSite() { + // Call sites represent different ways of invoking the action. + // In this case, this represents a button that is shown for all stored shell connections. + return new DataStoreCallSite() { + + @Override + public Action createAction(ShellStore store) { + return new Action(DataStorage.get().getStoreEntry(store)); + } + + @Override + public Class getApplicableClass() { + // For which general type of connection store to make this action available. + return ShellStore.class; + } + + @Override + public boolean isApplicable(ShellStore o) throws Exception { + // Allows you to individually check whether this action should be available for the specific store. + // In this case it should only be available for remote shell connections, not local ones. + return !ShellStore.isLocal(o); + } + + @Override + public ObservableValue getName(ShellStore store) { + // The displayed name of the action, allows you to use translation keys. + return AppI18n.observable("installConnector"); + } + + @Override + public String getIcon(ShellStore store) { + // The ikonli icon of the button. + return "mdi2c-code-greater-than"; + } + }; + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/actions/ShareStoreAction.java b/ext/base/src/main/java/io/xpipe/ext/base/actions/ShareStoreAction.java index 143e8f471..a3eecb901 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/actions/ShareStoreAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/actions/ShareStoreAction.java @@ -21,7 +21,7 @@ public class ShareStoreAction implements ActionProvider { DataStore store; @Override - public boolean requiresPlatform() { + public boolean requiresJavaFXPlatform() { return false; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/actions/StreamExportAction.java b/ext/base/src/main/java/io/xpipe/ext/base/actions/StreamExportAction.java index 42e514f3e..903d0a30b 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/actions/StreamExportAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/actions/StreamExportAction.java @@ -22,7 +22,7 @@ public class StreamExportAction implements ActionProvider { StreamDataStore store; @Override - public boolean requiresPlatform() { + public boolean requiresJavaFXPlatform() { return true; }