diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c609ab2b6..33648c595 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,15 +25,15 @@ components from it when it is run in a development environment. Note that in case the current master branch is ahead of the latest release, it might happen that there are some incompatibilities when loading data from your local XPipe installation. You should therefore always check out the matching version tag for your local repository and local XPipe installation. You can find the available version tags at https://github.com/xpipe-io/xpipe/tags. -So for example if you currently have XPipe `10.0` installed, you should run `git reset --hard 10.0` first to properly compile against it. +So for example if you currently have XPipe `11.3` installed, you should run `git reset --hard 11.3` first to properly compile against it. You need to have JDK for Java 21 installed to compile the project. If you are on Linux or macOS, you can easily accomplish that by running ```bash curl -s "https://get.sdkman.io" | bash . "$HOME/.sdkman/bin/sdkman-init.sh" -sdk install java 21.0.1-graalce -sdk default java 21.0.1-graalce +sdk install java 22.0.2-graalce +sdk default java 22.0.2-graalce ``` . On Windows, you have to manually install a JDK, e.g. from [Adoptium](https://adoptium.net/temurin/releases/?version=21). @@ -74,7 +74,7 @@ Especially when starting out, it might be a good idea to start with easy tasks f ### Interacting via the HTTP API -You can create clients they communicate with the XPipe daemon via its HTTP API. +You can create clients that communicate with the XPipe daemon via its HTTP API. To get started, see the [OpenAPI spec](/openapi.yaml). ### Implementing support for a new editor @@ -98,9 +98,13 @@ All actions that you can perform for certain connections in the connection overv You can add custom script definitions [here](https://github.com/xpipe-io/xpipe/tree/master/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptStore.java) and [here](https://github.com/xpipe-io/xpipe/tree/master/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts). +### Adding more system icons for system autodetection + +You can register new system types [here](https://github.com/xpipe-io/xpipe/blob/master/app/src/main/java/io/xpipe/app/resources/SystemIcons.java) and add the respective icons [here](https://github.com/xpipe-io/xpipe/tree/master/app/src/main/resources/io/xpipe/app/resources/img/system). + ### Adding more file icons for specific types -You can register file types [here](https://github.com/xpipe-io/xpipe/blob/master/app/src/main/resources/io/xpipe/app/resources/file_list.txt) and add the respective icons [here](https://github.com/xpipe-io/xpipe/tree/master/app/src/main/resources/io/xpipe/app/resources/browser_icons). +You can register file types [here](https://github.com/xpipe-io/xpipe/blob/master/app/src/main/resources/io/xpipe/app/resources/file_list.txt) and add the respective icons [here](https://github.com/xpipe-io/xpipe/tree/master/app/src/main/resources/io/xpipe/app/resources/img/browser). The existing file list and icons are taken from the [vscode-icons](https://github.com/vscode-icons/vscode-icons) project. Due to limitations in the file definition list compatibility, some file types might not be listed by their proper extension and are therefore not being applied correctly even though the images and definitions exist already. @@ -108,6 +112,6 @@ The existing file list and icons are taken from the [vscode-icons](https://githu if you want to work on something that was not listed here, you can still do so of course. You can reach out on the [Discord server](https://discord.gg/8y89vS8cRb) to discuss any development plans and get you started. -### Translations +### Adding translations See the [translation guide](/lang) for details. diff --git a/README.md b/README.md index ade164d71..fe79cd336 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,10 @@ It currently supports: - [Docker](https://www.docker.com/), [Podman](https://podman.io/), and [LXD](https://linuxcontainers.org/lxd/introduction/) container instances located on any host - [Windows Subsystem for Linux](https://ubuntu.com/wsl), [Cygwin](https://www.cygwin.com/), and [MSYS2](https://www.msys2.org/) instances - [Proxmox PVE](https://www.proxmox.com/en/proxmox-virtual-environment/overview) virtual machines and containers +- [Hyper-V](https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/about/) and [VMware Player/Workstation/Fusion](https://www.vmware.com/products/desktop-hypervisor/workstation-and-fusion) virtual machines - [Kubernetes](https://kubernetes.io/) clusters, pods, and containers - [Powershell Remote Sessions](https://learn.microsoft.com/en-us/powershell/scripting/learn/remoting/running-remote-commands?view=powershell-7.3) +- Built-in VNC connections and RDP launchers - Any other custom remote connection methods that work through the command-line ## Connection hub @@ -50,6 +52,8 @@ It currently supports: - Works with all command shells such as bash, zsh, cmd, PowerShell, and more, locally and remote - Connects to a system while the terminal is still starting up, allowing for faster connections than otherwise possible +![Terminal](https://github.com/xpipe-io/.github/raw/main/img/terminal_shadow.png) +

