diff --git a/app/src/main/java/io/xpipe/app/core/AppDistributionType.java b/app/src/main/java/io/xpipe/app/core/AppDistributionType.java index ee357cb73..61c24588c 100644 --- a/app/src/main/java/io/xpipe/app/core/AppDistributionType.java +++ b/app/src/main/java/io/xpipe/app/core/AppDistributionType.java @@ -2,12 +2,10 @@ package io.xpipe.app.core; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.issue.TrackEvent; -import io.xpipe.app.update.GitHubUpdater; -import io.xpipe.app.update.PortableUpdater; -import io.xpipe.app.update.UpdateHandler; -import io.xpipe.app.update.WebtopUpdater; +import io.xpipe.app.update.*; import io.xpipe.app.util.LocalExec; import io.xpipe.app.util.Translatable; +import io.xpipe.core.process.CommandBuilder; import io.xpipe.core.process.OsType; import io.xpipe.core.util.XPipeInstallation; @@ -25,11 +23,19 @@ public enum AppDistributionType implements Translatable { DEVELOPMENT("development", true, () -> new GitHubUpdater(false)), PORTABLE("portable", false, () -> new PortableUpdater(true)), NATIVE_INSTALLATION("install", true, () -> new GitHubUpdater(true)), - HOMEBREW("homebrew", true, () -> new PortableUpdater(true)), - APT_REPO("apt", true, () -> new PortableUpdater(true)), - RPM_REPO("rpm", true, () -> new PortableUpdater(true)), + HOMEBREW("homebrew", true, () -> { + return new CommandUpdater(CommandBuilder.of().add("brew", "upgrade", "--cask", AppProperties.get().isStaging() ? "xpipe-io/pbb/xpipe-ptb" : "xpipe-io/tap/xpipe")); + }), + APT_REPO("apt", true, () -> { + return new CommandUpdater(CommandBuilder.of().add("sudo", "apt", "update", "&&", "sudo", "apt", "install", AppProperties.get().isStaging() ? "xpipe-ptb" : "xpipe")); + }), + RPM_REPO("rpm", true, () -> { + return new CommandUpdater(CommandBuilder.of().add("sudo", "yum", "upgrade", AppProperties.get().isStaging() ? "xpipe-ptb" : "xpipe", "--refresh")); + }), WEBTOP("webtop", true, () -> new WebtopUpdater()), - CHOCO("choco", true, () -> new PortableUpdater(true)); + CHOCO("choco", true, () -> { + return new CommandUpdater(CommandBuilder.of().add("choco", "upgrade", AppProperties.get().isStaging() ? "xpipe-ptb" : "xpipe")); + }); private static AppDistributionType type; diff --git a/app/src/main/java/io/xpipe/app/update/CommandUpdater.java b/app/src/main/java/io/xpipe/app/update/CommandUpdater.java new file mode 100644 index 000000000..495d652ed --- /dev/null +++ b/app/src/main/java/io/xpipe/app/update/CommandUpdater.java @@ -0,0 +1,66 @@ +package io.xpipe.app.update; + +import io.xpipe.app.comp.base.ModalButton; +import io.xpipe.app.core.AppCache; +import io.xpipe.app.issue.ErrorEvent; +import io.xpipe.app.terminal.TerminalLauncher; +import io.xpipe.app.util.DocumentationLink; +import io.xpipe.app.util.Hyperlinks; +import io.xpipe.app.util.LocalShell; +import io.xpipe.core.process.CommandBuilder; + +import java.nio.file.Files; +import java.util.List; + +public class CommandUpdater extends PortableUpdater { + + private final CommandBuilder command; + + public CommandUpdater(CommandBuilder command) { + super(true); + this.command = command; + } + + @Override + public boolean supportsDirectInstallation() { + return true; + } + + @Override + public List createActions() { + var l = super.createActions(); + l.add(new ModalButton("ignore", null, true, false)); + l.add(new ModalButton( + "checkOutUpdate", + () -> { + if (getPreparedUpdate().getValue() == null) { + return; + } + + Hyperlinks.open(getPreparedUpdate().getValue().getReleaseUrl()); + }, + false, + false)); + l.add(new ModalButton( + "install", + () -> { + executeUpdateAndClose(); + }, + true, + true)); + return l; + } + + @Override + public void executeUpdate() { + try { + var p = preparedUpdate.getValue(); + var performedUpdate = new PerformedUpdate(p.getVersion(), p.getBody(), p.getVersion()); + AppCache.update("performedUpdate", performedUpdate); + TerminalLauncher.openDirect("Update", command); + } catch (Throwable t) { + ErrorEvent.fromThrowable(t).handle(); + preparedUpdate.setValue(null); + } + } +} diff --git a/version b/version index e18354d8d..d0968bd3c 100644 --- a/version +++ b/version @@ -1 +1 @@ -16.0-29 +16.0-30