Rework async browser actions

This commit is contained in:
crschnick
2025-07-09 14:23:53 +00:00
parent 95bcc670d9
commit 388a20d5a4
9 changed files with 62 additions and 47 deletions

View File

@@ -163,12 +163,12 @@ public final class BrowserFileSystemTabModel extends BrowserStoreSessionTab<File
cdSyncWithoutCheck(currentPath.get());
}
public void refreshBrowserEntriesSync(List<BrowserEntry> entries) throws Exception {
public void refreshBrowserEntriesSync(List<BrowserEntry> entries) {
refreshFileEntriesSync(
entries.stream().map(BrowserEntry::getRawFileEntry).collect(Collectors.toList()));
}
public void refreshFileEntriesSync(List<FileEntry> entries) throws Exception {
public void refreshFileEntriesSync(List<FileEntry> entries) {
if (fileList.getAll().getValue().size() < 10) {
refreshSync();
return;
@@ -179,9 +179,13 @@ public final class BrowserFileSystemTabModel extends BrowserStoreSessionTab<File
return;
}
for (var e : entries) {
var refresh = fileSystem.getFileInfo(e.getPath());
fileList.updateEntry(e.getPath(), refresh.orElse(null));
try {
for (var e : entries) {
var refresh = fileSystem.getFileInfo(e.getPath());
fileList.updateEntry(e.getPath(), refresh.orElse(null));
}
} catch (Exception e) {
ErrorEventFactory.fromThrowable(e).handle();
}
}

View File

@@ -8,6 +8,7 @@ import io.xpipe.app.process.CommandBuilder;
import io.xpipe.app.process.ShellControl;
import io.xpipe.app.util.CommandDialog;
import io.xpipe.app.util.ThreadHelper;
import javafx.beans.value.ObservableValue;
import java.util.List;
@@ -33,7 +34,7 @@ public abstract class MultiExecuteMenuProvider implements BrowserMenuBranchProvi
}
var cmd = sc.command(c);
model.openTerminalSync(
model.openTerminalAsync(
entry.getRawFileEntry().getName(),
model.getCurrentDirectory() != null
? model.getCurrentDirectory().getPath()
@@ -61,17 +62,19 @@ public abstract class MultiExecuteMenuProvider implements BrowserMenuBranchProvi
@Override
public void execute(BrowserFileSystemTabModel model, List<BrowserEntry> entries) throws Exception {
var sc = model.getFileSystem().getShell().orElseThrow();
for (BrowserEntry entry : entries) {
var c = createCommand(sc, model, entry);
if (c == null) {
return;
}
ThreadHelper.runAsync(() -> {
var sc = model.getFileSystem().getShell().orElseThrow();
for (BrowserEntry entry : entries) {
var c = createCommand(sc, model, entry);
if (c == null) {
return;
}
var cmd = sc.command(c);
CommandDialog.runAndShow(cmd);
}
model.refreshBrowserEntriesSync(entries);
var cmd = sc.command(c);
CommandDialog.runAndShow(cmd);
}
model.refreshBrowserEntriesSync(entries);
});
}
@Override
@@ -84,19 +87,18 @@ public abstract class MultiExecuteMenuProvider implements BrowserMenuBranchProvi
@Override
public void execute(BrowserFileSystemTabModel model, List<BrowserEntry> entries) throws Exception {
var sc = model.getFileSystem().getShell().orElseThrow();
for (BrowserEntry entry : entries) {
var cmd = createCommand(sc, model, entry);
if (cmd == null) {
continue;
}
ThreadHelper.runFailableAsync(() -> {
var sc = model.getFileSystem().getShell().orElseThrow();
for (BrowserEntry entry : entries) {
var cmd = createCommand(sc, model, entry);
if (cmd == null) {
continue;
}
sc.command(cmd)
.withWorkingDirectory(
model.getCurrentDirectory().getPath())
.execute();
}
model.refreshBrowserEntriesSync(entries);
sc.command(cmd).withWorkingDirectory(model.getCurrentDirectory().getPath()).execute();
}
model.refreshBrowserEntriesSync(entries);
});
}
@Override

View File

@@ -6,6 +6,7 @@ import io.xpipe.app.browser.menu.BrowserMenuLeafProvider;
import io.xpipe.app.core.AppI18n;
import io.xpipe.app.util.LabelGraphic;
import io.xpipe.app.util.ThreadHelper;
import javafx.beans.value.ObservableValue;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
@@ -17,7 +18,9 @@ public class BackMenuProvider implements BrowserMenuLeafProvider {
@Override
public void execute(BrowserFileSystemTabModel model, List<BrowserEntry> entries) {
model.backSync(1);
ThreadHelper.runAsync(() -> {
model.backSync(1);
});
}
public String getId() {

View File

@@ -8,6 +8,7 @@ import io.xpipe.app.browser.menu.BrowserMenuLeafProvider;
import io.xpipe.app.core.AppI18n;
import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.app.util.LabelGraphic;
import io.xpipe.app.util.ThreadHelper;
import io.xpipe.core.FileKind;
import javafx.beans.value.ObservableValue;
@@ -26,9 +27,11 @@ public class EditFileMenuProvider implements BrowserMenuLeafProvider {
@Override
public void execute(BrowserFileSystemTabModel model, List<BrowserEntry> entries) {
for (BrowserEntry entry : entries) {
BrowserFileOpener.openInTextEditor(model, entry.getRawFileEntry());
}
ThreadHelper.runAsync(() -> {
for (BrowserEntry entry : entries) {
BrowserFileOpener.openInTextEditor(model, entry.getRawFileEntry());
}
});
}
@Override

View File

@@ -6,6 +6,7 @@ import io.xpipe.app.browser.menu.BrowserMenuLeafProvider;
import io.xpipe.app.core.AppI18n;
import io.xpipe.app.util.LabelGraphic;
import io.xpipe.app.util.ThreadHelper;
import javafx.beans.value.ObservableValue;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
@@ -17,7 +18,9 @@ public class ForwardMenuProvider implements BrowserMenuLeafProvider {
@Override
public void execute(BrowserFileSystemTabModel model, List<BrowserEntry> entries) {
model.forthSync(1);
ThreadHelper.runAsync(() -> {
model.forthSync(1);
});
}
public String getId() {

View File

@@ -11,6 +11,7 @@ import io.xpipe.app.process.CommandBuilder;
import io.xpipe.app.process.ShellControl;
import io.xpipe.app.util.FileOpener;
import io.xpipe.app.util.ThreadHelper;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
@@ -42,16 +43,14 @@ public class JavapMenuProvider
@Override
public void execute(BrowserFileSystemTabModel model, List<BrowserEntry> entries) throws Exception {
ShellControl sc = model.getFileSystem().getShell().orElseThrow();
for (BrowserEntry entry : entries) {
var command = CommandBuilder.of()
.add("javap", "-c", "-p")
.addFile(entry.getRawFileEntry().getPath());
var out = sc.command(command)
.withWorkingDirectory(model.getCurrentDirectory().getPath())
.readStdoutOrThrow();
FileOpener.openReadOnlyString(out);
}
ThreadHelper.runFailableAsync(() -> {
ShellControl sc = model.getFileSystem().getShell().orElseThrow();
for (BrowserEntry entry : entries) {
var command = CommandBuilder.of().add("javap", "-c", "-p").addFile(entry.getRawFileEntry().getPath());
var out = sc.command(command).withWorkingDirectory(model.getCurrentDirectory().getPath()).readStdoutOrThrow();
FileOpener.openReadOnlyString(out);
}
});
}
@Override

View File

@@ -6,6 +6,7 @@ import io.xpipe.app.browser.menu.BrowserMenuLeafProvider;
import io.xpipe.app.core.AppI18n;
import io.xpipe.app.util.LabelGraphic;
import io.xpipe.app.util.ThreadHelper;
import javafx.beans.value.ObservableValue;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
@@ -17,7 +18,9 @@ public class RefreshDirectoryMenuProvider implements BrowserMenuLeafProvider {
@Override
public void execute(BrowserFileSystemTabModel model, List<BrowserEntry> entries) {
model.refreshSync();
ThreadHelper.runAsync(() -> {
model.refreshSync();
});
}
public String getId() {

View File

@@ -132,6 +132,7 @@ The HTTP API has been improved in various areas. The action system is integrated
- You can now disable icon sources without having to remove them
- Terminal connections now enable truecolor mode if possible
- Add notification when a password is copied to the clipboard
- Add support for Ghostty on macOS
## Fixes

View File

@@ -47,9 +47,6 @@ public class RunFileScriptMenuProvider implements BrowserMenuBranchProvider {
DataStorage.get().getEffectiveCategoryConfig(model.getEntry().get());
if (Boolean.TRUE.equals(config.getDontAllowScripts())) {
return List.of(new BrowserMenuLeafProvider() {
@Override
public void execute(BrowserFileSystemTabModel model, List<BrowserEntry> entries) {}
@Override
public ObservableValue<String> getName(BrowserFileSystemTabModel model, List<BrowserEntry> entries) {
return AppI18n.observable("scriptsDisabled");