Homebrew fixes

This commit is contained in:
crschnick 2023-05-01 09:21:14 +00:00
parent e1fa5a9c52
commit 9f4359a4eb
2 changed files with 25 additions and 28 deletions

View file

@ -9,7 +9,7 @@ import javafx.scene.layout.Region;
import java.time.Instant;
public class HomebrewUpdater extends UpdateHandler {
public class HomebrewUpdater extends GitHubUpdater {
public HomebrewUpdater() {
super(true);
@ -20,31 +20,29 @@ public class HomebrewUpdater extends UpdateHandler {
var snippet = CodeSnippet.builder()
.keyword("brew")
.space()
.keyword("install")
.keyword("upgrade")
.space()
.identifier("--cask")
.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();
}
@Override
public void prepareUpdateImpl() {
var changelogString =
AppDownloads.downloadChangelog(lastUpdateCheckResult.getValue().getVersion(), false);
var changelog = changelogString.orElse(null);
var rel = new PreparedUpdate(
AppProperties.get().getVersion(),
XPipeDistributionType.get().getId(),
lastUpdateCheckResult.getValue().getVersion(),
lastUpdateCheckResult.getValue().getReleaseUrl(),
null,
changelog,
lastUpdateCheckResult.getValue().getAssetType());
preparedUpdate.setValue(rel);
}
}

View file

@ -73,15 +73,14 @@ public enum XPipeDistributionType {
}
if (OsType.getLocal().equals(OsType.MACOS)) {
try (var brewOut = sc.command("brew info xpipe").start()) {
try (var brewOut = sc.command("brew list --casks --versions").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;
}
if (out.lines().anyMatch(s -> {
var split = s.split(" ");
return split.length == 2 && split[0].equals("xpipe") && split[1].equals(AppProperties.get().getVersion());
})) {
return HOMEBREW;
}
}
}