Skip to content

Commit

Permalink
#21 Add About-Dialog and a check for a newer github release version o…
Browse files Browse the repository at this point in the history
…n startup
  • Loading branch information
patschuh committed Feb 28, 2022
1 parent 476250d commit 0a043e7
Show file tree
Hide file tree
Showing 11 changed files with 510 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -155,4 +155,8 @@ Check the settings.yaml in the <user.home>/.kafkaesque directory for cluster ind
* default.key.messagetype: configures the default Key MessageType to use if no configuration was saved for the topic yet</span>.
* <span style="color:gray">default: STRING</span>
* default.value.messagetype: configures the default Value MessageType to use if no configuration was saved for the topic yet</span>.
* <span style="color:gray">default: STRING</span>
* <span style="color:gray">default: STRING</span>
* check.for.updates.enabled: configures if KafkaEsque checks github-releases for a newer version on startup</span>.
* <span style="color:gray">default: true</span>
* check.for.updates.duration.between.hours: configures how many hours a check of the latest version on github is valid before it is checked again</span>.
* <span style="color:gray">default: 24</span>
28 changes: 28 additions & 0 deletions build.gradle
@@ -1,9 +1,12 @@
import org.gradle.internal.jvm.Jvm
import org.gradle.internal.os.OperatingSystem
import java.text.SimpleDateFormat

plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.beryx.runtime' version '1.12.7'
id "org.ajoberstar.grgit" version "5.0.0"
}

group = 'at.esque.kafka'
Expand All @@ -20,6 +23,9 @@ repositories {
maven {
url = 'https://repository.mulesoft.org/nexus/content/repositories/public/'
}
maven{
url = 'https://repo.gradle.org/gradle/libs-releases-local/'
}
}

dependencies {
Expand All @@ -39,6 +45,7 @@ dependencies {
implementation 'com.dlsc.formsfx:formsfx-core:11.4.2'
implementation 'org.sourcelab:kafka-connect-client:3.1.2'
implementation 'org.controlsfx:controlsfx:11.1.1'
implementation 'org.gradle:gradle-core:6.1.1'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.springframework.kafka:spring-kafka-test:2.4.13.RELEASE'
Expand Down Expand Up @@ -84,3 +91,24 @@ runtime {
}
}
}

task versionFile() {
doLast {
mkdir "$buildDir/resources/main"
new File("$buildDir/resources/main", "version.json").text = """{
"version": "$version",
"revision": "${grgit.head().abbreviatedId}",
"tag": ${
var tag = grgit.tag.list().find{ it.commit == grgit.head() }
if(tag != null){
return "\""+tag.getName()+"\""
}
},
"buildTime": "${new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())}",
"buildJvm": "${Jvm.current()}",
"name": "KakfaEsque"
}"""
}
}

tasks.named('processResources') { dependsOn('versionFile')}
50 changes: 50 additions & 0 deletions src/main/java/at/esque/kafka/AboutController.java
@@ -0,0 +1,50 @@
package at.esque.kafka;