Terminal launcher diff --git a/app/build.gradle b/app/build.gradle index 0160355de..b7fdfcf1b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -52,10 +52,10 @@ dependencies { api files("$rootDir/gradle/gradle_scripts/vernacular-1.16.jar") api 'org.bouncycastle:bcprov-jdk18on:1.78.1' api 'info.picocli:picocli:4.7.6' - api ('org.kohsuke:github-api:1.324') { + api ('org.kohsuke:github-api:1.326') { exclude group: 'org.apache.commons', module: 'commons-lang3' } - api 'org.apache.commons:commons-lang3:3.16.0' + api 'org.apache.commons:commons-lang3:3.17.0' api 'io.sentry:sentry:7.14.0' api 'commons-io:commons-io:2.16.1' api group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "2.17.2" 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 972307a24..aac5156aa 100644 --- a/app/src/main/java/io/xpipe/app/beacon/AppBeaconServer.java +++ b/app/src/main/java/io/xpipe/app/beacon/AppBeaconServer.java @@ -1,8 +1,8 @@ package io.xpipe.app.beacon; -import io.xpipe.app.core.AppResources; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.issue.TrackEvent; +import io.xpipe.app.resources.AppResources; import io.xpipe.app.util.MarkdownHelper; import io.xpipe.beacon.BeaconConfig; import io.xpipe.beacon.BeaconInterface; diff --git a/app/src/main/java/io/xpipe/app/beacon/BeaconRequestHandler.java b/app/src/main/java/io/xpipe/app/beacon/BeaconRequestHandler.java index ab2467d4e..0a391696d 100644 --- a/app/src/main/java/io/xpipe/app/beacon/BeaconRequestHandler.java +++ b/app/src/main/java/io/xpipe/app/beacon/BeaconRequestHandler.java @@ -39,7 +39,8 @@ public class BeaconRequestHandler implements HttpHandler { } } - if (beaconInterface.requiresEnabledApi() && !AppPrefs.get().enableHttpApi().get()) { + if (beaconInterface.requiresEnabledApi() + && !AppPrefs.get().enableHttpApi().get()) { var ex = new BeaconServerException("HTTP API is not enabled in the settings menu"); writeError(exchange, ex, 403); return; diff --git a/app/src/main/java/io/xpipe/app/beacon/impl/ConnectionRefreshExchangeImpl.java b/app/src/main/java/io/xpipe/app/beacon/impl/ConnectionRefreshExchangeImpl.java index 5fa336528..3c97868e9 100644 --- a/app/src/main/java/io/xpipe/app/beacon/impl/ConnectionRefreshExchangeImpl.java +++ b/app/src/main/java/io/xpipe/app/beacon/impl/ConnectionRefreshExchangeImpl.java @@ -15,9 +15,9 @@ public class ConnectionRefreshExchangeImpl extends ConnectionRefreshExchange { .getStoreEntryIfPresent(msg.getConnection()) .orElseThrow(() -> new BeaconClientException("Unknown connection: " + msg.getConnection())); if (e.getStore() instanceof FixedHierarchyStore) { - DataStorage.get().refreshChildren(e, true); + DataStorage.get().refreshChildren(e, null, true); } else { - e.validateOrThrow(); + e.validateOrThrowAndClose(null); } return Response.builder().build(); } diff --git a/app/src/main/java/io/xpipe/app/beacon/impl/FsReadExchangeImpl.java b/app/src/main/java/io/xpipe/app/beacon/impl/FsReadExchangeImpl.java index 97f9c7ed1..590a3f229 100644 --- a/app/src/main/java/io/xpipe/app/beacon/impl/FsReadExchangeImpl.java +++ b/app/src/main/java/io/xpipe/app/beacon/impl/FsReadExchangeImpl.java @@ -43,7 +43,6 @@ public class FsReadExchangeImpl extends FsReadExchange { var out = exchange.getResponseBody()) { fileIn.transferTo(out); } - return Response.builder().build(); } else { byte[] bytes; try (var in = fs.openInput(msg.getPath().toString())) { @@ -55,7 +54,7 @@ public class FsReadExchangeImpl extends FsReadExchange { try (var out = exchange.getResponseBody()) { out.write(bytes); } - return Response.builder().build(); } + return Response.builder().build(); } } diff --git a/app/src/main/java/io/xpipe/app/beacon/impl/ShellStartExchangeImpl.java b/app/src/main/java/io/xpipe/app/beacon/impl/ShellStartExchangeImpl.java index c43be274d..21cefe252 100644 --- a/app/src/main/java/io/xpipe/app/beacon/impl/ShellStartExchangeImpl.java +++ b/app/src/main/java/io/xpipe/app/beacon/impl/ShellStartExchangeImpl.java @@ -1,12 +1,13 @@ package io.xpipe.app.beacon.impl; -import com.sun.net.httpserver.HttpExchange; import io.xpipe.app.beacon.AppBeaconServer; import io.xpipe.app.beacon.BeaconShellSession; import io.xpipe.app.storage.DataStorage; import io.xpipe.beacon.BeaconClientException; import io.xpipe.beacon.api.ShellStartExchange; import io.xpipe.core.store.ShellStore; + +import com.sun.net.httpserver.HttpExchange; import lombok.SneakyThrows; public class ShellStartExchangeImpl extends ShellStartExchange { diff --git a/app/src/main/java/io/xpipe/app/beacon/impl/SshLaunchExchangeImpl.java b/app/src/main/java/io/xpipe/app/beacon/impl/SshLaunchExchangeImpl.java index e9d4bfeff..2b8c8c410 100644 --- a/app/src/main/java/io/xpipe/app/beacon/impl/SshLaunchExchangeImpl.java +++ b/app/src/main/java/io/xpipe/app/beacon/impl/SshLaunchExchangeImpl.java @@ -1,11 +1,12 @@ package io.xpipe.app.beacon.impl; -import com.sun.net.httpserver.HttpExchange; +import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.app.util.TerminalLauncherManager; import io.xpipe.beacon.api.SshLaunchExchange; -import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.core.process.ShellDialects; +import com.sun.net.httpserver.HttpExchange; + import java.util.List; public class SshLaunchExchangeImpl extends SshLaunchExchange { @@ -27,7 +28,7 @@ public class SshLaunchExchangeImpl extends SshLaunchExchange { // There are sometimes multiple requests by a terminal client (e.g. Termius) // This might fail sometimes, but it is expected - var r = TerminalLauncherManager.waitForNextLaunch(); + var r = TerminalLauncherManager.sshLaunchExchange(); var c = ProcessControlProvider.get() .getEffectiveLocalDialect() .getOpenScriptCommand(r.toString()) diff --git a/app/src/main/java/io/xpipe/app/beacon/impl/TerminalLaunchExchangeImpl.java b/app/src/main/java/io/xpipe/app/beacon/impl/TerminalLaunchExchangeImpl.java index 1d732bbb9..d1982ca7f 100644 --- a/app/src/main/java/io/xpipe/app/beacon/impl/TerminalLaunchExchangeImpl.java +++ b/app/src/main/java/io/xpipe/app/beacon/impl/TerminalLaunchExchangeImpl.java @@ -9,7 +9,7 @@ import com.sun.net.httpserver.HttpExchange; public class TerminalLaunchExchangeImpl extends TerminalLaunchExchange { @Override public Object handle(HttpExchange exchange, Request msg) throws BeaconClientException { - var r = TerminalLauncherManager.performLaunch(msg.getRequest()); + var r = TerminalLauncherManager.launchExchange(msg.getRequest()); return Response.builder().targetFile(r).build(); } diff --git a/app/src/main/java/io/xpipe/app/beacon/impl/TerminalWaitExchangeImpl.java b/app/src/main/java/io/xpipe/app/beacon/impl/TerminalWaitExchangeImpl.java index 4f6729c5d..7a4cef411 100644 --- a/app/src/main/java/io/xpipe/app/beacon/impl/TerminalWaitExchangeImpl.java +++ b/app/src/main/java/io/xpipe/app/beacon/impl/TerminalWaitExchangeImpl.java @@ -1,6 +1,7 @@ package io.xpipe.app.beacon.impl; import io.xpipe.app.util.TerminalLauncherManager; +import io.xpipe.app.util.TerminalView; import io.xpipe.beacon.BeaconClientException; import io.xpipe.beacon.BeaconServerException; import io.xpipe.beacon.api.TerminalWaitExchange; @@ -10,7 +11,8 @@ import com.sun.net.httpserver.HttpExchange; public class TerminalWaitExchangeImpl extends TerminalWaitExchange { @Override public Object handle(HttpExchange exchange, Request msg) throws BeaconClientException, BeaconServerException { - TerminalLauncherManager.waitForCompletion(msg.getRequest()); + TerminalLauncherManager.waitExchange(msg.getRequest()); + TerminalView.get().open(msg.getPid()); return Response.builder().build(); } diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserClipboard.java b/app/src/main/java/io/xpipe/app/browser/BrowserClipboard.java index 1921d9a3a..c07dfc0e6 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserClipboard.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserClipboard.java @@ -3,9 +3,9 @@ package io.xpipe.app.browser; import io.xpipe.app.browser.file.BrowserEntry; import io.xpipe.app.browser.file.BrowserFileTransferMode; import io.xpipe.app.browser.file.LocalFileSystem; +import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.util.ThreadHelper; -import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.core.store.FileEntry; import io.xpipe.core.util.FailableRunnable; diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserFileOpener.java b/app/src/main/java/io/xpipe/app/browser/BrowserFileOpener.java index a25524f50..c66cc2ff3 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserFileOpener.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserFileOpener.java @@ -1,20 +1,76 @@ package io.xpipe.app.browser; import io.xpipe.app.browser.fs.OpenFileSystemModel; +import io.xpipe.app.core.window.AppWindowHelper; import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.util.BooleanScope; import io.xpipe.app.util.FileBridge; import io.xpipe.app.util.FileOpener; +import io.xpipe.core.process.ElevationFunction; +import io.xpipe.core.process.OsType; +import io.xpipe.core.store.ConnectionFileSystem; import io.xpipe.core.store.FileEntry; +import io.xpipe.core.store.FileInfo; import io.xpipe.core.store.FileNames; +import java.io.FilterOutputStream; +import java.io.IOException; import java.io.OutputStream; +import java.util.Objects; public class BrowserFileOpener { + private static OutputStream openFileOutput(OpenFileSystemModel model, FileEntry file, long totalBytes) + throws Exception { + var fileSystem = model.getFileSystem(); + if (model.isClosed() || fileSystem.getShell().isEmpty()) { + return OutputStream.nullOutputStream(); + } + + var sc = fileSystem.getShell().get(); + if (sc.getOsType() == OsType.WINDOWS) { + return fileSystem.openOutput(file.getPath(), totalBytes); + } + + var info = (FileInfo.Unix) file.getInfo(); + var zero = Integer.valueOf(0); + var otherWrite = info.getPermissions().charAt(7) == 'w'; + var requiresRoot = zero.equals(info.getUid()) && zero.equals(info.getGid()) && !otherWrite; + if (!requiresRoot || model.getCache().isRoot()) { + return fileSystem.openOutput(file.getPath(), totalBytes); + } + + var elevate = AppWindowHelper.showConfirmationAlert( + "app.fileWriteSudoTitle", "app.fileWriteSudoHeader", "app.fileWriteSudoContent"); + if (!elevate) { + return fileSystem.openOutput(file.getPath(), totalBytes); + } + + var rootSc = sc.identicalSubShell() + .elevated(ElevationFunction.elevated("sudo")) + .start(); + var rootFs = new ConnectionFileSystem(rootSc); + try { + return new FilterOutputStream(rootFs.openOutput(file.getPath(), totalBytes)) { + @Override + public void close() throws IOException { + super.close(); + rootFs.close(); + } + }; + } catch (Exception ex) { + rootFs.close(); + throw ex; + } + } + + private static int calculateKey(FileEntry entry) { + return Objects.hash(entry.getPath(), entry.getFileSystem(), entry.getKind(), entry.getInfo()); + } + public static void openWithAnyApplication(OpenFileSystemModel model, FileEntry entry) { var file = entry.getPath(); - var key = entry.getPath().hashCode() + entry.getFileSystem().hashCode(); + var key = calculateKey(entry); FileBridge.get() .openIO( FileNames.getFileName(file), @@ -35,7 +91,7 @@ public class BrowserFileOpener { public static void openInDefaultApplication(OpenFileSystemModel model, FileEntry entry) { var file = entry.getPath(); - var key = entry.getPath().hashCode() + entry.getFileSystem().hashCode(); + var key = calculateKey(entry); FileBridge.get() .openIO( FileNames.getFileName(file), @@ -61,7 +117,7 @@ public class BrowserFileOpener { } var file = entry.getPath(); - var key = entry.getPath().hashCode() + entry.getFileSystem().hashCode(); + var key = calculateKey(entry); FileBridge.get() .openIO( FileNames.getFileName(file), @@ -71,11 +127,7 @@ public class BrowserFileOpener { return entry.getFileSystem().openInput(file); }, (size) -> { - if (model.isClosed()) { - return OutputStream.nullOutputStream(); - } - - return entry.getFileSystem().openOutput(file, size); + return openFileOutput(model, entry, size); }, FileOpener::openInTextEditor); } diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserNavBar.java b/app/src/main/java/io/xpipe/app/browser/BrowserNavBar.java index f4c4f55f6..06fb8cd32 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserNavBar.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserNavBar.java @@ -84,7 +84,7 @@ public class BrowserNavBar extends Comp { var graphic = Bindings.createStringBinding( () -> { return model.getCurrentDirectory() != null - ? FileIconManager.getFileIcon(model.getCurrentDirectory(), false) + ? FileIconManager.getFileIcon(model.getCurrentDirectory()) : null; }, model.getCurrentPath()); diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserStatusBarComp.java b/app/src/main/java/io/xpipe/app/browser/BrowserStatusBarComp.java index 8d853d5fd..43edfb8e3 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserStatusBarComp.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserStatusBarComp.java @@ -55,7 +55,7 @@ public class BrowserStatusBarComp extends SimpleComp { private Comp createProgressEstimateStatus() { var text = BindingsHelper.map(model.getProgress(), p -> { - if (p == null || p.done()) { + if (p == null) { return null; } else { var expected = p.expectedTimeRemaining(); @@ -74,7 +74,7 @@ public class BrowserStatusBarComp extends SimpleComp { private Comp createProgressStatus() { var text = BindingsHelper.map(model.getProgress(), p -> { - if (p == null || p.done()) { + if (p == null) { return null; } else { var transferred = HumanReadableFormat.progressByteCount(p.getTransferred()); @@ -91,7 +91,7 @@ public class BrowserStatusBarComp extends SimpleComp { private Comp createProgressNameStatus() { var text = BindingsHelper.map(model.getProgress(), p -> { - if (p == null || p.done()) { + if (p == null) { return null; } else { return p.getName(); diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserTransferModel.java b/app/src/main/java/io/xpipe/app/browser/BrowserTransferModel.java index 87e44d064..5f1818bba 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserTransferModel.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserTransferModel.java @@ -10,12 +10,14 @@ import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.util.DesktopHelper; import io.xpipe.app.util.ShellTemp; import io.xpipe.app.util.ThreadHelper; + import javafx.beans.binding.Bindings; import javafx.beans.property.Property; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.value.ObservableBooleanValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; + import lombok.Value; import org.apache.commons.io.FileUtils; @@ -133,6 +135,12 @@ public class BrowserTransferModel { BrowserFileTransferMode.COPY, false, progress -> { + // Don't update item progress to keep it as finished + if (progress == null) { + item.getOpenFileSystemModel().getProgress().setValue(null); + return; + } + synchronized (item.getProgress()) { item.getProgress().setValue(progress); } @@ -170,7 +178,7 @@ public class BrowserTransferModel { if (Files.isDirectory(file)) { FileUtils.moveDirectory(file.toFile(), target.toFile()); } else { - FileUtils.moveFile(file.toFile(), target.toFile(), StandardCopyOption.REPLACE_EXISTING); + Files.move(file, target, StandardCopyOption.REPLACE_EXISTING); } } DesktopHelper.browseFileInDirectory(downloads.resolve(files.getFirst().getFileName())); diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserTransferProgress.java b/app/src/main/java/io/xpipe/app/browser/BrowserTransferProgress.java index bb1e16ec7..7486afdb6 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserTransferProgress.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserTransferProgress.java @@ -14,14 +14,6 @@ public class BrowserTransferProgress { long total; Instant start; - public static BrowserTransferProgress empty() { - return new BrowserTransferProgress(null, 0, 0, Instant.now()); - } - - static BrowserTransferProgress empty(String name, long size) { - return new BrowserTransferProgress(name, 0, size, Instant.now()); - } - public static BrowserTransferProgress finished(String name, long size) { return new BrowserTransferProgress(name, size, size, Instant.now()); } diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserWelcomeComp.java b/app/src/main/java/io/xpipe/app/browser/BrowserWelcomeComp.java index 08f4f4d4a..87a1b186f 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserWelcomeComp.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserWelcomeComp.java @@ -52,7 +52,7 @@ public class BrowserWelcomeComp extends SimpleComp { var vbox = new VBox(welcome, new Spacer(4, Orientation.VERTICAL)); vbox.setAlignment(Pos.CENTER_LEFT); - var img = new PrettySvgComp(new SimpleStringProperty("Hips.svg"), 50, 75) + var img = new PrettySvgComp(new SimpleStringProperty("graphics/Hips.svg"), 50, 75) .padding(new Insets(5, 0, 0, 0)) .createRegion(); @@ -145,8 +145,7 @@ public class BrowserWelcomeComp extends SimpleComp { private Comp entryButton(BrowserSavedState.Entry e, BooleanProperty disable) { var entry = DataStorage.get().getStoreEntryIfPresent(e.getUuid()); - var graphic = - entry.get().getProvider().getDisplayIconFileName(entry.get().getStore()); + var graphic = entry.get().getEffectiveIconFile(); var view = PrettyImageHelper.ofFixedSize(graphic, 30, 24); return new ButtonComp( new SimpleStringProperty(DataStorage.get().getStoreEntryDisplayName(entry.get())), diff --git a/app/src/main/java/io/xpipe/app/browser/file/BrowserAlerts.java b/app/src/main/java/io/xpipe/app/browser/file/BrowserAlerts.java index 80e71cdff..6f0350188 100644 --- a/app/src/main/java/io/xpipe/app/browser/file/BrowserAlerts.java +++ b/app/src/main/java/io/xpipe/app/browser/file/BrowserAlerts.java @@ -2,6 +2,7 @@ package io.xpipe.app.browser.file; import io.xpipe.app.core.AppI18n; import io.xpipe.app.core.window.AppWindowHelper; +import io.xpipe.app.prefs.AppPrefs; import io.xpipe.core.store.FileEntry; import io.xpipe.core.store.FileKind; import io.xpipe.core.store.FilePath; @@ -62,7 +63,8 @@ public class BrowserAlerts { } public static boolean showDeleteAlert(List source) { - if (source.stream().noneMatch(entry -> entry.getKind() == FileKind.DIRECTORY)) { + if (!AppPrefs.get().confirmDeletions().get() + && source.stream().noneMatch(entry -> entry.getKind() == FileKind.DIRECTORY)) { return true; } diff --git a/app/src/main/java/io/xpipe/app/browser/file/BrowserEntry.java b/app/src/main/java/io/xpipe/app/browser/file/BrowserEntry.java index 616693aab..184cc12a7 100644 --- a/app/src/main/java/io/xpipe/app/browser/file/BrowserEntry.java +++ b/app/src/main/java/io/xpipe/app/browser/file/BrowserEntry.java @@ -65,11 +65,11 @@ public class BrowserEntry { if (fileType != null) { return fileType.getIcon(); } else if (directoryType != null) { - return directoryType.getIcon(rawFileEntry, false); + return directoryType.getIcon(rawFileEntry); } else { return rawFileEntry != null && rawFileEntry.resolved().getKind() == FileKind.DIRECTORY - ? "default_folder.svg" - : "default_file.svg"; + ? "browser/default_folder.svg" + : "browser/default_file.svg"; } } diff --git a/app/src/main/java/io/xpipe/app/browser/file/BrowserFileListComp.java b/app/src/main/java/io/xpipe/app/browser/file/BrowserFileListComp.java index 9eaba89c9..f9cfb23a2 100644 --- a/app/src/main/java/io/xpipe/app/browser/file/BrowserFileListComp.java +++ b/app/src/main/java/io/xpipe/app/browser/file/BrowserFileListComp.java @@ -194,9 +194,9 @@ public final class BrowserFileListComp extends SimpleComp { ? unix.getGroup() : m.getCache().getGroups().getOrDefault(unix.getGid(), "?"); var uid = String.valueOf( - unix.getUid() != null ? unix.getUid() : m.getCache().getUidForUser(user)); + unix.getUid() != null ? unix.getUid() : m.getCache().getUidForUser(user)); var gid = String.valueOf( - unix.getGid() != null ? unix.getGid() : m.getCache().getGidForGroup(group)); + unix.getGid() != null ? unix.getGid() : m.getCache().getGidForGroup(group)); if (uid.equals(gid) && user.equals(group)) { return user + " [" + uid + "]"; } @@ -248,7 +248,6 @@ public final class BrowserFileListComp extends SimpleComp { if (inCooldown) { lastType.set(Instant.now()); event.consume(); - return; } else { lastType.set(null); typedSelection.set(""); @@ -256,8 +255,8 @@ public final class BrowserFileListComp extends SimpleComp { if (!recursive) { updateTypedSelection(table, lastType, event, true); } - return; } + return; } lastType.set(Instant.now()); @@ -631,6 +630,10 @@ public final class BrowserFileListComp extends SimpleComp { () -> getTableRow().getItem(), fileList.getFileSystemModel()) .hide(Bindings.createBooleanBinding( () -> { + if (getTableRow() == null) { + return true; + } + var item = getTableRow().getItem(); var notDir = item.getRawFileEntry().resolved().getKind() != FileKind.DIRECTORY; var isParentLink = item.getRawFileEntry() diff --git a/app/src/main/java/io/xpipe/app/browser/file/BrowserFileTransferOperation.java b/app/src/main/java/io/xpipe/app/browser/file/BrowserFileTransferOperation.java index 65af868aa..6e49f8a4a 100644 --- a/app/src/main/java/io/xpipe/app/browser/file/BrowserFileTransferOperation.java +++ b/app/src/main/java/io/xpipe/app/browser/file/BrowserFileTransferOperation.java @@ -102,7 +102,7 @@ public class BrowserFileTransferOperation { public void execute() throws Exception { if (files.isEmpty()) { - updateProgress(BrowserTransferProgress.empty()); + updateProgress(null); return; } @@ -115,18 +115,22 @@ public class BrowserFileTransferOperation { } } - for (var file : files) { - if (same) { - handleSingleOnSameFileSystem(file); - } else { - handleSingleAcrossFileSystems(file); - } - } - - if (!same && doesMove) { + try { for (var file : files) { - deleteSingle(file); + if (same) { + handleSingleOnSameFileSystem(file); + } else { + handleSingleAcrossFileSystems(file); + } } + + if (!same && doesMove) { + for (var file : files) { + deleteSingle(file); + } + } + } finally { + updateProgress(null); } } diff --git a/app/src/main/java/io/xpipe/app/browser/file/BrowserQuickAccessContextMenu.java b/app/src/main/java/io/xpipe/app/browser/file/BrowserQuickAccessContextMenu.java index 83d3d6a33..6f5735534 100644 --- a/app/src/main/java/io/xpipe/app/browser/file/BrowserQuickAccessContextMenu.java +++ b/app/src/main/java/io/xpipe/app/browser/file/BrowserQuickAccessContextMenu.java @@ -142,8 +142,7 @@ public class BrowserQuickAccessContextMenu extends ContextMenu { this.menu = new Menu( // Use original name, not the link target browserEntry.getRawFileEntry().getName(), - PrettyImageHelper.ofFixedRasterized( - FileIconManager.getFileIcon(browserEntry.getRawFileEntry(), false), 24, 24) + PrettyImageHelper.ofFixedSize(FileIconManager.getFileIcon(browserEntry.getRawFileEntry()), 24, 24) .createRegion()); createMenu(); addInputListeners(); diff --git a/app/src/main/java/io/xpipe/app/browser/file/LocalFileSystem.java b/app/src/main/java/io/xpipe/app/browser/file/LocalFileSystem.java index 6b07cd7c8..48b74d368 100644 --- a/app/src/main/java/io/xpipe/app/browser/file/LocalFileSystem.java +++ b/app/src/main/java/io/xpipe/app/browser/file/LocalFileSystem.java @@ -1,9 +1,9 @@ package io.xpipe.app.browser.file; +import io.xpipe.app.ext.LocalStore; import io.xpipe.core.store.FileEntry; import io.xpipe.core.store.FileKind; import io.xpipe.core.store.FileSystem; -import io.xpipe.app.ext.LocalStore; import java.nio.file.Files; import java.nio.file.Path; @@ -19,6 +19,13 @@ public class LocalFileSystem { } } + public static void reset() throws Exception { + if (localFileSystem != null) { + localFileSystem.close(); + localFileSystem = null; + } + } + public static FileEntry getLocalFileEntry(Path file) throws Exception { if (localFileSystem == null) { throw new IllegalStateException(); diff --git a/app/src/main/java/io/xpipe/app/browser/fs/OpenFileSystemCache.java b/app/src/main/java/io/xpipe/app/browser/fs/OpenFileSystemCache.java index 9a750cdb3..9d9037af9 100644 --- a/app/src/main/java/io/xpipe/app/browser/fs/OpenFileSystemCache.java +++ b/app/src/main/java/io/xpipe/app/browser/fs/OpenFileSystemCache.java @@ -60,7 +60,8 @@ public class OpenFileSystemCache extends ShellControlCache { var split = s.split(":"); try { users.putIfAbsent(Integer.parseInt(split[2]), split[0]); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } }); if (users.isEmpty()) { @@ -81,7 +82,8 @@ public class OpenFileSystemCache extends ShellControlCache { var split = s.split(":"); try { groups.putIfAbsent(Integer.parseInt(split[2]), split[0]); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } }); if (groups.isEmpty()) { diff --git a/app/src/main/java/io/xpipe/app/browser/fs/OpenFileSystemModel.java b/app/src/main/java/io/xpipe/app/browser/fs/OpenFileSystemModel.java index 3697c98e0..fffc99126 100644 --- a/app/src/main/java/io/xpipe/app/browser/fs/OpenFileSystemModel.java +++ b/app/src/main/java/io/xpipe/app/browser/fs/OpenFileSystemModel.java @@ -11,6 +11,7 @@ import io.xpipe.app.browser.file.FileSystemHelper; import io.xpipe.app.browser.session.BrowserAbstractSessionModel; import io.xpipe.app.browser.session.BrowserSessionTab; import io.xpipe.app.comp.base.ModalOverlayComp; +import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.storage.DataStorage; @@ -18,7 +19,7 @@ import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.BooleanScope; import io.xpipe.app.util.TerminalLauncher; import io.xpipe.app.util.ThreadHelper; -import io.xpipe.app.ext.ProcessControlProvider; +import io.xpipe.core.process.CommandBuilder; import io.xpipe.core.process.ShellControl; import io.xpipe.core.process.ShellDialects; import io.xpipe.core.process.ShellOpenFunction; @@ -47,8 +48,7 @@ public final class OpenFileSystemModel extends BrowserSessionTab overlay = new SimpleObjectProperty<>(); private final BooleanProperty inOverview = new SimpleBooleanProperty(); - private final Property progress = - new SimpleObjectProperty<>(BrowserTransferProgress.empty()); + private final Property progress = new SimpleObjectProperty<>(); private FileSystem fileSystem; private OpenFileSystemSavedState savedState; private OpenFileSystemCache cache; @@ -73,10 +73,13 @@ public final class OpenFileSystemModel extends BrowserSessionTab 4 ? "browser/" + split[4].trim() : closedIcon; - var lightClosedIcon = split.length > 4 ? split[4].trim() : closedIcon; - var lightOpenIcon = split.length > 4 ? split[5].trim() : openIcon; - - ALL.add(new Simple( - id, - new IconVariant(lightClosedIcon, closedIcon), - new IconVariant(lightOpenIcon, openIcon), - filter)); + ALL.add(new Simple(id, new IconVariant(lightClosedIcon, closedIcon), filter)); } } }); @@ -84,7 +77,7 @@ public abstract class BrowserIconDirectoryType { public abstract boolean matches(FileEntry entry); - public abstract String getIcon(FileEntry entry, boolean open); + public abstract String getIcon(FileEntry entry); public static class Simple extends BrowserIconDirectoryType { @@ -92,13 +85,11 @@ public abstract class BrowserIconDirectoryType { private final String id; private final IconVariant closed; - private final IconVariant open; private final Set names; - public Simple(String id, IconVariant closed, IconVariant open, Set names) { + public Simple(String id, IconVariant closed, Set names) { this.id = id; this.closed = closed; - this.open = open; this.names = names; } @@ -113,8 +104,8 @@ public abstract class BrowserIconDirectoryType { } @Override - public String getIcon(FileEntry entry, boolean open) { - return open ? this.open.getIcon() : this.closed.getIcon(); + public String getIcon(FileEntry entry) { + return this.closed.getIcon(); } } } diff --git a/app/src/main/java/io/xpipe/app/browser/icon/BrowserIconFileType.java b/app/src/main/java/io/xpipe/app/browser/icon/BrowserIconFileType.java index d955481f8..4293aa2b6 100644 --- a/app/src/main/java/io/xpipe/app/browser/icon/BrowserIconFileType.java +++ b/app/src/main/java/io/xpipe/app/browser/icon/BrowserIconFileType.java @@ -1,6 +1,6 @@ package io.xpipe.app.browser.icon; -import io.xpipe.app.core.AppResources; +import io.xpipe.app.resources.AppResources; import io.xpipe.core.store.FileEntry; import io.xpipe.core.store.FileKind; import io.xpipe.core.store.FileNames; @@ -47,8 +47,8 @@ public abstract class BrowserIconFileType { return "." + r; }) .collect(Collectors.toSet()); - var darkIcon = split[2].trim(); - var lightIcon = split.length > 3 ? split[3].trim() : darkIcon; + var darkIcon = "browser/" + split[2].trim(); + var lightIcon = (split.length > 3 ? "browser/" + split[3].trim() : darkIcon); ALL.add(new BrowserIconFileType.Simple(id, lightIcon, darkIcon, filter)); } } diff --git a/app/src/main/java/io/xpipe/app/browser/icon/BrowserIcons.java b/app/src/main/java/io/xpipe/app/browser/icon/BrowserIcons.java index e156867ea..18fc39bde 100644 --- a/app/src/main/java/io/xpipe/app/browser/icon/BrowserIcons.java +++ b/app/src/main/java/io/xpipe/app/browser/icon/BrowserIcons.java @@ -7,11 +7,11 @@ import io.xpipe.core.store.FileEntry; public class BrowserIcons { public static Comp createDefaultFileIcon() { - return PrettyImageHelper.ofFixedSizeSquare("default_file.svg", 24); + return PrettyImageHelper.ofFixedSizeSquare("browser/default_file.svg", 24); } public static Comp createDefaultDirectoryIcon() { - return PrettyImageHelper.ofFixedSizeSquare("default_folder.svg", 24); + return PrettyImageHelper.ofFixedSizeSquare("browser/default_folder.svg", 24); } public static Comp createIcon(BrowserIconFileType type) { @@ -19,6 +19,6 @@ public class BrowserIcons { } public static Comp createIcon(FileEntry entry) { - return PrettyImageHelper.ofFixedSizeSquare(FileIconManager.getFileIcon(entry, false), 24); + return PrettyImageHelper.ofFixedSizeSquare(FileIconManager.getFileIcon(entry), 24); } } diff --git a/app/src/main/java/io/xpipe/app/browser/icon/FileIconManager.java b/app/src/main/java/io/xpipe/app/browser/icon/FileIconManager.java index 4df214cd7..1b28618df 100644 --- a/app/src/main/java/io/xpipe/app/browser/icon/FileIconManager.java +++ b/app/src/main/java/io/xpipe/app/browser/icon/FileIconManager.java @@ -1,7 +1,5 @@ package io.xpipe.app.browser.icon; -import io.xpipe.app.core.AppImages; -import io.xpipe.app.core.AppResources; import io.xpipe.core.store.FileEntry; import io.xpipe.core.store.FileKind; @@ -13,12 +11,11 @@ public class FileIconManager { if (!loaded) { BrowserIconFileType.loadDefinitions(); BrowserIconDirectoryType.loadDefinitions(); - AppImages.loadDirectory(AppResources.XPIPE_MODULE, "browser_icons", true, false); loaded = true; } } - public static synchronized String getFileIcon(FileEntry entry, boolean open) { + public static synchronized String getFileIcon(FileEntry entry) { if (entry == null) { return null; } @@ -33,13 +30,11 @@ public class FileIconManager { } else { for (var f : BrowserIconDirectoryType.getAll()) { if (f.matches(r)) { - return f.getIcon(r, open); + return f.getIcon(r); } } } - return r.getKind() == FileKind.DIRECTORY - ? (open ? "default_folder_opened.svg" : "default_folder.svg") - : "default_file.svg"; + return "browser/" + (r.getKind() == FileKind.DIRECTORY ? "default_folder.svg" : "default_file.svg"); } } diff --git a/app/src/main/java/io/xpipe/app/browser/session/BrowserChooserComp.java b/app/src/main/java/io/xpipe/app/browser/session/BrowserChooserComp.java index 8b38c6bb9..59189e207 100644 --- a/app/src/main/java/io/xpipe/app/browser/session/BrowserChooserComp.java +++ b/app/src/main/java/io/xpipe/app/browser/session/BrowserChooserComp.java @@ -9,11 +9,8 @@ import io.xpipe.app.comp.base.DialogComp; import io.xpipe.app.comp.base.SideSplitPaneComp; import io.xpipe.app.comp.store.StoreEntryWrapper; import io.xpipe.app.core.AppFont; -import io.xpipe.app.core.AppI18n; import io.xpipe.app.core.AppLayoutModel; -import io.xpipe.app.core.window.AppWindowHelper; import io.xpipe.app.fxcomps.Comp; -import io.xpipe.app.fxcomps.SimpleComp; import io.xpipe.app.fxcomps.impl.StackComp; import io.xpipe.app.fxcomps.impl.VerticalComp; import io.xpipe.app.fxcomps.util.BindingsHelper; @@ -30,7 +27,6 @@ import javafx.geometry.Pos; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; -import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; import javafx.scene.shape.Rectangle; @@ -40,7 +36,7 @@ import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; -public class BrowserChooserComp extends SimpleComp { +public class BrowserChooserComp extends DialogComp { private final BrowserFileChooserModel model; @@ -52,24 +48,16 @@ public class BrowserChooserComp extends SimpleComp { Supplier> store, Consumer file, boolean save) { PlatformThread.runLaterIfNeeded(() -> { var model = new BrowserFileChooserModel(OpenFileSystemModel.SelectionMode.SINGLE_FILE); - var comp = new BrowserChooserComp(model) - .apply(struc -> struc.get().setPrefSize(1200, 700)) - .apply(struc -> AppFont.normal(struc.get())); - var window = AppWindowHelper.sideWindow( - AppI18n.get(save ? "saveFileTitle" : "openFileTitle"), - stage -> { - return comp; - }, - false, - null); + DialogComp.showWindow(save ? "saveFileTitle" : "openFileTitle", stage -> { + var comp = new BrowserChooserComp(model); + comp.apply(struc -> struc.get().setPrefSize(1200, 700)) + .apply(struc -> AppFont.normal(struc.get())) + .styleClass("browser") + .styleClass("chooser"); + return comp; + }); model.setOnFinish(fileStores -> { file.accept(fileStores.size() > 0 ? fileStores.getFirst() : null); - window.close(); - }); - window.show(); - window.setOnHidden(event -> { - model.finishWithoutChoice(); - event.consume(); }); ThreadHelper.runAsync(() -> { model.openFileSystemAsync(store.get(), null, null); @@ -78,7 +66,27 @@ public class BrowserChooserComp extends SimpleComp { } @Override - protected Region createSimple() { + protected String finishKey() { + return "select"; + } + + @Override + protected Comp pane(Comp content) { + return content; + } + + @Override + protected void finish() { + model.finishChooser(); + } + + @Override + protected void discard() { + model.finishWithoutChoice(); + } + + @Override + public Comp content() { Predicate applicable = storeEntryWrapper -> { return (storeEntryWrapper.getEntry().getStore() instanceof ShellStore) && storeEntryWrapper.getEntry().getValidity().isUsable(); @@ -96,7 +104,7 @@ public class BrowserChooserComp extends SimpleComp { return; } - if (entry.getStore() instanceof ShellStore fileSystem) { + if (entry.getStore() instanceof ShellStore) { model.openFileSystemAsync(entry.ref(), null, busy); } }); @@ -144,60 +152,33 @@ public class BrowserChooserComp extends SimpleComp { struc.getLeft().setMinWidth(200); struc.getLeft().setMaxWidth(500); }); + return splitPane; + } - var dialogPane = new DialogComp() { - - @Override - protected String finishKey() { - return "select"; - } - - @Override - protected Comp pane(Comp content) { - return content; - } - - @Override - protected void finish() { - model.finishChooser(); - } - - @Override - public Comp content() { - return splitPane; - } - - @Override - public Comp bottom() { - return Comp.of(() -> { - var selected = new HBox(); - selected.setAlignment(Pos.CENTER_LEFT); - model.getFileSelection().addListener((ListChangeListener) c -> { - PlatformThread.runLaterIfNeeded(() -> { - selected.getChildren() - .setAll(c.getList().stream() - .map(s -> { - var field = new TextField( - s.getRawFileEntry().getPath()); - field.setEditable(false); - field.getStyleClass().add("chooser-selection"); - HBox.setHgrow(field, Priority.ALWAYS); - return field; - }) - .toList()); - }); - }); - var bottomBar = new HBox(selected); - HBox.setHgrow(selected, Priority.ALWAYS); - bottomBar.setAlignment(Pos.CENTER); - return bottomBar; + @Override + public Comp bottom() { + return Comp.of(() -> { + var selected = new HBox(); + selected.setAlignment(Pos.CENTER_LEFT); + model.getFileSelection().addListener((ListChangeListener) c -> { + PlatformThread.runLaterIfNeeded(() -> { + selected.getChildren() + .setAll(c.getList().stream() + .map(s -> { + var field = new TextField( + s.getRawFileEntry().getPath()); + field.setEditable(false); + field.getStyleClass().add("chooser-selection"); + HBox.setHgrow(field, Priority.ALWAYS); + return field; + }) + .toList()); }); - } - }; - - var r = dialogPane.createRegion(); - r.getStyleClass().add("browser"); - r.getStyleClass().add("chooser"); - return r; + }); + var bottomBar = new HBox(selected); + HBox.setHgrow(selected, Priority.ALWAYS); + bottomBar.setAlignment(Pos.CENTER); + return bottomBar; + }); } } diff --git a/app/src/main/java/io/xpipe/app/browser/session/BrowserSessionModel.java b/app/src/main/java/io/xpipe/app/browser/session/BrowserSessionModel.java index 4063dc75a..3fdc6fa43 100644 --- a/app/src/main/java/io/xpipe/app/browser/session/BrowserSessionModel.java +++ b/app/src/main/java/io/xpipe/app/browser/session/BrowserSessionModel.java @@ -51,11 +51,12 @@ public class BrowserSessionModel extends BrowserAbstractSessionModel(sessionEntries)) { // Don't close busy connections gracefully // as we otherwise might lock up - if (o.canImmediatelyClose()) { + if (!o.canImmediatelyClose()) { continue; } - closeSync(o); + // Prevent blocking of shutdown + closeAsync(o); } BrowserSavedStateImpl.get().save(); } diff --git a/app/src/main/java/io/xpipe/app/browser/session/BrowserSessionTabsComp.java b/app/src/main/java/io/xpipe/app/browser/session/BrowserSessionTabsComp.java index 9a1331273..e4cb2ef1a 100644 --- a/app/src/main/java/io/xpipe/app/browser/session/BrowserSessionTabsComp.java +++ b/app/src/main/java/io/xpipe/app/browser/session/BrowserSessionTabsComp.java @@ -9,6 +9,7 @@ import io.xpipe.app.fxcomps.impl.PrettyImageHelper; import io.xpipe.app.fxcomps.impl.TooltipAugment; import io.xpipe.app.fxcomps.util.LabelGraphic; import io.xpipe.app.fxcomps.util.PlatformThread; +import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.storage.DataStorage; import io.xpipe.app.util.BooleanScope; import io.xpipe.app.util.ContextMenuHelper; @@ -238,7 +239,6 @@ public class BrowserSessionTabsComp extends SimpleComp { % tabs.getTabs().size(); tabs.getSelectionModel().select(previous); keyEvent.consume(); - return; } }); @@ -329,12 +329,14 @@ public class BrowserSessionTabsComp extends SimpleComp { ring.setMaxSize(16, 16); ring.progressProperty() .bind(Bindings.createDoubleBinding( - () -> model.getBusy().get() ? -1d : 0, PlatformThread.sync(model.getBusy()))); + () -> model.getBusy().get() + && !AppPrefs.get().performanceMode().get() + ? -1d + : 0, + PlatformThread.sync(model.getBusy()), + AppPrefs.get().performanceMode())); - var image = model.getEntry() - .get() - .getProvider() - .getDisplayIconFileName(model.getEntry().getStore()); + var image = model.getEntry().get().getEffectiveIconFile(); var logo = PrettyImageHelper.ofFixedSizeSquare(image, 16).createRegion(); tab.graphicProperty() diff --git a/app/src/main/java/io/xpipe/app/comp/AppLayoutComp.java b/app/src/main/java/io/xpipe/app/comp/AppLayoutComp.java index 32c419d36..58eac8921 100644 --- a/app/src/main/java/io/xpipe/app/comp/AppLayoutComp.java +++ b/app/src/main/java/io/xpipe/app/comp/AppLayoutComp.java @@ -11,6 +11,7 @@ import io.xpipe.app.fxcomps.SimpleCompStructure; import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.storage.DataStorage; +import io.xpipe.app.util.TerminalView; import javafx.beans.binding.Bindings; import javafx.beans.value.ObservableValue; import javafx.scene.Parent; @@ -49,14 +50,16 @@ public class AppLayoutComp extends Comp> { var sidebarR = sidebar.createRegion(); pane.setRight(sidebarR); model.getSelected().addListener((c, o, n) -> { - if (o != null && o.equals(model.getEntries().get(2))) { + if (o != null && o.equals(model.getEntries().get(3))) { AppPrefs.get().save(); DataStorage.get().saveAsync(); } - if (o != null && o.equals(model.getEntries().get(1))) { + if (o != null && o.equals(model.getEntries().get(0))) { StoreViewState.get().updateDisplay(); } + + TerminalView.get().toggleView(model.getEntries().get(2).equals(n)); }); pane.addEventHandler(KeyEvent.KEY_PRESSED, event -> { sidebarR.getChildrenUnmodifiable().forEach(node -> { @@ -64,7 +67,6 @@ public class AppLayoutComp extends Comp> { if (shortcut != null && shortcut.match(event)) { ((ButtonBase) ((Parent) node).getChildrenUnmodifiable().get(1)).fire(); event.consume(); - return; } }); }); diff --git a/app/src/main/java/io/xpipe/app/comp/base/DialogComp.java b/app/src/main/java/io/xpipe/app/comp/base/DialogComp.java index a5963378f..782bc981b 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/DialogComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/DialogComp.java @@ -20,22 +20,30 @@ import javafx.stage.Stage; import atlantafx.base.theme.Styles; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; public abstract class DialogComp extends Comp> { public static void showWindow(String titleKey, Function f) { var loading = new SimpleBooleanProperty(); + var dialog = new AtomicReference(); Platform.runLater(() -> { var stage = AppWindowHelper.sideWindow( AppI18n.get(titleKey), window -> { var c = f.apply(window); + dialog.set(c); loading.bind(c.busy()); return c; }, false, loading); + stage.setOnCloseRequest(event -> { + if (dialog.get() != null) { + dialog.get().discard(); + } + }); stage.show(); }); } @@ -60,12 +68,16 @@ public abstract class DialogComp extends Comp> { .addAll(customButtons().stream() .map(buttonComp -> buttonComp.createRegion()) .toList()); - var nextButton = new ButtonComp(AppI18n.observable(finishKey()), null, this::finish) + var nextButton = finishButton(); + buttons.getChildren().add(nextButton.createRegion()); + return buttons; + } + + protected Comp finishButton() { + return new ButtonComp(AppI18n.observable(finishKey()), null, this::finish) .apply(struc -> struc.get().setDefaultButton(true)) .styleClass(Styles.ACCENT) .styleClass("next"); - buttons.getChildren().add(nextButton.createRegion()); - return buttons; } protected String finishKey() { @@ -93,6 +105,8 @@ public abstract class DialogComp extends Comp> { protected abstract void finish(); + protected abstract void discard(); + public abstract Comp content(); protected Comp pane(Comp content) { diff --git a/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java b/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java index cc4921cac..f013c329b 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java @@ -26,6 +26,8 @@ public class ListBoxViewComp extends Comp> { private static final PseudoClass ODD = PseudoClass.getPseudoClass("odd"); private static final PseudoClass EVEN = PseudoClass.getPseudoClass("even"); + private static final PseudoClass FIRST = PseudoClass.getPseudoClass("first"); + private static final PseudoClass LAST = PseudoClass.getPseudoClass("last"); private final ObservableList shown; private final ObservableList all; @@ -114,9 +116,10 @@ public class ListBoxViewComp extends Comp> { for (int i = 0; i < newShown.size(); i++) { var r = newShown.get(i); - r.pseudoClassStateChanged(ODD, false); - r.pseudoClassStateChanged(EVEN, false); - r.pseudoClassStateChanged(i % 2 == 0 ? EVEN : ODD, true); + r.pseudoClassStateChanged(ODD, i % 2 != 0); + r.pseudoClassStateChanged(EVEN, i % 2 == 0); + r.pseudoClassStateChanged(FIRST, i == 0); + r.pseudoClassStateChanged(LAST, i == newShown.size() - 1); } var d = new DerivedObservableList<>(listView.getChildren(), true); diff --git a/app/src/main/java/io/xpipe/app/comp/base/MarkdownComp.java b/app/src/main/java/io/xpipe/app/comp/base/MarkdownComp.java index b977727df..cec482fbe 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/MarkdownComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/MarkdownComp.java @@ -1,13 +1,13 @@ package io.xpipe.app.comp.base; import io.xpipe.app.core.AppProperties; -import io.xpipe.app.core.AppResources; import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.fxcomps.CompStructure; import io.xpipe.app.fxcomps.SimpleCompStructure; import io.xpipe.app.fxcomps.util.PlatformThread; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.prefs.AppPrefs; +import io.xpipe.app.resources.AppResources; import io.xpipe.app.util.Hyperlinks; import io.xpipe.app.util.MarkdownHelper; import io.xpipe.app.util.ShellTemp; diff --git a/app/src/main/java/io/xpipe/app/comp/base/OsLogoComp.java b/app/src/main/java/io/xpipe/app/comp/base/OsLogoComp.java index 74cf6a2b0..288cb31ff 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/OsLogoComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/OsLogoComp.java @@ -1,11 +1,11 @@ package io.xpipe.app.comp.base; import io.xpipe.app.comp.store.StoreEntryWrapper; -import io.xpipe.app.core.AppResources; import io.xpipe.app.fxcomps.SimpleComp; -import io.xpipe.app.fxcomps.impl.PrettyImageComp; +import io.xpipe.app.fxcomps.impl.PrettyImageHelper; import io.xpipe.app.fxcomps.impl.StackComp; import io.xpipe.app.fxcomps.util.BindingsHelper; +import io.xpipe.app.resources.AppResources; import io.xpipe.core.process.OsNameState; import io.xpipe.core.store.FileNames; @@ -22,8 +22,7 @@ import java.util.Map; public class OsLogoComp extends SimpleComp { private static final Map ICONS = new HashMap<>(); - private static final String LINUX_DEFAULT = "linux-24.png"; - private static final String LINUX_DEFAULT_SVG = "linux.svg"; + private static final String LINUX_DEFAULT_24 = "linux-24.png"; private final StoreEntryWrapper wrapper; private final ObservableValue state; @@ -54,8 +53,9 @@ public class OsLogoComp extends SimpleComp { wrapper.getPersistentState(), state); var hide = BindingsHelper.map(img, s -> s != null); - return new StackComp( - List.of(new SystemStateComp(state).hide(hide), new PrettyImageComp(img, 24, 24).visible(hide))) + return new StackComp(List.of( + new SystemStateComp(state).hide(hide), + PrettyImageHelper.ofFixedSize(img, 24, 24).visible(hide))) .createRegion(); } @@ -67,11 +67,12 @@ public class OsLogoComp extends SimpleComp { if (ICONS.isEmpty()) { AppResources.with(AppResources.XPIPE_MODULE, "img/os", file -> { try (var list = Files.list(file)) { - list.filter(path -> path.toString().endsWith(".svg") - && !path.toString().endsWith(LINUX_DEFAULT_SVG)) + list.filter(path -> path.toString().endsWith(".png") + && !path.toString().endsWith(LINUX_DEFAULT_24) + && !path.toString().endsWith("-40.png")) .map(path -> FileNames.getFileName(path.toString())) .forEach(path -> { - var base = FileNames.getBaseName(path).replace("-dark", "") + "-24.png"; + var base = path.replace("-dark", "").replace("-24.png", ".svg"); ICONS.put(FileNames.getBaseName(base).split("-")[0], "os/" + base); }); } @@ -82,6 +83,6 @@ public class OsLogoComp extends SimpleComp { .filter(e -> name.toLowerCase().contains(e.getKey())) .findAny() .map(e -> e.getValue()) - .orElse("os/" + LINUX_DEFAULT); + .orElse("os/linux.svg"); } } diff --git a/app/src/main/java/io/xpipe/app/comp/base/TerminalViewDockComp.java b/app/src/main/java/io/xpipe/app/comp/base/TerminalViewDockComp.java new file mode 100644 index 000000000..5ea657e96 --- /dev/null +++ b/app/src/main/java/io/xpipe/app/comp/base/TerminalViewDockComp.java @@ -0,0 +1,67 @@ +package io.xpipe.app.comp.base; + +import io.xpipe.app.core.AppI18n; +import io.xpipe.app.core.window.AppMainWindow; +import io.xpipe.app.fxcomps.SimpleComp; +import io.xpipe.app.util.TerminalView; +import javafx.geometry.Pos; +import javafx.scene.Cursor; +import javafx.scene.control.Label; +import javafx.scene.layout.Region; +import javafx.scene.layout.StackPane; +import javafx.stage.WindowEvent; + +public class TerminalViewDockComp extends SimpleComp { + + @Override + protected Region createSimple() { + var label = new Label(); + label.textProperty().bind(AppI18n.observable("clickToDock")); + var stack = new StackPane(label); + stack.setAlignment(Pos.CENTER); + stack.setCursor(Cursor.HAND); + stack.boundsInParentProperty().addListener((observable, oldValue, newValue) -> { + update(stack); + }); + var s = AppMainWindow.getInstance().getStage(); + s.xProperty().addListener((observable, oldValue, newValue) -> { + update(stack); + }); + s.yProperty().addListener((observable, oldValue, newValue) -> { + update(stack); + }); + s.widthProperty().addListener((observable, oldValue, newValue) -> { + update(stack); + }); + s.heightProperty().addListener((observable, oldValue, newValue) -> { + update(stack); + }); + s.iconifiedProperty().addListener((observable, oldValue, newValue) -> { + if (newValue) { + TerminalView.get().onMinimize(); + } else { + TerminalView.get().onFocusGain(); + } + }); + s.focusedProperty().addListener((observable, oldValue, newValue) -> { + if (newValue) { + TerminalView.get().onFocusGain(); + } else { + TerminalView.get().onFocusLost(); + } + }); + s.addEventFilter(WindowEvent.WINDOW_HIDDEN,event -> { + TerminalView.get().onClose(); + }); + stack.setOnMouseClicked(event -> { + TerminalView.get().clickView(); + event.consume(); + }); + return stack; + } + + private void update(Region region) { + var bounds = region.localToScreen(region.getBoundsInLocal()); + TerminalView.get().resizeView((int) bounds.getMinX(), (int) bounds.getMinY(),(int) bounds.getWidth(), (int) bounds.getHeight()); + } +} diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreCreationComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreCreationComp.java index c2c97fbbf..e0dd41b68 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreCreationComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreCreationComp.java @@ -20,6 +20,7 @@ import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; import io.xpipe.app.util.*; import io.xpipe.core.store.DataStore; +import io.xpipe.core.store.ValidationContext; import io.xpipe.core.util.ValidationException; import javafx.application.Platform; @@ -42,14 +43,13 @@ import net.synedra.validatorfx.GraphicDecorationStackPane; import java.util.List; import java.util.Objects; import java.util.UUID; -import java.util.function.BiConsumer; import java.util.function.Predicate; @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) public class StoreCreationComp extends DialogComp { Stage window; - BiConsumer consumer; + CreationConsumer consumer; Property provider; ObjectProperty store; Predicate filter; @@ -67,7 +67,7 @@ public class StoreCreationComp extends DialogComp { public StoreCreationComp( Stage window, - BiConsumer consumer, + CreationConsumer consumer, Property provider, ObjectProperty store, Predicate filter, @@ -165,8 +165,11 @@ public class StoreCreationComp extends DialogComp { e.getProvider(), e.getStore(), v -> true, - (newE, validated) -> { + (newE, context, validated) -> { ThreadHelper.runAsync(() -> { + if (context != null) { + context.close(); + } if (!DataStorage.get().getStoreEntries().contains(e)) { DataStorage.get().addStoreEntryIfNotPresent(newE); } else { @@ -193,15 +196,16 @@ public class StoreCreationComp extends DialogComp { base != null ? DataStoreProviders.byStore(base) : null, base, dataStoreProvider -> category.equals(dataStoreProvider.getCreationCategory()), - (e, validated) -> { + (e, context, validated) -> { try { DataStorage.get().addStoreEntryIfNotPresent(e); - if (validated + if (context != null + && validated && e.getProvider().shouldShowScan() && AppPrefs.get() .openConnectionSearchWindowOnConnectionCreation() .get()) { - ScanAlert.showAsync(e); + ScanAlert.showAsync(e, context); } } catch (Exception ex) { ErrorEvent.fromThrowable(ex).handle(); @@ -211,12 +215,17 @@ public class StoreCreationComp extends DialogComp { null); } + public interface CreationConsumer { + + void consume(DataStoreEntry entry, ValidationContext validationContext, boolean validated); + } + private static void show( String initialName, DataStoreProvider provider, DataStore s, Predicate filter, - BiConsumer con, + CreationConsumer con, boolean staticDisplay, DataStoreEntry existingEntry) { var prop = new SimpleObjectProperty<>(provider); @@ -247,7 +256,7 @@ public class StoreCreationComp extends DialogComp { return List.of( new ButtonComp(AppI18n.observable("skip"), null, () -> { if (showInvalidConfirmAlert()) { - commit(false); + commit(null, false); } else { finish(); } @@ -275,6 +284,9 @@ public class StoreCreationComp extends DialogComp { return busy; } + @Override + protected void discard() {} + @Override protected void finish() { if (finished.get()) { @@ -287,7 +299,7 @@ public class StoreCreationComp extends DialogComp { // We didn't change anything if (existingEntry != null && existingEntry.getStore().equals(store.getValue())) { - commit(false); + commit(null, false); return; } @@ -315,10 +327,10 @@ public class StoreCreationComp extends DialogComp { return; } - try (var b = new BooleanScope(busy).start()) { + try (var ignored = new BooleanScope(busy).start()) { DataStorage.get().addStoreEntryInProgress(entry.getValue()); - entry.getValue().validateOrThrow(); - commit(true); + var context = entry.getValue().validateAndKeepOpenOrThrowAndClose(null); + commit(context, true); } catch (Throwable ex) { if (ex instanceof ValidationException) { ErrorEvent.expected(ex); @@ -403,14 +415,14 @@ public class StoreCreationComp extends DialogComp { .createRegion(); } - private void commit(boolean validated) { + private void commit(ValidationContext validationContext, boolean validated) { if (finished.get()) { return; } finished.setValue(true); if (entry.getValue() != null) { - consumer.accept(entry.getValue(), validated); + consumer.consume(entry.getValue(), validationContext, validated); } PlatformThread.runLaterIfNeeded(() -> { diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreCreationMenu.java b/app/src/main/java/io/xpipe/app/comp/store/StoreCreationMenu.java index 13ad741f3..df546265f 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreCreationMenu.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreCreationMenu.java @@ -22,7 +22,7 @@ public class StoreCreationMenu { automatically.setGraphic(new FontIcon("mdi2e-eye-plus-outline")); automatically.textProperty().bind(AppI18n.observable("addAutomatically")); automatically.setOnAction(event -> { - ScanAlert.showAsync(null); + ScanAlert.showAsync(null, null); event.consume(); }); menu.getItems().add(automatically); @@ -32,17 +32,21 @@ public class StoreCreationMenu { menu.getItems().add(category("addDesktop", "mdi2c-camera-plus", DataStoreCreationCategory.DESKTOP, null)); - menu.getItems().add(category("addShell", "mdi2t-text-box-multiple", DataStoreCreationCategory.SHELL, "shellEnvironment")); + menu.getItems() + .add(category( + "addShell", "mdi2t-text-box-multiple", DataStoreCreationCategory.SHELL, "shellEnvironment")); menu.getItems() .add(category("addScript", "mdi2s-script-text-outline", DataStoreCreationCategory.SCRIPT, "script")); menu.getItems() - .add(category("addTunnel", "mdi2v-vector-polyline-plus", DataStoreCreationCategory.TUNNEL, "customService")); + .add(category( + "addTunnel", "mdi2v-vector-polyline-plus", DataStoreCreationCategory.TUNNEL, "customService")); menu.getItems().add(category("addSerial", "mdi2s-serial-port", DataStoreCreationCategory.SERIAL, "serial")); - // menu.getItems().add(category("addDatabase", "mdi2d-database-plus", DataStoreCreationCategory.DATABASE, null)); + // menu.getItems().add(category("addDatabase", "mdi2d-database-plus", DataStoreCreationCategory.DATABASE, + // null)); } private static MenuItem category( @@ -85,8 +89,7 @@ public class StoreCreationMenu { .sorted(Comparator.comparingInt(dataStoreProvider -> dataStoreProvider.getOrderPriority())) .toList(); int lastOrder = providers.getFirst().getOrderPriority(); - for (int i = 0; i < providers.size(); i++) { - var dataStoreProvider = providers.get(i); + for (io.xpipe.app.ext.DataStoreProvider dataStoreProvider : providers) { if (dataStoreProvider.getOrderPriority() != lastOrder) { menu.getItems().add(new SeparatorMenuItem()); lastOrder = dataStoreProvider.getOrderPriority(); 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 94883bd98..7f74eeafe 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 @@ -10,12 +10,12 @@ import io.xpipe.app.fxcomps.augment.ContextMenuAugment; import io.xpipe.app.fxcomps.augment.GrowAugment; import io.xpipe.app.fxcomps.impl.IconButtonComp; import io.xpipe.app.fxcomps.impl.LabelComp; -import io.xpipe.app.fxcomps.impl.PrettyImageHelper; import io.xpipe.app.fxcomps.impl.TooltipAugment; import io.xpipe.app.fxcomps.util.BindingsHelper; import io.xpipe.app.fxcomps.util.DerivedObservableList; import io.xpipe.app.fxcomps.util.PlatformThread; import io.xpipe.app.prefs.AppPrefs; +import io.xpipe.app.resources.AppResources; import io.xpipe.app.storage.DataColor; import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; @@ -33,7 +33,6 @@ import javafx.scene.control.*; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; import javafx.scene.layout.Region; -import javafx.scene.layout.StackPane; import atlantafx.base.layout.InputGroup; import atlantafx.base.theme.Styles; @@ -192,26 +191,7 @@ public abstract class StoreEntryComp extends SimpleComp { } protected Node createIcon(int w, int h) { - var img = getWrapper().disabledProperty().get() - ? "disabled_icon.png" - : getWrapper() - .getEntry() - .getProvider() - .getDisplayIconFileName(getWrapper().getEntry().getStore()); - var imageComp = PrettyImageHelper.ofFixedSize(img, w, h); - var storeIcon = imageComp.createRegion(); - if (getWrapper().getValidity().getValue().isUsable()) { - new TooltipAugment<>(getWrapper().getEntry().getProvider().displayName(), null).augment(storeIcon); - } - - var stack = new StackPane(storeIcon); - stack.setMinHeight(w + 7); - stack.setMinWidth(w + 7); - stack.setMaxHeight(w + 7); - stack.setMaxWidth(w + 7); - stack.getStyleClass().add("icon"); - stack.setAlignment(Pos.CENTER); - return stack; + return new StoreIconComp(getWrapper(), w, h).createRegion(); } protected Region createButtonBar() { @@ -265,12 +245,14 @@ public abstract class StoreEntryComp extends SimpleComp { button.apply(new ContextMenuAugment<>( mouseEvent -> mouseEvent.getButton() == MouseButton.PRIMARY, keyEvent -> false, () -> { var cm = ContextMenuHelper.create(); - branch.getChildren(getWrapper().getEntry().ref()).forEach(childProvider -> { - var menu = buildMenuItemForAction(childProvider); - if (menu != null) { - cm.getItems().add(menu); - } - }); + branch.getChildren(getWrapper().getEntry().ref()).stream() + .filter(actionProvider -> getWrapper().showActionProvider(actionProvider)) + .forEach(childProvider -> { + var menu = buildMenuItemForAction(childProvider); + if (menu != null) { + cm.getItems().add(menu); + } + }); return cm; })); } @@ -341,14 +323,16 @@ public abstract class StoreEntryComp extends SimpleComp { if (DataStorage.get().isRootEntry(getWrapper().getEntry())) { var color = new Menu(AppI18n.get("color"), new FontIcon("mdi2f-format-color-fill")); - var none = new MenuItem("None"); + var none = new MenuItem(); + none.textProperty().bind(AppI18n.observable("none")); none.setOnAction(event -> { getWrapper().getEntry().setColor(null); event.consume(); }); color.getItems().add(none); Arrays.stream(DataColor.values()).forEach(dataStoreColor -> { - MenuItem m = new MenuItem(DataStoreFormatter.capitalize(dataStoreColor.getId())); + MenuItem m = new MenuItem(); + m.textProperty().bind(AppI18n.observable(dataStoreColor.getId())); m.setOnAction(event -> { getWrapper().getEntry().setColor(dataStoreColor); event.consume(); @@ -463,6 +447,7 @@ public abstract class StoreEntryComp extends SimpleComp { if (branch != null) { var items = branch.getChildren(getWrapper().getEntry().ref()).stream() + .filter(actionProvider -> getWrapper().showActionProvider(actionProvider)) .map(c -> buildMenuItemForAction(c)) .toList(); menu.getItems().addAll(items); @@ -475,6 +460,7 @@ public abstract class StoreEntryComp extends SimpleComp { getWrapper() .runAction(leaf.createAction(getWrapper().getEntry().ref()), leaf.showBusy()); }); + event.consume(); }); menu.getItems().add(run); @@ -493,6 +479,7 @@ public abstract class StoreEntryComp extends SimpleComp { .getName(getWrapper().getEntry().ref()) .getValue() + ")"); }); + event.consume(); }); menu.getItems().add(sc); @@ -504,6 +491,7 @@ public abstract class StoreEntryComp extends SimpleComp { AppActionLinkDetector.setLastDetectedAction(url); ClipboardHelper.copyUrl(url); }); + event.consume(); }); menu.getItems().add(l); } @@ -518,10 +506,13 @@ public abstract class StoreEntryComp extends SimpleComp { return; } - event.consume(); ThreadHelper.runFailableAsync(() -> { getWrapper().runAction(leaf.createAction(getWrapper().getEntry().ref()), leaf.showBusy()); }); + event.consume(); + if (event.getTarget() instanceof Menu m) { + m.getParentPopup().hide(); + } }); return item; diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryListComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryListComp.java index 53b775696..71474e3f7 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryListComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryListComp.java @@ -2,6 +2,7 @@ package io.xpipe.app.comp.store; import io.xpipe.app.comp.base.ListBoxViewComp; import io.xpipe.app.comp.base.MultiContentComp; +import io.xpipe.app.core.AppLayoutModel; import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.fxcomps.SimpleComp; @@ -34,6 +35,12 @@ public class StoreEntryListComp extends SimpleComp { struc.get().setVvalue(0); }); }); + content.apply(struc -> { + // Reset scroll + AppLayoutModel.get().getSelected().addListener((observable, oldValue, newValue) -> { + struc.get().setVvalue(0); + }); + }); return content.styleClass("store-list-comp"); } @@ -44,7 +51,8 @@ public class StoreEntryListComp extends SimpleComp { () -> { var allCat = StoreViewState.get().getAllConnectionsCategory(); var connections = StoreViewState.get().getAllEntries().getList().stream() - .filter(wrapper -> allCat.equals(wrapper.getCategory().getValue().getRoot())) + .filter(wrapper -> allCat.equals( + wrapper.getCategory().getValue().getRoot())) .toList(); return initialCount == connections.size() && StoreViewState.get() diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryListOverviewComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryListOverviewComp.java index 62440566c..92a3640b5 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryListOverviewComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryListOverviewComp.java @@ -8,6 +8,7 @@ import io.xpipe.app.fxcomps.SimpleComp; import io.xpipe.app.fxcomps.impl.FilterComp; import io.xpipe.app.fxcomps.impl.IconButtonComp; import io.xpipe.app.fxcomps.util.BindingsHelper; +import io.xpipe.app.fxcomps.util.LabelGraphic; import io.xpipe.app.util.ThreadHelper; import io.xpipe.core.process.OsType; @@ -72,8 +73,13 @@ public class StoreEntryListOverviewComp extends SimpleComp { // But it is good enough. var showProvider = true; try { - showProvider = storeEntryWrapper.getEntry().getProvider().shouldShow(storeEntryWrapper); - } catch (Exception ignored) {} + showProvider = storeEntryWrapper.getEntry().getProvider() == null + || storeEntryWrapper + .getEntry() + .getProvider() + .shouldShow(storeEntryWrapper); + } catch (Exception ignored) { + } return inRootCategory && showProvider; }, StoreViewState.get().getActiveCategory()); @@ -143,15 +149,15 @@ public class StoreEntryListOverviewComp extends SimpleComp { } private Comp createAlphabeticalSortButton() { - var icon = Bindings.createStringBinding( + var icon = Bindings.createObjectBinding( () -> { if (sortMode.getValue() == StoreSortMode.ALPHABETICAL_ASC) { - return "mdi2s-sort-alphabetical-descending"; + return new LabelGraphic.IconGraphic("mdi2s-sort-alphabetical-descending"); } if (sortMode.getValue() == StoreSortMode.ALPHABETICAL_DESC) { - return "mdi2s-sort-alphabetical-ascending"; + return new LabelGraphic.IconGraphic("mdi2s-sort-alphabetical-ascending"); } - return "mdi2s-sort-alphabetical-descending"; + return new LabelGraphic.IconGraphic("mdi2s-sort-alphabetical-descending"); }, sortMode); var alphabetical = new IconButtonComp(icon, () -> { @@ -184,15 +190,15 @@ public class StoreEntryListOverviewComp extends SimpleComp { } private Comp createDateSortButton() { - var icon = Bindings.createStringBinding( + var icon = Bindings.createObjectBinding( () -> { if (sortMode.getValue() == StoreSortMode.DATE_ASC) { - return "mdi2s-sort-clock-ascending-outline"; + return new LabelGraphic.IconGraphic("mdi2s-sort-clock-ascending-outline"); } if (sortMode.getValue() == StoreSortMode.DATE_DESC) { - return "mdi2s-sort-clock-descending-outline"; + return new LabelGraphic.IconGraphic("mdi2s-sort-clock-descending-outline"); } - return "mdi2s-sort-clock-ascending-outline"; + return new LabelGraphic.IconGraphic("mdi2s-sort-clock-ascending-outline"); }, sortMode); var date = new IconButtonComp(icon, () -> { diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryWrapper.java b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryWrapper.java index adb9cce0e..4e43f2087 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryWrapper.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryWrapper.java @@ -17,7 +17,9 @@ import lombok.Getter; import java.time.Duration; import java.time.Instant; -import java.util.*; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; @Getter public class StoreEntryWrapper { @@ -40,6 +42,8 @@ public class StoreEntryWrapper { private final Property category = new SimpleObjectProperty<>(); private final Property summary = new SimpleObjectProperty<>(); private final Property notes; + private final Property customIcon = new SimpleObjectProperty<>(); + private final Property iconFile = new SimpleObjectProperty<>(); public StoreEntryWrapper(DataStoreEntry entry) { this.entry = entry; @@ -137,6 +141,8 @@ public class StoreEntryWrapper { } color.setValue(entry.getColor()); notes.setValue(new StoreNotes(entry.getNotes(), entry.getNotes())); + customIcon.setValue(entry.getIcon()); + iconFile.setValue(entry.getEffectiveIconFile()); busy.setValue(entry.getBusyCounter().get() != 0); deletable.setValue(entry.getConfiguration().isDeletable() @@ -191,7 +197,7 @@ public class StoreEntryWrapper { } } - private boolean showActionProvider(ActionProvider p) { + public boolean showActionProvider(ActionProvider p) { var leaf = p.getLeafDataStoreCallSite(); if (leaf != null) { return (entry.getValidity().isUsable() || (!leaf.requiresValidStore() && entry.getProvider() != null)) @@ -214,7 +220,7 @@ public class StoreEntryWrapper { } public void refreshChildren() { - var hasChildren = DataStorage.get().refreshChildren(entry); + var hasChildren = DataStorage.get().refreshChildren(entry, null); PlatformThread.runLaterIfNeeded(() -> { expanded.set(hasChildren); }); diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreIconChoiceComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreIconChoiceComp.java new file mode 100644 index 000000000..d853331b2 --- /dev/null +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreIconChoiceComp.java @@ -0,0 +1,145 @@ +package io.xpipe.app.comp.store; + +import io.xpipe.app.fxcomps.SimpleComp; +import io.xpipe.app.fxcomps.impl.PrettyImageHelper; +import io.xpipe.app.resources.SystemIcon; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.scene.control.*; +import javafx.scene.input.MouseButton; +import javafx.scene.layout.Region; + +import atlantafx.base.theme.Tweaks; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Locale; + +import static atlantafx.base.theme.Styles.TEXT_SMALL; + +public class StoreIconChoiceComp extends SimpleComp { + + private final Property selected; + private final List icons; + private final int columns; + private final SimpleStringProperty filter; + private final Runnable doubleClick; + + public StoreIconChoiceComp( + Property selected, + List icons, + int columns, + SimpleStringProperty filter, + Runnable doubleClick) { + this.selected = selected; + this.icons = icons; + this.columns = columns; + this.filter = filter; + this.doubleClick = doubleClick; + } + + @Override + protected Region createSimple() { + var table = new TableView>(); + initTable(table); + updateData(table, null); + filter.addListener((observable, oldValue, newValue) -> updateData(table, newValue)); + return table; + } + + private void initTable(TableView> table) { + for (int i = 0; i < columns; i++) { + var col = new TableColumn, SystemIcon>("col" + i); + final int colIndex = i; + col.setCellValueFactory(cb -> { + var row = cb.getValue(); + var item = row.size() > colIndex ? row.get(colIndex) : null; + return new SimpleObjectProperty<>(item); + }); + col.setCellFactory(cb -> new IconCell()); + col.getStyleClass().add(Tweaks.ALIGN_CENTER); + table.getColumns().add(col); + } + + table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY_ALL_COLUMNS); + table.getSelectionModel().setCellSelectionEnabled(true); + table.getStyleClass().add("icon-browser"); + table.setPlaceholder(new Region()); + } + + private void updateData(TableView> table, String filterString) { + var displayedIcons = filterString == null || filterString.isBlank() || filterString.length() < 2 + ? icons + : icons.stream() + .filter(icon -> containsString(icon.getDisplayName(), filterString)) + .toList(); + + var data = partitionList(displayedIcons, columns); + table.getItems().setAll(data); + } + + private Collection> partitionList(List list, int size) { + List> partitions = new ArrayList<>(); + if (list.size() == 0) { + return partitions; + } + + int length = list.size(); + int numOfPartitions = length / size + ((length % size == 0) ? 0 : 1); + + for (int i = 0; i < numOfPartitions; i++) { + int from = i * size; + int to = Math.min((i * size + size), length); + partitions.add(list.subList(from, to)); + } + return partitions; + } + + private boolean containsString(String s1, String s2) { + return s1.toLowerCase(Locale.ROOT).contains(s2.toLowerCase(Locale.ROOT)); + } + + public class IconCell extends TableCell, SystemIcon> { + + private final Label root = new Label(); + private final StringProperty image = new SimpleStringProperty(); + + public IconCell() { + super(); + + root.setContentDisplay(ContentDisplay.TOP); + Region imageView = PrettyImageHelper.ofFixedSize(image, 40, 40).createRegion(); + root.setGraphic(imageView); + root.setGraphicTextGap(10); + root.getStyleClass().addAll("icon-label", TEXT_SMALL); + + setOnMouseClicked(event -> { + if (event.getButton() == MouseButton.PRIMARY) { + selected.setValue(getItem()); + } + + if (event.getClickCount() > 1) { + doubleClick.run(); + } + }); + } + + @Override + protected void updateItem(SystemIcon icon, boolean empty) { + super.updateItem(icon, empty); + + if (icon == null) { + setGraphic(null); + return; + } + + root.setText(icon.getDisplayName()); + image.set("app:system/" + icon.getIconName() + ".svg"); + setGraphic(root); + } + } +} diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreIconChoiceDialogComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreIconChoiceDialogComp.java new file mode 100644 index 000000000..d66f1bb25 --- /dev/null +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreIconChoiceDialogComp.java @@ -0,0 +1,99 @@ +package io.xpipe.app.comp.store; + +import io.xpipe.app.comp.base.ButtonComp; +import io.xpipe.app.comp.base.DialogComp; +import io.xpipe.app.core.AppI18n; +import io.xpipe.app.core.window.AppWindowHelper; +import io.xpipe.app.fxcomps.Comp; +import io.xpipe.app.fxcomps.SimpleComp; +import io.xpipe.app.fxcomps.impl.FilterComp; +import io.xpipe.app.fxcomps.impl.HorizontalComp; +import io.xpipe.app.resources.SystemIcon; +import io.xpipe.app.resources.SystemIcons; +import io.xpipe.app.storage.DataStoreEntry; +import io.xpipe.app.util.Hyperlinks; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.scene.layout.Region; +import javafx.stage.Modality; +import javafx.stage.Stage; + +import org.kordamp.ikonli.javafx.FontIcon; + +import java.util.List; + +public class StoreIconChoiceDialogComp extends SimpleComp { + + public static void show(DataStoreEntry entry) { + var window = AppWindowHelper.sideWindow( + AppI18n.get("chooseCustomIcon"), stage -> new StoreIconChoiceDialogComp(entry, stage), false, null); + window.initModality(Modality.APPLICATION_MODAL); + window.show(); + } + + private final ObjectProperty selected = new SimpleObjectProperty<>(); + private final DataStoreEntry entry; + private final Stage dialogStage; + + public StoreIconChoiceDialogComp(DataStoreEntry entry, Stage dialogStage) { + this.entry = entry; + this.dialogStage = dialogStage; + } + + @Override + protected Region createSimple() { + var filterText = new SimpleStringProperty(); + var filter = new FilterComp(filterText).apply(struc -> { + dialogStage.setOnShowing(event -> { + struc.get().requestFocus(); + event.consume(); + }); + }); + var github = new ButtonComp(null, new FontIcon("mdi2g-github"), () -> { + Hyperlinks.open(Hyperlinks.SELFHST_ICONS); + }) + .grow(false, true); + var dialog = new DialogComp() { + @Override + protected void finish() { + entry.setIcon(selected.get() != null ? selected.getValue().getIconName() : null, true); + dialogStage.close(); + } + + @Override + protected void discard() {} + + @Override + public Comp content() { + return new StoreIconChoiceComp(selected, SystemIcons.getSystemIcons(), 5, filterText, () -> { + finish(); + }); + } + + @Override + protected Comp pane(Comp content) { + return content; + } + + @Override + public Comp bottom() { + var clear = new ButtonComp(AppI18n.observable("clear"), () -> { + selected.setValue(null); + finish(); + }) + .grow(false, true); + return new HorizontalComp(List.of(github, filter.hgrow(), clear)).spacing(10); + } + + @Override + protected Comp finishButton() { + return super.finishButton().disable(selected.isNull()); + } + }; + dialog.prefWidth(600); + dialog.prefHeight(600); + return dialog.createRegion(); + } +} diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreIconComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreIconComp.java new file mode 100644 index 000000000..4d7c26095 --- /dev/null +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreIconComp.java @@ -0,0 +1,64 @@ +package io.xpipe.app.comp.store; + +import io.xpipe.app.fxcomps.SimpleComp; +import io.xpipe.app.fxcomps.impl.PrettyImageHelper; +import io.xpipe.app.fxcomps.impl.TooltipAugment; + +import javafx.beans.binding.Bindings; +import javafx.geometry.Pos; +import javafx.scene.input.MouseButton; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.Region; +import javafx.scene.layout.StackPane; + +import lombok.AllArgsConstructor; +import org.kordamp.ikonli.javafx.FontIcon; + +@AllArgsConstructor +public class StoreIconComp extends SimpleComp { + + private final StoreEntryWrapper wrapper; + private final int w; + private final int h; + + @Override + protected Region createSimple() { + var imageComp = PrettyImageHelper.ofFixedSize(wrapper.getIconFile(), w, h); + var storeIcon = imageComp.createRegion(); + if (wrapper.getValidity().getValue().isUsable()) { + new TooltipAugment<>(wrapper.getEntry().getProvider().displayName(), null).augment(storeIcon); + } + + var background = new Region(); + background.getStyleClass().add("background"); + + var dots = new FontIcon("mdi2d-dots-horizontal"); + dots.setIconSize((int) (h * 1.3)); + + var stack = new StackPane(background, storeIcon, dots); + stack.setMinHeight(w + 7); + stack.setMinWidth(w + 7); + stack.setMaxHeight(w + 7); + stack.setMaxWidth(w + 7); + stack.getStyleClass().add("icon"); + stack.setAlignment(Pos.CENTER); + + dots.visibleProperty().bind(stack.hoverProperty()); + storeIcon + .opacityProperty() + .bind(Bindings.createDoubleBinding( + () -> { + return stack.isHover() ? 0.5 : 1.0; + }, + stack.hoverProperty())); + + stack.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> { + if (event.getButton() == MouseButton.PRIMARY) { + StoreIconChoiceDialogComp.show(wrapper.getEntry()); + event.consume(); + } + }); + + return stack; + } +} diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreIntroComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreIntroComp.java index 60719766a..c427fca82 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreIntroComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreIntroComp.java @@ -39,12 +39,12 @@ public class StoreIntroComp extends SimpleComp { var scanButton = new Button(null, new FontIcon("mdi2m-magnify")); scanButton.textProperty().bind(AppI18n.observable("detectConnections")); - scanButton.setOnAction(event -> ScanAlert.showAsync(DataStorage.get().local())); + scanButton.setOnAction(event -> ScanAlert.showAsync(DataStorage.get().local(), null)); scanButton.setDefaultButton(true); var scanPane = new StackPane(scanButton); scanPane.setAlignment(Pos.CENTER); - var img = new PrettySvgComp(new SimpleStringProperty("Wave.svg"), 80, 150).createRegion(); + var img = new PrettySvgComp(new SimpleStringProperty("graphics/Wave.svg"), 80, 150).createRegion(); var text = new VBox(title, introDesc); text.setSpacing(5); text.setAlignment(Pos.CENTER_LEFT); diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreNotesComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreNotesComp.java index 35431fb16..654ede6df 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreNotesComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreNotesComp.java @@ -96,6 +96,9 @@ public class StoreNotesComp extends Comp { ref.get().hide(); } + @Override + protected void discard() {} + @Override protected String finishKey() { return "apply"; diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreQuickAccessButtonComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreQuickAccessButtonComp.java index 47a513865..d53029e53 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreQuickAccessButtonComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreQuickAccessButtonComp.java @@ -41,8 +41,7 @@ public class StoreQuickAccessButtonComp extends Comp> { private MenuItem recurse(ContextMenu contextMenu, StoreSection section) { var c = section.getShownChildren(); var w = section.getWrapper(); - var graphic = - w.getEntry().getProvider().getDisplayIconFileName(w.getEntry().getStore()); + var graphic = w.getEntry().getEffectiveIconFile(); if (c.getList().isEmpty()) { var item = ContextMenuHelper.item( new LabelGraphic.ImageGraphic(graphic, 16), w.getName().getValue()); diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreSection.java b/app/src/main/java/io/xpipe/app/comp/store/StoreSection.java index 8c244d783..1961c8da4 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreSection.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreSection.java @@ -176,7 +176,8 @@ public class StoreSection { var showProvider = true; try { showProvider = other.getEntry().getProvider().shouldShow(other); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } return showProvider; }, e.getPersistentState(), diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreSectionComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreSectionComp.java index 154e72013..7303c7127 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreSectionComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreSectionComp.java @@ -7,6 +7,7 @@ import io.xpipe.app.fxcomps.augment.GrowAugment; import io.xpipe.app.fxcomps.impl.HorizontalComp; import io.xpipe.app.fxcomps.impl.IconButtonComp; import io.xpipe.app.fxcomps.impl.VerticalComp; +import io.xpipe.app.fxcomps.util.LabelGraphic; import io.xpipe.app.storage.DataColor; import io.xpipe.app.util.ThreadHelper; @@ -68,11 +69,15 @@ public class StoreSectionComp extends Comp> { private Comp> createExpandButton() { var expandButton = new IconButtonComp( - Bindings.createStringBinding( - () -> section.getWrapper().getExpanded().get() - && section.getShownChildren().getList().size() > 0 - ? "mdal-keyboard_arrow_down" - : "mdal-keyboard_arrow_right", + Bindings.createObjectBinding( + () -> new LabelGraphic.IconGraphic( + section.getWrapper().getExpanded().get() + && section.getShownChildren() + .getList() + .size() + > 0 + ? "mdal-keyboard_arrow_down" + : "mdal-keyboard_arrow_right"), section.getWrapper().getExpanded(), section.getShownChildren().getList()), () -> { diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreSectionMiniComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreSectionMiniComp.java index 9e35bf600..a02c91314 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreSectionMiniComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreSectionMiniComp.java @@ -8,6 +8,7 @@ import io.xpipe.app.fxcomps.impl.HorizontalComp; import io.xpipe.app.fxcomps.impl.IconButtonComp; import io.xpipe.app.fxcomps.impl.PrettyImageHelper; import io.xpipe.app.fxcomps.impl.VerticalComp; +import io.xpipe.app.fxcomps.util.LabelGraphic; import io.xpipe.app.storage.DataColor; import javafx.beans.binding.Bindings; @@ -52,15 +53,9 @@ public class StoreSectionMiniComp extends Comp> { if (section.getWrapper() != null) { var root = new ButtonComp(section.getWrapper().nameProperty(), () -> {}) .apply(struc -> { - var provider = section.getWrapper().getEntry().getProvider(); struc.get() - .setGraphic(PrettyImageHelper.ofFixedSizeSquare( - provider != null - ? provider.getDisplayIconFileName(section.getWrapper() - .getEntry() - .getStore()) - : null, - 16) + .setGraphic(PrettyImageHelper.ofFixedSize( + section.getWrapper().getIconFile(), 16, 16) .createRegion()); }) .apply(struc -> { @@ -81,8 +76,9 @@ public class StoreSectionMiniComp extends Comp> { new SimpleBooleanProperty(section.getWrapper().getExpanded().get() && section.getShownChildren().getList().size() > 0); var button = new IconButtonComp( - Bindings.createStringBinding( - () -> expanded.get() ? "mdal-keyboard_arrow_down" : "mdal-keyboard_arrow_right", + Bindings.createObjectBinding( + () -> new LabelGraphic.IconGraphic( + expanded.get() ? "mdal-keyboard_arrow_down" : "mdal-keyboard_arrow_right"), expanded), () -> { expanded.set(!expanded.get()); diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreViewState.java b/app/src/main/java/io/xpipe/app/comp/store/StoreViewState.java index c86b069dc..c2297d6d2 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreViewState.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreViewState.java @@ -98,10 +98,11 @@ public class StoreViewState { private void initFilterJump() { var all = getAllConnectionsCategory(); filter.addListener((observable, oldValue, newValue) -> { - var matchingCats = categories.getList().stream().filter(storeCategoryWrapper -> storeCategoryWrapper.getRoot().equals(all)) - .filter(storeCategoryWrapper -> storeCategoryWrapper.getDirectContainedEntries() - .stream() - .anyMatch(wrapper -> wrapper.matchesFilter(newValue))) + var matchingCats = categories.getList().stream() + .filter(storeCategoryWrapper -> + storeCategoryWrapper.getRoot().equals(all)) + .filter(storeCategoryWrapper -> storeCategoryWrapper.getDirectContainedEntries().stream() + .anyMatch(wrapper -> wrapper.matchesFilter(newValue))) .toList(); if (matchingCats.size() == 1) { activeCategory.setValue(matchingCats.getFirst()); diff --git a/app/src/main/java/io/xpipe/app/core/App.java b/app/src/main/java/io/xpipe/app/core/App.java index c370764a2..8b1f3bcb7 100644 --- a/app/src/main/java/io/xpipe/app/core/App.java +++ b/app/src/main/java/io/xpipe/app/core/App.java @@ -10,6 +10,8 @@ import io.xpipe.app.util.LicenseProvider; import javafx.application.Application; import javafx.beans.binding.Bindings; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.value.ObservableDoubleValue; import javafx.stage.Stage; import lombok.Getter; @@ -63,4 +65,12 @@ public class App extends Application { stage.requestFocus(); }); } + + public ObservableDoubleValue displayScale() { + if (getStage() == null) { + return new SimpleDoubleProperty(1.0); + } + + return getStage().outputScaleXProperty(); + } } diff --git a/app/src/main/java/io/xpipe/app/core/AppDesktopIntegration.java b/app/src/main/java/io/xpipe/app/core/AppDesktopIntegration.java index 8f680a9ca..bdad8b00d 100644 --- a/app/src/main/java/io/xpipe/app/core/AppDesktopIntegration.java +++ b/app/src/main/java/io/xpipe/app/core/AppDesktopIntegration.java @@ -9,10 +9,10 @@ import io.xpipe.app.util.PlatformState; import io.xpipe.app.util.ThreadHelper; import io.xpipe.core.process.OsType; -import javax.imageio.ImageIO; import java.awt.*; import java.awt.desktop.*; import java.util.List; +import javax.imageio.ImageIO; public class AppDesktopIntegration { @@ -36,7 +36,8 @@ public class AppDesktopIntegration { ThreadHelper.sleep(1000); OperationMode.close(); }); - }} + } + } }); } diff --git a/app/src/main/java/io/xpipe/app/core/AppExtensionManager.java b/app/src/main/java/io/xpipe/app/core/AppExtensionManager.java index 6a9f064a0..58e6776ca 100644 --- a/app/src/main/java/io/xpipe/app/core/AppExtensionManager.java +++ b/app/src/main/java/io/xpipe/app/core/AppExtensionManager.java @@ -1,10 +1,11 @@ package io.xpipe.app.core; import io.xpipe.app.ext.ExtensionException; +import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.issue.TrackEvent; +import io.xpipe.app.resources.AppResources; import io.xpipe.core.process.OsType; -import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.core.util.ModuleHelper; import io.xpipe.core.util.ModuleLayerLoader; import io.xpipe.core.util.XPipeInstallation; @@ -55,8 +56,8 @@ public class AppExtensionManager { ErrorEvent.fromThrowable(t).handle(); }); } catch (Throwable t) { - throw new ExtensionException( - "Service provider initialization failed. Is the installation data corrupt?", t); + throw ExtensionException.corrupt( + "Service provider initialization failed", t); } } } @@ -72,7 +73,7 @@ public class AppExtensionManager { private void loadBaseExtension() { var baseModule = findAndParseExtension("base", ModuleLayer.boot()); if (baseModule.isEmpty()) { - throw new ExtensionException("Missing base module. Is the installation data corrupt?"); + throw ExtensionException.corrupt("Missing base module"); } baseLayer = baseModule.get().getModule().getLayer(); @@ -205,8 +206,8 @@ public class AppExtensionManager { var ext = getExtensionFromDir(layer, dir); if (ext.isEmpty()) { if (AppProperties.get().isFullVersion()) { - throw new ExtensionException( - "Unable to load extension from directory " + dir + ". Is the installation corrupted?"); + throw ExtensionException.corrupt( + "Unable to load extension from directory " + dir); } } else { if (loadedExtensions.stream() diff --git a/app/src/main/java/io/xpipe/app/core/AppFont.java b/app/src/main/java/io/xpipe/app/core/AppFont.java index 92af9378c..99ca4dfd2 100644 --- a/app/src/main/java/io/xpipe/app/core/AppFont.java +++ b/app/src/main/java/io/xpipe/app/core/AppFont.java @@ -1,6 +1,7 @@ package io.xpipe.app.core; import io.xpipe.app.issue.TrackEvent; +import io.xpipe.app.resources.AppResources; import io.xpipe.core.process.OsType; import javafx.scene.Node; diff --git a/app/src/main/java/io/xpipe/app/core/AppGreetings.java b/app/src/main/java/io/xpipe/app/core/AppGreetings.java index b44ac8813..4d061087d 100644 --- a/app/src/main/java/io/xpipe/app/core/AppGreetings.java +++ b/app/src/main/java/io/xpipe/app/core/AppGreetings.java @@ -4,6 +4,7 @@ import io.xpipe.app.comp.base.MarkdownComp; import io.xpipe.app.core.mode.OperationMode; import io.xpipe.app.core.window.AppWindowHelper; import io.xpipe.app.fxcomps.Comp; +import io.xpipe.app.resources.AppResources; import javafx.beans.property.SimpleBooleanProperty; import javafx.geometry.Insets; diff --git a/app/src/main/java/io/xpipe/app/core/AppImages.java b/app/src/main/java/io/xpipe/app/core/AppImages.java deleted file mode 100644 index f0101fadc..000000000 --- a/app/src/main/java/io/xpipe/app/core/AppImages.java +++ /dev/null @@ -1,144 +0,0 @@ -package io.xpipe.app.core; - -import io.xpipe.app.issue.ErrorEvent; -import io.xpipe.app.issue.TrackEvent; - -import javafx.scene.image.Image; -import javafx.scene.image.WritableImage; - -import org.apache.commons.io.FilenameUtils; - -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.HashMap; -import java.util.Map; - -public class AppImages { - - public static final Image DEFAULT_IMAGE = new WritableImage(1, 1); - private static final Map images = new HashMap<>(); - private static final Map svgImages = new HashMap<>(); - - public static void init() { - if (images.size() > 0 || svgImages.size() > 0) { - return; - } - - TrackEvent.info("Loading images ..."); - for (var module : AppExtensionManager.getInstance().getContentModules()) { - loadDirectory(module.getName(), "img", true, true); - } - } - - public static void loadDirectory(String module, String dir, boolean loadImages, boolean loadSvgs) { - AppResources.with(module, dir, basePath -> { - if (!Files.exists(basePath)) { - return; - } - - var simpleName = FilenameUtils.getExtension(module); - String defaultPrefix = simpleName + ":"; - Files.walkFileTree(basePath, new SimpleFileVisitor<>() { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { - var relativeFileName = FilenameUtils.separatorsToUnix( - basePath.relativize(file).toString()); - try { - if (FilenameUtils.getExtension(file.toString()).equals("svg") && loadSvgs) { - var s = Files.readString(file); - svgImages.put(defaultPrefix + relativeFileName, s); - } else if (loadImages) { - images.put(defaultPrefix + relativeFileName, loadImage(file)); - } - } catch (IOException ex) { - ErrorEvent.fromThrowable(ex).omitted(true).build().handle(); - } - return FileVisitResult.CONTINUE; - } - }); - }); - } - - public static String svgImage(String file) { - if (file == null) { - return ""; - } - - var key = file.contains(":") ? file : "app:" + file; - - if (svgImages.containsKey(key)) { - return svgImages.get(key); - } - - TrackEvent.warn("Svg image " + key + " not found"); - return ""; - } - - public static boolean hasNormalImage(String file) { - if (file == null) { - return false; - } - - var key = file.contains(":") ? file : "app:" + file; - return images.containsKey(key); - } - - public static boolean hasSvgImage(String file) { - if (file == null) { - return false; - } - - var key = file.contains(":") ? file : "app:" + file; - return svgImages.containsKey(key); - } - - public static Image image(String file) { - if (file == null) { - return DEFAULT_IMAGE; - } - - var key = file.contains(":") ? file : "app:" + file; - - if (images.containsKey(key)) { - return images.get(key); - } - - TrackEvent.warn("Normal image " + key + " not found"); - return DEFAULT_IMAGE; - } - - public static BufferedImage toAwtImage(Image fxImage) { - BufferedImage img = - new BufferedImage((int) fxImage.getWidth(), (int) fxImage.getHeight(), BufferedImage.TYPE_INT_ARGB); - for (int x = 0; x < fxImage.getWidth(); x++) { - for (int y = 0; y < fxImage.getHeight(); y++) { - int rgb = fxImage.getPixelReader().getArgb(x, y); - img.setRGB(x, y, rgb); - } - } - return img; - } - - public static Image loadImage(Path p) { - if (p == null) { - return DEFAULT_IMAGE; - } - - if (!Files.isRegularFile(p)) { - TrackEvent.error("Image file " + p + " not found."); - return DEFAULT_IMAGE; - } - - try (var in = Files.newInputStream(p)) { - return new Image(in, -1, -1, true, true); - } catch (IOException e) { - ErrorEvent.fromThrowable(e).omitted(true).build().handle(); - return DEFAULT_IMAGE; - } - } -} diff --git a/app/src/main/java/io/xpipe/app/core/AppLayoutModel.java b/app/src/main/java/io/xpipe/app/core/AppLayoutModel.java index b58fb9e2e..e7cdae97c 100644 --- a/app/src/main/java/io/xpipe/app/core/AppLayoutModel.java +++ b/app/src/main/java/io/xpipe/app/core/AppLayoutModel.java @@ -3,14 +3,17 @@ package io.xpipe.app.core; import io.xpipe.app.beacon.AppBeaconServer; import io.xpipe.app.browser.session.BrowserSessionComp; import io.xpipe.app.browser.session.BrowserSessionModel; +import io.xpipe.app.comp.base.TerminalViewDockComp; import io.xpipe.app.comp.store.StoreLayoutComp; import io.xpipe.app.fxcomps.Comp; +import io.xpipe.app.fxcomps.util.LabelGraphic; import io.xpipe.app.prefs.AppPrefsComp; import io.xpipe.app.util.Hyperlinks; import io.xpipe.app.util.LicenseProvider; import javafx.beans.property.Property; import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; import javafx.beans.value.ObservableValue; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; @@ -21,6 +24,7 @@ import lombok.Data; import lombok.Getter; import lombok.extern.jackson.Jacksonized; +import java.time.*; import java.util.ArrayList; import java.util.List; @@ -38,7 +42,7 @@ public class AppLayoutModel { public AppLayoutModel(SavedState savedState) { this.savedState = savedState; this.entries = createEntryList(); - this.selected = new SimpleObjectProperty<>(entries.get(1)); + this.selected = new SimpleObjectProperty<>(entries.get(0)); } public static AppLayoutModel get() { @@ -56,66 +60,100 @@ public class AppLayoutModel { } public void selectBrowser() { - selected.setValue(entries.getFirst()); + selected.setValue(entries.get(1)); } - public void selectSettings() { + public void selectTerminal() { selected.setValue(entries.get(2)); } - public void selectLicense() { + public void selectSettings() { selected.setValue(entries.get(3)); } + public void selectLicense() { + selected.setValue(entries.get(4)); + } + public void selectConnections() { - selected.setValue(entries.get(1)); + selected.setValue(entries.get(0)); } private List createEntryList() { var l = new ArrayList<>(List.of( new Entry( - AppI18n.observable("browser"), - "mdi2f-file-cabinet", - new BrowserSessionComp(BrowserSessionModel.DEFAULT), + AppI18n.observable("connections"), + new LabelGraphic.IconGraphic("mdi2c-connection"), + new StoreLayoutComp(), null, new KeyCodeCombination(KeyCode.DIGIT1, KeyCombination.SHORTCUT_DOWN)), new Entry( - AppI18n.observable("connections"), - "mdi2c-connection", - new StoreLayoutComp(), + AppI18n.observable("browser"), + new LabelGraphic.IconGraphic("mdi2f-file-cabinet"), + new BrowserSessionComp(BrowserSessionModel.DEFAULT), null, new KeyCodeCombination(KeyCode.DIGIT2, KeyCombination.SHORTCUT_DOWN)), + new Entry( + AppI18n.observable("terminal"), + new LabelGraphic.IconGraphic("mdi2m-monitor-screenshot"), + new TerminalViewDockComp(), + null, + new KeyCodeCombination(KeyCode.DIGIT3, KeyCombination.SHORTCUT_DOWN)), new Entry( AppI18n.observable("settings"), - "mdsmz-miscellaneous_services", + new LabelGraphic.IconGraphic("mdsmz-miscellaneous_services"), new AppPrefsComp(), null, new KeyCodeCombination(KeyCode.DIGIT3, KeyCombination.SHORTCUT_DOWN)), new Entry( AppI18n.observable("explorePlans"), - "mdi2p-professional-hexagon", + new LabelGraphic.IconGraphic("mdi2p-professional-hexagon"), LicenseProvider.get().overviewPage(), null, null), new Entry( AppI18n.observable("visitGithubRepository"), - "mdi2g-github", + new LabelGraphic.IconGraphic("mdi2g-github"), null, () -> Hyperlinks.open(Hyperlinks.GITHUB), null), new Entry( AppI18n.observable("discord"), - "mdi2d-discord", + new LabelGraphic.IconGraphic("mdi2d-discord"), null, () -> Hyperlinks.open(Hyperlinks.DISCORD), null), new Entry( AppI18n.observable("api"), - "mdi2c-code-json", + new LabelGraphic.IconGraphic("mdi2c-code-json"), null, () -> Hyperlinks.open( "http://localhost:" + AppBeaconServer.get().getPort()), - null))); + null) + // new Entry( + // AppI18n.observable("webtop"), + // "mdi2d-desktop-mac", + // null, + // () -> Hyperlinks.open(Hyperlinks.GITHUB_WEBTOP), + // null) + )); + + var now = Instant.now(); + var zone = ZoneId.of(ZoneId.SHORT_IDS.get("PST")); + var phStart = ZonedDateTime.of(2024, 10, 22, 0, 1, 0, 0, zone).toInstant(); + var clicked = AppCache.get("phClicked",Boolean.class,() -> false); + var phShow = now.isAfter(phStart) && !clicked; + if (phShow) { + l.add(new Entry( + new SimpleStringProperty("Product Hunt"), + new LabelGraphic.ImageGraphic("app:producthunt-color.png", 24), + null, + () -> { + AppCache.update("phClicked", true); + Hyperlinks.open(Hyperlinks.PRODUCT_HUNT); + }, + null)); + } return l; } @@ -129,5 +167,9 @@ public class AppLayoutModel { } public record Entry( - ObservableValue name, String icon, Comp comp, Runnable action, KeyCombination combination) {} + ObservableValue name, + LabelGraphic icon, + Comp comp, + Runnable action, + KeyCombination combination) {} } diff --git a/app/src/main/java/io/xpipe/app/core/AppResources.java b/app/src/main/java/io/xpipe/app/core/AppResources.java deleted file mode 100644 index ec0bc9119..000000000 --- a/app/src/main/java/io/xpipe/app/core/AppResources.java +++ /dev/null @@ -1,132 +0,0 @@ -package io.xpipe.app.core; - -import io.xpipe.app.issue.ErrorEvent; -import io.xpipe.core.util.FailableConsumer; -import io.xpipe.modulefs.ModuleFileSystem; - -import java.io.IOException; -import java.net.JarURLConnection; -import java.net.URI; -import java.net.URL; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; - -public class AppResources { - - public static final String XPIPE_MODULE = "io.xpipe.app"; - - private static final Map fileSystems = new ConcurrentHashMap<>(); - - public static void reset() { - fileSystems.forEach((s, moduleFileSystem) -> { - try { - moduleFileSystem.close(); - } catch (IOException ignored) { - // Usually when updating, a SIGTERM is sent to this application. - // However, it takes a while to shut down but the installer is deleting files meanwhile. - // It can happen that the jar it does not exist anymore - } - }); - fileSystems.clear(); - } - - private static ModuleFileSystem openFileSystemIfNeeded(String module) throws IOException { - var layer = AppExtensionManager.getInstance() != null - ? AppExtensionManager.getInstance().getExtendedLayer() - : null; - - // Only cache file systems with extended layer - if (layer != null && fileSystems.containsKey(module)) { - return fileSystems.get(module); - } - - if (layer == null) { - layer = ModuleLayer.boot(); - } - - var fs = (ModuleFileSystem) FileSystems.newFileSystem(URI.create("module:/" + module), Map.of("layer", layer)); - if (AppExtensionManager.getInstance() != null) { - fileSystems.put(module, fs); - } - return fs; - } - - public static Optional getResourceURL(String module, String file) { - try { - var fs = openFileSystemIfNeeded(module); - var f = fs.getPath(module.replace('.', '/') + "/resources/" + file); - var url = f.getWrappedPath().toUri().toURL(); - return Optional.of(url); - } catch (IOException e) { - ErrorEvent.fromThrowable(e).omitted(true).build().handle(); - return Optional.empty(); - } - } - - public static void with(String module, String file, FailableConsumer con) { - if (AppProperties.get() != null - && !AppProperties.get().isImage() - && AppProperties.get().isDeveloperMode()) { - // Check if resource was found. If we use external processed resources, we can't use local dev resources - if (withLocalDevResource(module, file, con)) { - return; - } - } - - withResource(module, file, con); - } - - public static void withResourceInLayer( - String module, String file, ModuleLayer layer, FailableConsumer con) { - try (var fs = FileSystems.newFileSystem(URI.create("module:/" + module), Map.of("layer", layer))) { - var f = fs.getPath(module.replace('.', '/') + "/resources/" + file); - con.accept(f); - } catch (IOException e) { - ErrorEvent.fromThrowable(e).omitted(true).build().handle(); - } - } - - private static void withResource(String module, String file, FailableConsumer con) { - var path = module.startsWith("io.xpipe") ? module.replace('.', '/') + "/resources/" + file : file; - try { - var fs = openFileSystemIfNeeded(module); - var f = fs.getPath(path); - con.accept(f); - } catch (IOException e) { - ErrorEvent.fromThrowable(e).omitted(true).build().handle(); - } - } - - private static boolean withLocalDevResource(String module, String file, FailableConsumer con) { - try { - var fs = openFileSystemIfNeeded(module); - var url = fs.getPath("").getWrappedPath().toUri().toURL(); - if (!url.getProtocol().equals("jar")) { - return false; - } - - JarURLConnection connection = (JarURLConnection) url.openConnection(); - URL fileUrl = connection.getJarFileURL(); - var jarFile = Path.of(fileUrl.toURI()); - var resDir = jarFile.getParent() - .getParent() - .getParent() - .resolve("src") - .resolve("main") - .resolve("resources"); - var f = resDir.resolve(module.replace('.', '/') + "/resources/" + file); - if (!Files.exists(f)) { - return false; - } - - con.accept(f); - } catch (Exception e) { - ErrorEvent.fromThrowable(e).omitted(true).build().handle(); - } - return true; - } -} diff --git a/app/src/main/java/io/xpipe/app/core/AppStyle.java b/app/src/main/java/io/xpipe/app/core/AppStyle.java index e009c3f4b..44486a20e 100644 --- a/app/src/main/java/io/xpipe/app/core/AppStyle.java +++ b/app/src/main/java/io/xpipe/app/core/AppStyle.java @@ -3,6 +3,7 @@ package io.xpipe.app.core; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.prefs.AppPrefs; +import io.xpipe.app.resources.AppResources; import javafx.scene.Scene; diff --git a/app/src/main/java/io/xpipe/app/core/AppTheme.java b/app/src/main/java/io/xpipe/app/core/AppTheme.java index 05cdb6cb8..b0ac3c689 100644 --- a/app/src/main/java/io/xpipe/app/core/AppTheme.java +++ b/app/src/main/java/io/xpipe/app/core/AppTheme.java @@ -6,6 +6,7 @@ import io.xpipe.app.fxcomps.util.PlatformThread; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.prefs.AppPrefs; +import io.xpipe.app.resources.AppResources; import io.xpipe.core.process.OsType; import javafx.animation.Interpolator; diff --git a/app/src/main/java/io/xpipe/app/core/AppTrayIcon.java b/app/src/main/java/io/xpipe/app/core/AppTrayIcon.java index 7a641ccd7..cfd8c881b 100644 --- a/app/src/main/java/io/xpipe/app/core/AppTrayIcon.java +++ b/app/src/main/java/io/xpipe/app/core/AppTrayIcon.java @@ -2,6 +2,8 @@ package io.xpipe.app.core; import io.xpipe.app.core.mode.OperationMode; import io.xpipe.app.issue.ErrorEvent; +import io.xpipe.app.resources.AppImages; +import io.xpipe.app.resources.AppResources; import io.xpipe.core.process.OsType; import java.awt.*; diff --git a/app/src/main/java/io/xpipe/app/core/check/AppAvCheck.java b/app/src/main/java/io/xpipe/app/core/check/AppAvCheck.java index 4dff8398a..d75c301cb 100644 --- a/app/src/main/java/io/xpipe/app/core/check/AppAvCheck.java +++ b/app/src/main/java/io/xpipe/app/core/check/AppAvCheck.java @@ -1,9 +1,13 @@ package io.xpipe.app.core.check; import io.xpipe.app.comp.base.MarkdownComp; -import io.xpipe.app.core.*; +import io.xpipe.app.core.AppI18n; +import io.xpipe.app.core.AppProperties; +import io.xpipe.app.core.AppState; +import io.xpipe.app.core.AppStyle; import io.xpipe.app.core.mode.OperationMode; import io.xpipe.app.core.window.AppWindowHelper; +import io.xpipe.app.resources.AppResources; import io.xpipe.app.util.PlatformState; import io.xpipe.app.util.WindowsRegistry; import io.xpipe.core.process.OsType; @@ -42,7 +46,6 @@ public class AppAvCheck { PlatformState.initPlatformOrThrow(); AppStyle.init(); - AppImages.init(); var a = AppWindowHelper.showBlockingAlert(alert -> { alert.setTitle(AppI18n.get("antivirusNoticeTitle")); diff --git a/app/src/main/java/io/xpipe/app/core/check/AppBundledToolsCheck.java b/app/src/main/java/io/xpipe/app/core/check/AppBundledToolsCheck.java index 57aefbcab..7c745b1a1 100644 --- a/app/src/main/java/io/xpipe/app/core/check/AppBundledToolsCheck.java +++ b/app/src/main/java/io/xpipe/app/core/check/AppBundledToolsCheck.java @@ -8,7 +8,9 @@ import java.util.concurrent.TimeUnit; public class AppBundledToolsCheck { private static boolean getResult() { - var fc = new ProcessBuilder("where", "ssh").redirectErrorStream(true).redirectOutput(ProcessBuilder.Redirect.DISCARD); + var fc = new ProcessBuilder("where", "ssh") + .redirectErrorStream(true) + .redirectOutput(ProcessBuilder.Redirect.DISCARD); try { var proc = fc.start(); proc.waitFor(2, TimeUnit.SECONDS); diff --git a/app/src/main/java/io/xpipe/app/core/check/AppGpuCheck.java b/app/src/main/java/io/xpipe/app/core/check/AppGpuCheck.java new file mode 100644 index 000000000..1b669a94e --- /dev/null +++ b/app/src/main/java/io/xpipe/app/core/check/AppGpuCheck.java @@ -0,0 +1,22 @@ +package io.xpipe.app.core.check; + +import io.xpipe.app.prefs.AppPrefs; +import io.xpipe.app.util.PlatformState; + +import javafx.application.ConditionalFeature; +import javafx.application.Platform; + +public class AppGpuCheck { + + public static void check() { + if (PlatformState.getCurrent() != PlatformState.RUNNING) { + return; + } + + if (Platform.isSupported(ConditionalFeature.SCENE3D)) { + return; + } + + AppPrefs.get().performanceMode.setValue(true); + } +} diff --git a/app/src/main/java/io/xpipe/app/core/check/AppJavaOptionsCheck.java b/app/src/main/java/io/xpipe/app/core/check/AppJavaOptionsCheck.java new file mode 100644 index 000000000..e351e3c5c --- /dev/null +++ b/app/src/main/java/io/xpipe/app/core/check/AppJavaOptionsCheck.java @@ -0,0 +1,28 @@ +package io.xpipe.app.core.check; + +import io.xpipe.app.core.AppCache; +import io.xpipe.app.issue.ErrorEvent; + +public class AppJavaOptionsCheck { + + public static void check() { + if (AppCache.get("javaOptionsWarningShown", Boolean.class,() -> false)) { + return; + } + + var env = System.getenv("_JAVA_OPTIONS"); + if (env == null) { + return; + } + + ErrorEvent.fromMessage( + "You have configured the global environment variable _JAVA_OPTIONS=%s on your system." + .formatted(env) + + " This will forcefully apply all custom JVM options to XPipe and can cause a variety of different issues." + + " Please remove this global environment variable and use local configuration instead for your other JVM programs.") + .noDefaultActions() + .expected() + .handle(); + AppCache.update("javaOptionsWarningShown", true); + } +} diff --git a/app/src/main/java/io/xpipe/app/core/check/AppRosettaCheck.java b/app/src/main/java/io/xpipe/app/core/check/AppRosettaCheck.java index e555e7c00..c97b14478 100644 --- a/app/src/main/java/io/xpipe/app/core/check/AppRosettaCheck.java +++ b/app/src/main/java/io/xpipe/app/core/check/AppRosettaCheck.java @@ -25,8 +25,11 @@ public class AppRosettaCheck { if (ret.get().equals("1")) { ErrorEvent.fromMessage("You are running the Intel version of XPipe on an Apple Silicon system." - + " There is a native build available that comes with much better performance." - + " Please install that one instead."); + + " There is a native build available that comes with much better performance." + + " Please install that one instead.") + .noDefaultActions() + .expected() + .handle(); } } } diff --git a/app/src/main/java/io/xpipe/app/core/check/AppShellCheck.java b/app/src/main/java/io/xpipe/app/core/check/AppShellCheck.java index 9d792cea7..15dc09272 100644 --- a/app/src/main/java/io/xpipe/app/core/check/AppShellCheck.java +++ b/app/src/main/java/io/xpipe/app/core/check/AppShellCheck.java @@ -1,9 +1,9 @@ package io.xpipe.app.core.check; +import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.util.LocalShell; import io.xpipe.core.process.OsType; -import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.core.process.ProcessOutputException; import lombok.Value; diff --git a/app/src/main/java/io/xpipe/app/core/mode/BaseMode.java b/app/src/main/java/io/xpipe/app/core/mode/BaseMode.java index 79be0a3a7..a9f19a6b7 100644 --- a/app/src/main/java/io/xpipe/app/core/mode/BaseMode.java +++ b/app/src/main/java/io/xpipe/app/core/mode/BaseMode.java @@ -8,8 +8,11 @@ import io.xpipe.app.core.*; import io.xpipe.app.core.check.*; import io.xpipe.app.ext.ActionProvider; import io.xpipe.app.ext.DataStoreProviders; +import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.prefs.AppPrefs; +import io.xpipe.app.resources.AppResources; +import io.xpipe.app.resources.SystemIcons; import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStorageSyncHandler; import io.xpipe.app.update.XPipeDistributionType; @@ -44,6 +47,7 @@ public class BaseMode extends OperationMode { AppCertutilCheck.check(); AppBundledToolsCheck.check(); AppAvCheck.check(); + AppJavaOptionsCheck.check(); AppSid.init(); LocalShell.init(); AppShellCheck.check(); @@ -56,12 +60,14 @@ public class BaseMode extends OperationMode { DataStorageSyncHandler.getInstance().retrieveSyncedData(); AppPrefs.initSharedRemote(); UnlockAlert.showIfNeeded(); + SystemIcons.init(); DataStorage.init(); DataStoreProviders.init(); AppFileWatcher.init(); FileBridge.init(); BlobManager.init(); ActionProvider.initProviders(); + TerminalView.init(); TrackEvent.info("Finished base components initialization"); initialized = true; } @@ -70,7 +76,7 @@ public class BaseMode extends OperationMode { public void onSwitchFrom() {} @Override - public void finalTeardown() { + public void finalTeardown() throws Exception { TrackEvent.info("Background mode shutdown started"); BrowserSessionModel.DEFAULT.reset(); SshLocalBridge.reset(); @@ -78,12 +84,14 @@ public class BaseMode extends OperationMode { DataStoreProviders.reset(); DataStorage.reset(); AppPrefs.reset(); + DataStorageSyncHandler.getInstance().reset(); + LocalShell.reset(); + ProcessControlProvider.get().reset(); AppResources.reset(); AppExtensionManager.reset(); AppDataLock.unlock(); BlobManager.reset(); FileBridge.reset(); - // Shut down server last to keep a non-daemon thread running AppBeaconServer.reset(); TrackEvent.info("Background mode shutdown finished"); } diff --git a/app/src/main/java/io/xpipe/app/core/mode/GuiMode.java b/app/src/main/java/io/xpipe/app/core/mode/GuiMode.java index ad26c5d96..80c2280c4 100644 --- a/app/src/main/java/io/xpipe/app/core/mode/GuiMode.java +++ b/app/src/main/java/io/xpipe/app/core/mode/GuiMode.java @@ -4,6 +4,7 @@ import io.xpipe.app.browser.file.LocalFileSystem; import io.xpipe.app.browser.icon.FileIconManager; import io.xpipe.app.core.App; import io.xpipe.app.core.AppGreetings; +import io.xpipe.app.core.AppLayoutModel; import io.xpipe.app.core.check.AppPtbCheck; import io.xpipe.app.core.window.AppMainWindow; import io.xpipe.app.fxcomps.util.PlatformThread; @@ -39,6 +40,7 @@ public class GuiMode extends PlatformMode { AppGreetings.showIfNeeded(); AppPtbCheck.check(); NativeBridge.init(); + AppLayoutModel.init(); TrackEvent.info("Waiting for window setup completion ..."); PlatformThread.runLaterIfNeededBlocking(() -> { @@ -63,4 +65,10 @@ public class GuiMode extends PlatformMode { UpdateChangelogAlert.showIfNeeded(); } + + @Override + public void finalTeardown() throws Throwable { + LocalFileSystem.reset(); + super.finalTeardown(); + } } diff --git a/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java b/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java index fd5b6c206..cabdad67e 100644 --- a/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java +++ b/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java @@ -225,6 +225,8 @@ public abstract class OperationMode { CURRENT.finalTeardown(); } CURRENT = null; + // Restart local shell + LocalShell.init(); r.run(); } catch (Throwable ex) { ErrorEvent.fromThrowable(ex).handle(); @@ -293,17 +295,27 @@ public abstract class OperationMode { inShutdown = true; OperationMode.inShutdownHook = inShutdownHook; - try { - if (CURRENT != null) { - CURRENT.finalTeardown(); + // Keep a non-daemon thread running + var thread = ThreadHelper.createPlatformThread("shutdown", false, () -> { + try { + if (CURRENT != null) { + CURRENT.finalTeardown(); + } + CURRENT = null; + } catch (Throwable t) { + ErrorEvent.fromThrowable(t).term().handle(); + OperationMode.halt(1); } - CURRENT = null; - } catch (Throwable t) { - ErrorEvent.fromThrowable(t).term().handle(); + + OperationMode.halt(hasError ? 1 : 0); + }); + thread.start(); + + try { + thread.join(); + } catch (InterruptedException ignored) { OperationMode.halt(1); } - - OperationMode.halt(hasError ? 1 : 0); } // public static synchronized void reload() { diff --git a/app/src/main/java/io/xpipe/app/core/mode/PlatformMode.java b/app/src/main/java/io/xpipe/app/core/mode/PlatformMode.java index b5cb69efe..3499dd5e6 100644 --- a/app/src/main/java/io/xpipe/app/core/mode/PlatformMode.java +++ b/app/src/main/java/io/xpipe/app/core/mode/PlatformMode.java @@ -3,8 +3,10 @@ package io.xpipe.app.core.mode; import io.xpipe.app.comp.store.StoreViewState; import io.xpipe.app.core.*; import io.xpipe.app.core.check.AppFontLoadingCheck; +import io.xpipe.app.core.check.AppGpuCheck; import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.prefs.AppPrefs; +import io.xpipe.app.resources.AppImages; import io.xpipe.app.update.UpdateAvailableAlert; import io.xpipe.app.util.PlatformState; import io.xpipe.app.util.ThreadHelper; @@ -29,11 +31,14 @@ public abstract class PlatformMode extends OperationMode { PlatformState.initPlatformOrThrow(); // Check if we can load system fonts or fail AppFontLoadingCheck.check(); + // Can be loaded async + var imageThread = ThreadHelper.runFailableAsync(() -> { + AppImages.init(); + }); + AppGpuCheck.check(); AppFont.init(); AppTheme.init(); AppStyle.init(); - AppImages.init(); - AppLayoutModel.init(); TrackEvent.info("Finished essential component initialization before platform"); TrackEvent.info("Launching application ..."); @@ -56,6 +61,7 @@ public abstract class PlatformMode extends OperationMode { } StoreViewState.init(); + imageThread.join(); } @Override diff --git a/app/src/main/java/io/xpipe/app/core/window/AppMainWindow.java b/app/src/main/java/io/xpipe/app/core/window/AppMainWindow.java index 025100903..dc4d6d17e 100644 --- a/app/src/main/java/io/xpipe/app/core/window/AppMainWindow.java +++ b/app/src/main/java/io/xpipe/app/core/window/AppMainWindow.java @@ -1,7 +1,6 @@ package io.xpipe.app.core.window; import io.xpipe.app.core.AppCache; -import io.xpipe.app.core.AppImages; import io.xpipe.app.core.AppProperties; import io.xpipe.app.core.AppTheme; import io.xpipe.app.core.mode.OperationMode; @@ -10,8 +9,10 @@ import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.prefs.CloseBehaviourAlert; +import io.xpipe.app.resources.AppImages; import io.xpipe.app.util.ThreadHelper; import io.xpipe.core.process.OsType; + import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.geometry.Rectangle2D; @@ -24,17 +25,18 @@ import javafx.scene.layout.Region; import javafx.scene.paint.Color; import javafx.stage.Screen; import javafx.stage.Stage; + import lombok.Builder; import lombok.Getter; import lombok.Value; import lombok.extern.jackson.Jacksonized; -import javax.imageio.ImageIO; import java.io.IOException; import java.nio.file.Path; import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; +import javax.imageio.ImageIO; public class AppMainWindow { @@ -262,6 +264,9 @@ public class AppMainWindow { public void show() { stage.show(); + if (OsType.getLocal() == OsType.WINDOWS) { + NativeWinWindowControl.MAIN_WINDOW = new NativeWinWindowControl(stage); + } } private void setupContent(Comp content) { diff --git a/app/src/main/java/io/xpipe/app/core/window/AppWindowHelper.java b/app/src/main/java/io/xpipe/app/core/window/AppWindowHelper.java index ae4d0b5e2..79070c556 100644 --- a/app/src/main/java/io/xpipe/app/core/window/AppWindowHelper.java +++ b/app/src/main/java/io/xpipe/app/core/window/AppWindowHelper.java @@ -5,6 +5,8 @@ import io.xpipe.app.core.*; import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.prefs.AppPrefs; +import io.xpipe.app.resources.AppImages; +import io.xpipe.app.resources.AppResources; import io.xpipe.app.util.InputHelper; import io.xpipe.app.util.ThreadHelper; import io.xpipe.core.process.OsType; diff --git a/app/src/main/java/io/xpipe/app/core/window/NativeMacOsWindowControl.java b/app/src/main/java/io/xpipe/app/core/window/NativeMacOsWindowControl.java index c15d14a10..315a22680 100644 --- a/app/src/main/java/io/xpipe/app/core/window/NativeMacOsWindowControl.java +++ b/app/src/main/java/io/xpipe/app/core/window/NativeMacOsWindowControl.java @@ -1,11 +1,13 @@ package io.xpipe.app.core.window; -import com.sun.jna.NativeLong; import io.xpipe.app.core.AppProperties; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.util.NativeBridge; import io.xpipe.core.util.ModuleHelper; + import javafx.stage.Window; + +import com.sun.jna.NativeLong; import lombok.Getter; import lombok.SneakyThrows; diff --git a/app/src/main/java/io/xpipe/app/core/window/NativeWinWindowControl.java b/app/src/main/java/io/xpipe/app/core/window/NativeWinWindowControl.java index 398f33b36..c3cb376a6 100644 --- a/app/src/main/java/io/xpipe/app/core/window/NativeWinWindowControl.java +++ b/app/src/main/java/io/xpipe/app/core/window/NativeWinWindowControl.java @@ -1,5 +1,7 @@ package io.xpipe.app.core.window; +import com.sun.jna.ptr.IntByReference; +import io.xpipe.app.util.Rect; import javafx.stage.Window; import com.sun.jna.Library; @@ -13,10 +15,29 @@ import lombok.Getter; import lombok.SneakyThrows; import java.lang.reflect.Method; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; @Getter public class NativeWinWindowControl { + public static Optional byPid(long pid) { + var ref = new AtomicReference(); + User32.INSTANCE.EnumWindows((hWnd, data) -> { + var wpid = new IntByReference(); + User32.INSTANCE.GetWindowThreadProcessId(hWnd, wpid); + if (wpid.getValue() == pid) { + ref.set(new NativeWinWindowControl(hWnd)); + return false; + } else { + return true; + } + }, null); + return Optional.ofNullable(ref.get()); + } + + public static NativeWinWindowControl MAIN_WINDOW; + private final WinDef.HWND windowHandle; @SneakyThrows @@ -38,8 +59,28 @@ public class NativeWinWindowControl { this.windowHandle = windowHandle; } - public void move(int x, int y, int w, int h) { - User32.INSTANCE.SetWindowPos(windowHandle, new WinDef.HWND(), x, y, w, h, 0); + public void alwaysInFront() { + orderRelative(new WinDef.HWND(new Pointer( 0xFFFFFFFFFFFFFFFFL))); + } + + public void orderRelative(WinDef.HWND predecessor) { + User32.INSTANCE.SetWindowPos(windowHandle, predecessor, 0, 0, 0, 0, User32.SWP_NOACTIVATE | User32.SWP_NOMOVE | User32.SWP_NOSIZE); + } + + public void show() { + User32.INSTANCE.ShowWindow(windowHandle,User32.SW_RESTORE); + } + + public void close() { + User32.INSTANCE.CloseWindow(windowHandle); + } + + public void minimize() { + User32.INSTANCE.ShowWindow(windowHandle,User32.SW_MINIMIZE); + } + + public void move(Rect bounds) { + User32.INSTANCE.SetWindowPos(windowHandle, null, bounds.getX(), bounds.getY(), bounds.getW(), bounds.getH(), User32.SWP_NOACTIVATE); } public boolean setWindowAttribute(int attribute, boolean attributeValue) { diff --git a/app/src/main/java/io/xpipe/app/ext/ContainerImageStore.java b/app/src/main/java/io/xpipe/app/ext/ContainerImageStore.java new file mode 100644 index 000000000..fa5139226 --- /dev/null +++ b/app/src/main/java/io/xpipe/app/ext/ContainerImageStore.java @@ -0,0 +1,6 @@ +package io.xpipe.app.ext; + +public interface ContainerImageStore { + + String getImageName(); +} diff --git a/app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java b/app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java index cb1e01cd1..27ab1af3d 100644 --- a/app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java +++ b/app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java @@ -7,9 +7,9 @@ import io.xpipe.app.comp.store.StoreEntryWrapper; import io.xpipe.app.comp.store.StoreSection; import io.xpipe.app.comp.store.StoreSectionComp; import io.xpipe.app.core.AppI18n; -import io.xpipe.app.core.AppImages; import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.issue.ErrorEvent; +import io.xpipe.app.resources.AppImages; import io.xpipe.app.storage.DataStoreEntry; import io.xpipe.core.store.DataStore; import io.xpipe.core.util.JacksonizedValue; @@ -57,12 +57,12 @@ public interface DataStoreProvider { default void validate() { for (Class storeClass : getStoreClasses()) { if (!JacksonizedValue.class.isAssignableFrom(storeClass)) { - throw new ExtensionException( + throw ExtensionException.corrupt( String.format("Store class %s is not a Jacksonized value", storeClass.getSimpleName())); } if (getUsageCategory() == null) { - throw new ExtensionException("Provider %s does not have the usage category".formatted(getId())); + throw ExtensionException.corrupt("Provider %s does not have the usage category".formatted(getId())); } } } diff --git a/app/src/main/java/io/xpipe/app/ext/ExtensionException.java b/app/src/main/java/io/xpipe/app/ext/ExtensionException.java index e26db7670..d89baeb8c 100644 --- a/app/src/main/java/io/xpipe/app/ext/ExtensionException.java +++ b/app/src/main/java/io/xpipe/app/ext/ExtensionException.java @@ -1,14 +1,16 @@ package io.xpipe.app.ext; +import io.xpipe.core.util.XPipeInstallation; + public class ExtensionException extends RuntimeException { public ExtensionException() {} - public ExtensionException(String message) { + private ExtensionException(String message) { super(message); } - public ExtensionException(String message, Throwable cause) { + private ExtensionException(String message, Throwable cause) { super(message, cause); } @@ -20,7 +22,18 @@ public class ExtensionException extends RuntimeException { super(message, cause, enableSuppression, writableStackTrace); } + public static ExtensionException corrupt(String message, Throwable cause) { + try { + var loc = XPipeInstallation.getCurrentInstallationBasePath(); + var full = message + ".\n\n" + "Please check whether the XPipe installation data at " + loc + " is corrupted."; + return new ExtensionException(full, cause); + } catch (Throwable t) { + var full = message + ".\n\n" + "Please check whether the XPipe installation data is corrupted."; + return new ExtensionException(full, cause); + } + } + public static ExtensionException corrupt(String message) { - return new ExtensionException(message + ". Is the installation data corrupt?"); + return corrupt(message, null); } } diff --git a/app/src/main/java/io/xpipe/app/ext/LocalStore.java b/app/src/main/java/io/xpipe/app/ext/LocalStore.java index fe2c79287..ab23d77a1 100644 --- a/app/src/main/java/io/xpipe/app/ext/LocalStore.java +++ b/app/src/main/java/io/xpipe/app/ext/LocalStore.java @@ -20,7 +20,7 @@ public class LocalStore extends JacksonizedValue } @Override - public ShellControl control() { + public ShellControl parentControl() { var pc = ProcessControlProvider.get().createLocalProcessControl(true); pc.withSourceStore(this); pc.withShellStateInit(this); @@ -28,6 +28,11 @@ public class LocalStore extends JacksonizedValue return pc; } + @Override + public ShellControl control(ShellControl parent) { + return parent; + } + @Override public DataStore getNetworkParent() { return null; diff --git a/app/src/main/java/io/xpipe/app/ext/ProcessControlProvider.java b/app/src/main/java/io/xpipe/app/ext/ProcessControlProvider.java index 3196ac000..99c6468d6 100644 --- a/app/src/main/java/io/xpipe/app/ext/ProcessControlProvider.java +++ b/app/src/main/java/io/xpipe/app/ext/ProcessControlProvider.java @@ -3,6 +3,7 @@ package io.xpipe.app.ext; import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.core.process.*; import io.xpipe.core.store.DataStore; + import lombok.NonNull; import java.util.ServiceLoader; @@ -22,6 +23,8 @@ public abstract class ProcessControlProvider { return INSTANCE; } + public abstract void reset(); + public abstract ShellControl withDefaultScripts(ShellControl pc); public abstract ShellControl sub( diff --git a/app/src/main/java/io/xpipe/app/ext/ScanProvider.java b/app/src/main/java/io/xpipe/app/ext/ScanProvider.java index 8bc28c6c9..e7bae26a9 100644 --- a/app/src/main/java/io/xpipe/app/ext/ScanProvider.java +++ b/app/src/main/java/io/xpipe/app/ext/ScanProvider.java @@ -31,11 +31,11 @@ public abstract class ScanProvider { String nameKey; boolean disabled; boolean defaultSelected; - FailableRunnable scanner; + FailableRunnable scanner; String licenseFeatureId; public ScanOperation( - String nameKey, boolean disabled, boolean defaultSelected, FailableRunnable scanner) { + String nameKey, boolean disabled, boolean defaultSelected, FailableRunnable scanner) { this.nameKey = nameKey; this.disabled = disabled; this.defaultSelected = defaultSelected; diff --git a/app/src/main/java/io/xpipe/app/fxcomps/impl/DataStoreChoiceComp.java b/app/src/main/java/io/xpipe/app/fxcomps/impl/DataStoreChoiceComp.java index 24e8ecc9c..320d0a529 100644 --- a/app/src/main/java/io/xpipe/app/fxcomps/impl/DataStoreChoiceComp.java +++ b/app/src/main/java/io/xpipe/app/fxcomps/impl/DataStoreChoiceComp.java @@ -4,6 +4,7 @@ import io.xpipe.app.comp.base.ButtonComp; import io.xpipe.app.comp.store.*; import io.xpipe.app.core.AppFont; import io.xpipe.app.core.AppI18n; +import io.xpipe.app.ext.LocalStore; import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.fxcomps.SimpleComp; import io.xpipe.app.storage.DataStorage; @@ -11,7 +12,6 @@ import io.xpipe.app.storage.DataStoreEntry; import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.DataStoreCategoryChoiceComp; import io.xpipe.core.store.DataStore; -import io.xpipe.app.ext.LocalStore; import io.xpipe.core.store.ShellStore; import javafx.beans.binding.Bindings; @@ -200,18 +200,10 @@ public class DataStoreChoiceComp extends SimpleComp { button.apply(struc -> { struc.get().setMaxWidth(2000); struc.get().setAlignment(Pos.CENTER_LEFT); - Comp graphic = new PrettySvgComp( + Comp graphic = PrettyImageHelper.ofFixedSize( Bindings.createStringBinding( () -> { - if (selected.getValue() == null) { - return null; - } - - return selected.getValue() - .get() - .getProvider() - .getDisplayIconFileName( - selected.getValue().getStore()); + return selected.getValue().get().getEffectiveIconFile(); }, selected), 16, diff --git a/app/src/main/java/io/xpipe/app/fxcomps/impl/DataStoreListChoiceComp.java b/app/src/main/java/io/xpipe/app/fxcomps/impl/DataStoreListChoiceComp.java index 2e901e5e8..12341a04f 100644 --- a/app/src/main/java/io/xpipe/app/fxcomps/impl/DataStoreListChoiceComp.java +++ b/app/src/main/java/io/xpipe/app/fxcomps/impl/DataStoreListChoiceComp.java @@ -46,7 +46,7 @@ public class DataStoreListChoiceComp extends SimpleComp { var label = new LabelComp(t.get().getName()).apply(struc -> struc.get() .setGraphic(PrettyImageHelper.ofFixedSizeSquare( - t.get().getProvider().getDisplayIconFileName(t.getStore()), 16) + t.get().getEffectiveIconFile(), 16) .createRegion())); var delete = new IconButtonComp("mdal-delete_outline", () -> { selectedList.remove(t); diff --git a/app/src/main/java/io/xpipe/app/fxcomps/impl/IconButtonComp.java b/app/src/main/java/io/xpipe/app/fxcomps/impl/IconButtonComp.java index 438247b0e..eeba80d85 100644 --- a/app/src/main/java/io/xpipe/app/fxcomps/impl/IconButtonComp.java +++ b/app/src/main/java/io/xpipe/app/fxcomps/impl/IconButtonComp.java @@ -3,6 +3,7 @@ package io.xpipe.app.fxcomps.impl; import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.fxcomps.CompStructure; import io.xpipe.app.fxcomps.SimpleCompStructure; +import io.xpipe.app.fxcomps.util.LabelGraphic; import io.xpipe.app.fxcomps.util.PlatformThread; import javafx.beans.property.SimpleObjectProperty; @@ -16,23 +17,31 @@ import org.kordamp.ikonli.javafx.FontIcon; public class IconButtonComp extends Comp> { - private final ObservableValue icon; + private final ObservableValue icon; private final Runnable listener; public IconButtonComp(String defaultVal) { + this(new SimpleObjectProperty<>(new LabelGraphic.IconGraphic(defaultVal)), null); + } + + public IconButtonComp(String defaultVal, Runnable listener) { + this(new SimpleObjectProperty<>(new LabelGraphic.IconGraphic(defaultVal)), listener); + } + + public IconButtonComp(LabelGraphic defaultVal) { this(new SimpleObjectProperty<>(defaultVal), null); } - public IconButtonComp(ObservableValue icon) { + public IconButtonComp(ObservableValue icon) { this.icon = icon; this.listener = null; } - public IconButtonComp(String defaultVal, Runnable listener) { + public IconButtonComp(LabelGraphic defaultVal, Runnable listener) { this(new SimpleObjectProperty<>(defaultVal), listener); } - public IconButtonComp(ObservableValue icon, Runnable listener) { + public IconButtonComp(ObservableValue icon, Runnable listener) { this.icon = PlatformThread.sync(icon); this.listener = listener; } @@ -41,18 +50,17 @@ public class IconButtonComp extends Comp> { public CompStructure