mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-10-06 04:54:56 +13:00
Initial work for homebrew
This commit is contained in:
parent
9b2d4b7376
commit
e1fa5a9c52
2 changed files with 70 additions and 3 deletions
50
app/src/main/java/io/xpipe/app/update/HomebrewUpdater.java
Normal file
50
app/src/main/java/io/xpipe/app/update/HomebrewUpdater.java
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import io.xpipe.app.core.AppProperties;
|
||||||
import io.xpipe.app.issue.ErrorEvent;
|
import io.xpipe.app.issue.ErrorEvent;
|
||||||
import io.xpipe.app.util.XPipeSession;
|
import io.xpipe.app.util.XPipeSession;
|
||||||
import io.xpipe.core.impl.LocalStore;
|
import io.xpipe.core.impl.LocalStore;
|
||||||
|
import io.xpipe.core.process.OsType;
|
||||||
import io.xpipe.core.util.ModuleHelper;
|
import io.xpipe.core.util.ModuleHelper;
|
||||||
import io.xpipe.core.util.XPipeInstallation;
|
import io.xpipe.core.util.XPipeInstallation;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -15,7 +16,8 @@ import java.util.function.Supplier;
|
||||||
public enum XPipeDistributionType {
|
public enum XPipeDistributionType {
|
||||||
DEVELOPMENT("development", () -> new GitHubUpdater(false)),
|
DEVELOPMENT("development", () -> new GitHubUpdater(false)),
|
||||||
PORTABLE("portable", () -> new PortableUpdater()),
|
PORTABLE("portable", () -> new PortableUpdater()),
|
||||||
INSTALLATION("install", () -> new GitHubUpdater(true)),
|
NATIVE_INSTALLATION("install", () -> new GitHubUpdater(true)),
|
||||||
|
HOMEBREW("homebrew", () -> new HomebrewUpdater()),
|
||||||
CHOCO("choco", () -> new ChocoUpdater());
|
CHOCO("choco", () -> new ChocoUpdater());
|
||||||
|
|
||||||
private static XPipeDistributionType type;
|
private static XPipeDistributionType type;
|
||||||
|
@ -53,7 +55,7 @@ public enum XPipeDistributionType {
|
||||||
|
|
||||||
public static XPipeDistributionType determine() {
|
public static XPipeDistributionType determine() {
|
||||||
if (!XPipeInstallation.isInstallationDistribution()) {
|
if (!XPipeInstallation.isInstallationDistribution()) {
|
||||||
return (type = PORTABLE);
|
return PORTABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
try (var sc = LocalStore.getShell()) {
|
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) {
|
} catch (Exception ex) {
|
||||||
ErrorEvent.fromThrowable(ex).handle();
|
ErrorEvent.fromThrowable(ex).handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
return XPipeDistributionType.INSTALLATION;
|
return XPipeDistributionType.NATIVE_INSTALLATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
|
Loading…
Reference in a new issue