import at.esque.kafka.handlers.VersionInfo;
import at.esque.kafka.handlers.VersionInfoHandler;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class AboutController {
public ImageView imageView;
public HBox infoContainer;
public Text infoText;
public Label releaseVersion;
public Label runtimeVersion;
public Label buildJvm;
public Label buildTime;

public void setup(VersionInfoHandler versionInfoHandler) {
final VersionInfo versionInfo = versionInfoHandler.getVersionInfo();
final String tag = versionInfo.getTag();
infoContainer.setVisible(false);
if(tag != null){
releaseVersion.setText(tag);
} else {
releaseVersion.setText(versionInfo.getVersion() +" (" + versionInfo.getRevision() + ")");
infoContainer.setVisible(true);
infoText.setText("This is not a release version!\nNo update checks will be performed");
}
buildJvm.setText(versionInfo.getBuildJvm());
buildTime.setText(versionInfo.getBuildTime());
runtimeVersion.setText(System.getProperty("java.version"));
}

public void clickGithubLink(MouseEvent mouseEvent) {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
try {
Desktop.getDesktop().browse(new URI("https://github.com/patschuh/KafkaEsque"));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
}
}
26 changes: 26 additions & 0 deletions src/main/java/at/esque/kafka/Controller.java
Expand Up @@ -24,6 +24,7 @@
import at.esque.kafka.handlers.ConsumerHandler;
import at.esque.kafka.handlers.ProducerHandler;
import at.esque.kafka.handlers.Settings;
import at.esque.kafka.handlers.VersionInfoHandler;
import at.esque.kafka.lag.viewer.LagViewerController;
import at.esque.kafka.topics.CreateTopicController;
import at.esque.kafka.topics.DescribeTopicController;
Expand Down Expand Up @@ -148,6 +149,8 @@ public class Controller {
@Inject
private ConfigHandler configHandler;
@Inject
private VersionInfoHandler versionInfoHandler;
@Inject
private Injector injector;

//FXML
Expand Down Expand Up @@ -268,6 +271,8 @@ public void setup(Stage controlledStage) {
ClusterConfig dummycluster = new ClusterConfig();
dummycluster.setIdentifier("Empty");
messageTabPane.getTabs().add(createTab(dummycluster, "Tab"));

versionInfoHandler.showDialogIfUpdateIsAvailable();
}

private void setupJsonFormatToggle() {
Expand Down Expand Up @@ -562,6 +567,7 @@ public void schemaRegistryClick(ActionEvent event) {
stage.initModality(Modality.NONE);
stage.setTitle("Browse Schema Registry - " + selectedConfig.getIdentifier());
stage.setScene(Main.createStyledScene(root1, -1, -1));
stage.setResizable(false);
stage.show();
centerStageOnControlledStage(stage);
} catch (Exception e) {
Expand Down Expand Up @@ -1359,4 +1365,24 @@ private PinTab createTab(ClusterConfig clusterConfig, String name) {
private void updateTabName(PinTab tab, ClusterConfig clusterConfig, String name) {
Platform.runLater(() -> tab.setText(clusterConfig.getIdentifier() + " - " + name));
}

@FXML
public void aboutClick(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/about.fxml"));
Parent root1 = fxmlLoader.load();
AboutController controller = fxmlLoader.getController();
controller.setup(versionInfoHandler);
Stage stage = new Stage();
stage.getIcons().add(new Image(getClass().getResourceAsStream("/icons/kafkaesque.png")));
stage.initOwner(controlledStage);
stage.initModality(Modality.APPLICATION_MODAL);
stage.setTitle("About KafkaEsque");
stage.setScene(Main.createStyledScene(root1, -1, -1));
stage.show();
centerStageOnControlledStage(stage);
} catch (Exception e) {
ErrorAlert.show(e, controlledStage);
}
}
}
29 changes: 29 additions & 0 deletions src/main/java/at/esque/kafka/handlers/ConfigHandler.java
Expand Up @@ -165,6 +165,14 @@ private boolean setDefaultsIfMissing() {
settings.put(Settings.DEFAULT_VALUE_MESSAGE_TYPE, Settings.DEFAULT_VALUE_MESSAGE_TYPE_DEFAULT);
changed = true;
}
if (!settings.containsKey(Settings.CHECK_FOR_UPDATES_ENABLED)) {
settings.put(Settings.CHECK_FOR_UPDATES_ENABLED, Settings.CHECK_FOR_UPDATES_ENABLED_DEFAULT);
changed = true;
}
if (!settings.containsKey(Settings.CHECK_FOR_UPDATES_DURATION_BETWEEN_HOURS)) {
settings.put(Settings.CHECK_FOR_UPDATES_DURATION_BETWEEN_HOURS, Settings.CHECK_FOR_UPDATES_DURATION_BETWEEN_HOURS_DEFAULT);
changed = true;
}
return changed;
}

Expand Down Expand Up @@ -335,4 +343,25 @@ public void configureKafkaEsqueCodeArea(KafkaEsqueCodeArea kafkaEsqueCodeArea) {
}
}
}

public Map<String, Object> getVersionCheckContent() {
File versionCheckFile = new File(String.format(CONFIG_DIRECTORY, "versionCheck.yaml"));
if (versionCheckFile.exists()) {
try {
return (Map<String, Object>) objectMapper.readValue(versionCheckFile, Map.class);
} catch (IOException e) {
return null;
}
}
return null;
}

public void writeVersionCheckContent(Map<String, Object> content) {
File versionCheckFile = new File(String.format(CONFIG_DIRECTORY, "versionCheck.yaml"));
try {
objectMapper.writeValue(versionCheckFile, content);
} catch (IOException e) {
ErrorAlert.show(e);
}
}
}
11 changes: 11 additions & 0 deletions src/main/java/at/esque/kafka/handlers/Settings.java
Expand Up @@ -35,6 +35,10 @@ private Settings() {
public static final String DEFAULT_KEY_MESSAGE_TYPE_DEFAULT = "STRING";
public static final String DEFAULT_VALUE_MESSAGE_TYPE = "default.value.messagetype";
public static final String DEFAULT_VALUE_MESSAGE_TYPE_DEFAULT = "STRING";
public static final String CHECK_FOR_UPDATES_ENABLED = "check.for.updates.enabled";
public static final String CHECK_FOR_UPDATES_ENABLED_DEFAULT = "true";
public static final String CHECK_FOR_UPDATES_DURATION_BETWEEN_HOURS = "check.for.updates.duration.between.hours";
public static final String CHECK_FOR_UPDATES_DURATION_BETWEEN_HOURS_DEFAULT = "24";

public static List<Duration> readDurationSetting(Map<String, String> settings) {
return readDurationSetting(settings.get(TRACE_QUICK_SELECT_DURATION_LIST));
Expand All @@ -47,6 +51,13 @@ public static boolean isTraceQuickSelectEnabled(Map<String, String> settings) {
return Boolean.parseBoolean(settings.get(TRACE_QUICK_SELECT_ENABLED));
}

public static boolean isCheckForUpdatesEnabled(Map<String, String> settings) {
if (settings == null) {
return false;
}
return Boolean.parseBoolean(settings.get(CHECK_FOR_UPDATES_ENABLED));
}

public static List<Duration> readDurationSetting(String setting) {
if (setting == null) {
return new ArrayList<>();
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/at/esque/kafka/handlers/UpdateInfo.java
@@ -0,0 +1,38 @@
package at.esque.kafka.handlers;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class UpdateInfo {
private StringProperty tag = new SimpleStringProperty();
private StringProperty releasePage = new SimpleStringProperty();

public UpdateInfo(String tag, String releasePage) {
this.tag.set(tag);
this.releasePage.set(releasePage);
}

public String getTag() {
return tag.get();
}

public StringProperty tagProperty() {
return tag;
}

public void setTag(String tag) {
this.tag.set(tag);
}

public String getReleasePage() {
return releasePage.get();
}

public StringProperty releasePageProperty() {
return releasePage;
}

public void setReleasePage(String releasePage) {
this.releasePage.set(releasePage);
}
}
94 changes: 94 additions & 0 deletions src/main/java/at/esque/kafka/handlers/VersionInfo.java
@@ -0,0 +1,94 @@
package at.esque.kafka.handlers;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import org.gradle.util.VersionNumber;

public class VersionInfo {
private StringProperty name = new SimpleStringProperty();
private StringProperty version = new SimpleStringProperty();
private StringProperty revision = new SimpleStringProperty();
private StringProperty tag = new SimpleStringProperty();
private StringProperty buildTime = new SimpleStringProperty();
private StringProperty buildJvm = new SimpleStringProperty();


public String getName() {
return name.get();
}

public StringProperty nameProperty() {
return name;
}

public void setName(String name) {
this.name.set(name);
}

public String getVersion() {
return version.get();
}

public StringProperty versionProperty() {
return version;
}

public void setVersion(String version) {
this.version.set(version);
}

public String getRevision() {
return revision.get();
}

public StringProperty revisionProperty() {
return revision;
}

public void setRevision(String revision) {
this.revision.set(revision);
}

public String getTag() {
return tag.get();
}

public StringProperty tagProperty() {
return tag;
}

public void setTag(String tag) {
this.tag.set(tag);
}

public String getBuildTime() {
return buildTime.get();
}

public StringProperty buildTimeProperty() {
return buildTime;
}

public void setBuildTime(String buildTime) {
this.buildTime.set(buildTime);
}

public String getBuildJvm() {
return buildJvm.get();
}

public StringProperty buildJvmProperty() {
return buildJvm;
}

public void setBuildJvm(String buildJvm) {
this.buildJvm.set(buildJvm);
}

public VersionNumber releaseVersion(){
if(tag.get() == null){
return null;
}
return VersionNumber.parse(tag.get().substring(1));
}
}

0 comments on commit 0a043e7

Please sign in to comment.