mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-09-26 10:25:44 +00:00
Rework [stage]
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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<ModalButton> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user