diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java index e48c7f4e1..e4c7f1507 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java @@ -116,7 +116,9 @@ public abstract class StoreEntryComp extends SimpleComp { var loading = LoadingOverlayComp.noProgress( Comp.of(() -> button), - wrapper.getBusy().or(wrapper.getEntry().getProvider().busy(wrapper))); + wrapper.getEntry().getValidity().isUsable() ? + wrapper.getBusy().or(wrapper.getEntry().getProvider().busy(wrapper)): + wrapper.getBusy()); return loading.createRegion(); } diff --git a/core/src/main/java/io/xpipe/core/process/CommandControl.java b/core/src/main/java/io/xpipe/core/process/CommandControl.java index 37f4fba08..5192e1ca2 100644 --- a/core/src/main/java/io/xpipe/core/process/CommandControl.java +++ b/core/src/main/java/io/xpipe/core/process/CommandControl.java @@ -1,7 +1,6 @@ package io.xpipe.core.process; import io.xpipe.core.util.FailableConsumer; -import io.xpipe.core.util.FailableFunction; import java.io.InputStream; import java.io.InputStreamReader; @@ -64,11 +63,7 @@ public interface CommandControl extends ProcessControl { long getExitCode(); - default CommandControl elevated(String message) { - return elevated(message, (v) -> true); - } - - CommandControl elevated(String message, FailableFunction elevationFunction); + CommandControl elevated(ElevationFunction function); void withStdoutOrThrow(FailableConsumer c); diff --git a/core/src/main/java/io/xpipe/core/process/ElevationConfig.java b/core/src/main/java/io/xpipe/core/process/ElevationConfig.java deleted file mode 100644 index 72874c089..000000000 --- a/core/src/main/java/io/xpipe/core/process/ElevationConfig.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.xpipe.core.process; - -import lombok.Value; - -@Value -public class ElevationConfig { - - boolean requiresPassword; -} diff --git a/core/src/main/java/io/xpipe/core/process/ElevationFunction.java b/core/src/main/java/io/xpipe/core/process/ElevationFunction.java new file mode 100644 index 000000000..ff1398405 --- /dev/null +++ b/core/src/main/java/io/xpipe/core/process/ElevationFunction.java @@ -0,0 +1,69 @@ +package io.xpipe.core.process; + +import io.xpipe.core.util.FailableFunction; + +public interface ElevationFunction { + + static ElevationFunction of(String prefix, FailableFunction f) { + return new ElevationFunction() { + @Override + public String getPrefix() { + return prefix; + } + + @Override + public boolean isSpecified() { + return true; + } + + @Override + public boolean apply(ShellControl shellControl) throws Exception { + return f.apply(shellControl); + } + }; + } + + static ElevationFunction elevated(String prefix) { + return new ElevationFunction() { + @Override + public String getPrefix() { + return prefix; + } + + @Override + public boolean isSpecified() { + return true; + } + + @Override + public boolean apply(ShellControl shellControl) { + return true; + } + }; + } + + static ElevationFunction none() { + return new ElevationFunction() { + @Override + public String getPrefix() { + return null; + } + + @Override + public boolean isSpecified() { + return false; + } + + @Override + public boolean apply(ShellControl shellControl) { + return false; + } + }; + } + + String getPrefix(); + + boolean isSpecified(); + + boolean apply(ShellControl shellControl) throws Exception; +} 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 72b702fa2..4220acbe7 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellControl.java +++ b/core/src/main/java/io/xpipe/core/process/ShellControl.java @@ -171,7 +171,7 @@ public interface ShellControl extends ProcessControl { OsType.Any getOsType(); - ShellControl elevated(String message, FailableFunction elevationFunction); + ShellControl elevated(ElevationFunction elevationFunction); ShellControl withInitSnippet(ScriptSnippet snippet); diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/SampleAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/SampleAction.java index 7ee0bb28e..5fd353080 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/SampleAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/SampleAction.java @@ -5,6 +5,7 @@ import io.xpipe.app.ext.ActionProvider; import io.xpipe.app.storage.DataStoreEntry; import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.core.process.CommandControl; +import io.xpipe.core.process.ElevationFunction; import io.xpipe.core.process.ShellControl; import io.xpipe.core.process.ShellDialects; import io.xpipe.core.store.LocalStore; @@ -125,7 +126,7 @@ public class SampleAction implements ActionProvider { // by using the information from the connection store. // You can also set a custom working directory. try (CommandControl cc = sc.command("kill ") - .elevated("kill") + .elevated(ElevationFunction.elevated("kill")) .withWorkingDirectory("/") .start()) { // Discard any output but throw an exception with the stderr contents if the exit code is not 0