diff --git a/app/src/main/java/io/xpipe/app/update/HomebrewUpdater.java b/app/src/main/java/io/xpipe/app/update/HomebrewUpdater.java new file mode 100644 index 00000000..e064ba5b --- /dev/null +++ b/app/src/main/java/io/xpipe/app/update/HomebrewUpdater.java @@ -0,0 +1,50 @@ +package io.xpipe.app.update; + +import io.xpipe.app.core.AppProperties; +import io.xpipe.app.fxcomps.impl.CodeSnippet; +import io.xpipe.app.fxcomps.impl.CodeSnippetComp; +import io.xpipe.core.store.ShellStore; +import javafx.beans.property.SimpleObjectProperty; +import javafx.scene.layout.Region; + +import java.time.Instant; + +public class HomebrewUpdater extends UpdateHandler { + + public HomebrewUpdater() { + super(true); + } + + @Override + public Region createInterface() { + var snippet = CodeSnippet.builder() + .keyword("brew") + .space() + .keyword("install") + .space() + .string("xpipe") + .identifier("@") + .type(getPreparedUpdate().getValue().getVersion()) + .build(); + return new CodeSnippetComp(false, new SimpleObjectProperty<>(snippet)).createRegion(); + } + + public AvailableRelease refreshUpdateCheckImpl() throws Exception { + try (var sc = ShellStore.createLocal().create().start()) { + var latest = sc.executeStringSimpleCommand( + "choco outdated -r --nocolor").lines().filter(s -> s.startsWith("xpipe")).findAny().orElseThrow().split("\\|")[2]; + var isUpdate = isUpdate(latest); + var rel = new AvailableRelease( + AppProperties.get().getVersion(), + XPipeDistributionType.get().getId(), + latest, + "https://community.chocolatey.org/packages/xpipe/" + latest, + null, + null, + Instant.now(), + isUpdate); + lastUpdateCheckResult.setValue(rel); + return lastUpdateCheckResult.getValue(); + } + } +} diff --git a/app/src/main/java/io/xpipe/app/update/XPipeDistributionType.java b/app/src/main/java/io/xpipe/app/update/XPipeDistributionType.java index cc539155..d6ab9ccf 100644 --- a/app/src/main/java/io/xpipe/app/update/XPipeDistributionType.java +++ b/app/src/main/java/io/xpipe/app/update/XPipeDistributionType.java @@ -5,6 +5,7 @@ import io.xpipe.app.core.AppProperties; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.util.XPipeSession; import io.xpipe.core.impl.LocalStore; +import io.xpipe.core.process.OsType; import io.xpipe.core.util.ModuleHelper; import io.xpipe.core.util.XPipeInstallation; import lombok.Getter; @@ -15,7 +16,8 @@ import java.util.function.Supplier; public enum XPipeDistributionType { DEVELOPMENT("development", () -> new GitHubUpdater(false)), PORTABLE("portable", () -> new PortableUpdater()), - INSTALLATION("install", () -> new GitHubUpdater(true)), + NATIVE_INSTALLATION("install", () -> new GitHubUpdater(true)), + HOMEBREW("homebrew", () -> new HomebrewUpdater()), CHOCO("choco", () -> new ChocoUpdater()); private static XPipeDistributionType type; @@ -53,7 +55,7 @@ public enum XPipeDistributionType { public static XPipeDistributionType determine() { if (!XPipeInstallation.isInstallationDistribution()) { - return (type = PORTABLE); + return PORTABLE; } try (var sc = LocalStore.getShell()) { @@ -69,11 +71,26 @@ public enum XPipeDistributionType { } } } + + if (OsType.getLocal().equals(OsType.MACOS)) { + try (var brewOut = sc.command("brew info xpipe").start()) { + var out = brewOut.readStdoutDiscardErr(); + if (brewOut.getExitCode() == 0) { + var split = out.split("\\|"); + if (split.length == 2) { + var version = split[1]; + if (AppProperties.get().getVersion().equals(version)) { + return HOMEBREW; + } + } + } + } + } } catch (Exception ex) { ErrorEvent.fromThrowable(ex).handle(); } - return XPipeDistributionType.INSTALLATION; + return XPipeDistributionType.NATIVE_INSTALLATION; } @Getter