mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 23:20:23 +00:00
Create canonical version information
This commit is contained in:
parent
6df1f70a19
commit
7117b4f6f2
2 changed files with 54 additions and 0 deletions
|
@ -38,6 +38,7 @@ public class AppProperties {
|
|||
boolean debugThreads;
|
||||
Path dataDir;
|
||||
boolean showcase;
|
||||
AppVersion canonicalVersion;
|
||||
|
||||
public AppProperties() {
|
||||
image = ModuleHelper.isImage();
|
||||
|
@ -63,6 +64,7 @@ public class AppProperties {
|
|||
showcase = Optional.ofNullable(System.getProperty("io.xpipe.app.showcase"))
|
||||
.map(Boolean::parseBoolean)
|
||||
.orElse(false);
|
||||
canonicalVersion = AppVersion.parse(version).orElse(null);
|
||||
}
|
||||
|
||||
public static void logSystemProperties() {
|
||||
|
@ -117,4 +119,8 @@ public class AppProperties {
|
|||
|
||||
return AppPrefs.get().developerMode().getValue();
|
||||
}
|
||||
|
||||
public Optional<AppVersion> getCanonicalVersion() {
|
||||
return Optional.ofNullable(canonicalVersion);
|
||||
}
|
||||
}
|
||||
|
|
48
app/src/main/java/io/xpipe/app/core/AppVersion.java
Normal file
48
app/src/main/java/io/xpipe/app/core/AppVersion.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
package io.xpipe.app.core;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Value
|
||||
public class AppVersion implements Comparable<AppVersion> {
|
||||
|
||||
public static Optional<AppVersion> parse(String version) {
|
||||
try {
|
||||
var releaseSplit = version.split("-");
|
||||
var split = releaseSplit[0].split("\\.");
|
||||
var major = Integer.parseInt(split[0]);
|
||||
var minor = split.length > 1 ? Integer.parseInt(split[1]) : 0;
|
||||
var patch = split.length > 2 ? Integer.parseInt(split[2]) : 0;
|
||||
return Optional.of(new AppVersion(major, minor, patch));
|
||||
} catch (Exception ex) {
|
||||
// This can happen on number format exceptions
|
||||
// It shouldn't happen if the version is correctly formatted though
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
int major;
|
||||
int minor;
|
||||
int patch;
|
||||
|
||||
public boolean greaterThan(AppVersion other) {
|
||||
return compareTo(other) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull AppVersion o) {
|
||||
var majorCompare = major - o.major;
|
||||
if (majorCompare != 0) {
|
||||
return majorCompare;
|
||||
}
|
||||
|
||||
var minorCompare = minor - o.minor;
|
||||
if (minorCompare != 0) {
|
||||
return minorCompare;
|
||||
}
|
||||
|
||||
return patch - o.patch;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue