Skip to content

Commit

Permalink
feat: Show version type on main window
Browse files Browse the repository at this point in the history
  • Loading branch information
half-nothing committed Jan 6, 2025
1 parent 0f5e0f2 commit 9ea036d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ allprojects {
}

tasks {
withType<JavaCompile>().configureEach() {
withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release.set(targetJavaVersion)
}
Expand All @@ -83,6 +83,7 @@ allprojects {
"Build-By" to System.getProperty("user.name"),
"Build-TimeStamp" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(Date()),
"Build-Version" to version,
"Version-Type" to getVersionMetadata(),
"Created-By" to "Gradle ${gradle.gradleVersion}",
"Build-Jdk" to "${System.getProperty("java.version")} " +
"(${System.getProperty("java.vendor")} ${System.getProperty("java.vm.version")})",
Expand Down
33 changes: 30 additions & 3 deletions desktop/src/cn/harryh/arkpets/ArkHomeFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@
import javafx.stage.Window;
import javafx.util.Duration;

import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL;
import java.security.CodeSource;
import java.util.Objects;
import java.util.UUID;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

import static cn.harryh.arkpets.Const.*;

Expand Down Expand Up @@ -58,7 +64,7 @@ public void start(Stage stage) throws Exception {
// Load FXML for root node.
LoadFXMLResult<ArkHomeFX> fxml0 = FXMLHelper.loadFXML(getClass().getResource("/UI/RootModule.fxml"));
fxml0.initializeWith(this);
rootModule = (RootModule)fxml0.controller();
rootModule = (RootModule) fxml0.controller();
body = rootModule.body;

// Setup scene and primary stage.
Expand All @@ -70,8 +76,9 @@ public void start(Stage stage) throws Exception {
stage.initStyle(StageStyle.TRANSPARENT);
stage.setResizable(false);
stage.setScene(scene);
stage.setTitle(desktopTitle);
rootModule.titleText.setText(desktopTitle);
String title = desktopTitle + getVersionType();
stage.setTitle(title);
rootModule.titleText.setText(title);

// After the stage is shown, do initialization.
stage.show();
Expand Down Expand Up @@ -137,6 +144,26 @@ public void stop() {
Logger.debug("Launcher", "Finished stopping");
}

public String getVersionType() {
Class<?> clazz = this.getClass();
try {
CodeSource codeSource = clazz.getProtectionDomain().getCodeSource();
if (codeSource == null) {
return "+unknown";
}
URL jarUrl = codeSource.getLocation();
JarFile jarFile = new JarFile(new File(jarUrl.toURI()));
Manifest manifest = jarFile.getManifest();
jarFile.close();
return manifest.getMainAttributes().getValue("Version-Type");
} catch (FileNotFoundException ignored) {
// this mean run through gradle or IDEA
return "+dev";
} catch (Exception ignored) {
return "+unknown";
}
}

public void popLoading(EventHandler<ActionEvent> handler) {
rootModule.popLoading(handler);
}
Expand Down

0 comments on commit 9ea036d

Please sign in to comment.