From dec7d9daf6bee5a09f203e1f1f80d54fc7a669b2 Mon Sep 17 00:00:00 2001 From: CodeDead Date: Fri, 30 Oct 2026 22:55:38 +0100 Subject: [PATCH 1/3] feat: dynamically fetch app version and copyright year - Updated `AboutWindowController` to load version and year dynamically into the "About" text. - Centralized version management by introducing `version.properties` and the `loadVersion()` method in `SharedVariables`. - Adjusted build process to inject version and copyright year. - Standardized translations to support `{version}` and `{year}` placeholders. - Improved modular configuration for platform-specific copyright details. --- build.gradle | 14 ++++++-- .../controller/AboutWindowController.java | 9 ++++++ .../codedead/opal/utils/SharedVariables.java | 32 ++++++++++++++++++- .../translations/OpalApplication.properties | 2 +- .../OpalApplication_de_DE.properties | 2 +- .../OpalApplication_en_US.properties | 2 +- .../OpalApplication_es_ES.properties | 2 +- .../OpalApplication_fr_FR.properties | 2 +- .../OpalApplication_hi_IN.properties | 2 +- .../OpalApplication_ja_JP.properties | 2 +- .../OpalApplication_nl_NL.properties | 2 +- .../OpalApplication_ru_RU.properties | 2 +- .../OpalApplication_tr_TR.properties | 2 +- .../OpalApplication_uk_UA.properties | 2 +- .../OpalApplication_zh_CN.properties | 2 +- src/main/resources/version.properties | 1 + src/main/resources/windows/AboutWindow.fxml | 2 +- 17 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 src/main/resources/version.properties diff --git a/build.gradle b/build.gradle index 4f47130..fa1e684 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,5 @@ import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform +import java.time.Year plugins { id 'java' @@ -13,6 +14,7 @@ group 'com.codedead' version '1.5.1' def currentOS = DefaultNativePlatform.currentOperatingSystem +def currentYear = Year.now().getValue() java { toolchain { @@ -28,6 +30,12 @@ tasks.named("updateDaemonJvm") { } } +tasks.named('processResources') { + filesMatching('version.properties') { + expand(version: project.version) + } +} + application { mainModule = 'Opal' mainClass = 'com.codedead.opal.OpalApplication' @@ -60,7 +68,7 @@ jlink { '--win-upgrade-uuid', '876c5464-9a66-4913-89a4-c63a4b8b4bb9', '--win-help-url', 'https://codedead.com/contact', '--win-dir-chooser', - '--copyright', 'Copyright (c) 2026 CodeDead', + '--copyright', "Copyright (c) ${currentYear} CodeDead", '--description', 'Opal is a free and open-source JavaFX application that can play relaxing music in the background', '--vendor', 'CodeDead', '--license-file', 'LICENSE', @@ -76,7 +84,7 @@ jlink { '--linux-shortcut', '--linux-package-name', 'opal-codedead', '--linux-rpm-license-type', 'GPLv3', - '--copyright', 'Copyright (c) 2026 CodeDead', + '--copyright', "Copyright (c) ${currentYear} CodeDead", '--description', 'Opal is a free and open-source JavaFX application that can play relaxing music in the background', '--vendor', 'CodeDead', '--license-file', 'LICENSE', @@ -94,7 +102,7 @@ jlink { installerOptions = [ '--mac-package-name', 'Opal', '--mac-app-category', 'public.app-category.music', - '--copyright', 'Copyright (c) 2026 CodeDead', + '--copyright', "Copyright (c) ${currentYear} CodeDead", '--description', 'Opal is a free and open-source JavaFX application that can play relaxing music in the background', '--vendor', 'CodeDead', '--license-file', 'LICENSE', diff --git a/src/main/java/com/codedead/opal/controller/AboutWindowController.java b/src/main/java/com/codedead/opal/controller/AboutWindowController.java index 83e702b..f39c7cf 100644 --- a/src/main/java/com/codedead/opal/controller/AboutWindowController.java +++ b/src/main/java/com/codedead/opal/controller/AboutWindowController.java @@ -4,14 +4,19 @@ import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.stage.Stage; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.time.Year; import java.util.ResourceBundle; public final class AboutWindowController { + @FXML + private Label lblAbout; + private ResourceBundle translationBundle; private final HelpUtils helpUtils; private final Logger logger; @@ -36,6 +41,10 @@ public void setResourceBundle(final ResourceBundle resourceBundle) { throw new NullPointerException("ResourceBundle cannot be null"); this.translationBundle = resourceBundle; + + lblAbout.setText(resourceBundle.getString("AboutText") + .replace("{version}", SharedVariables.APP_VERSION) + .replace("{year}", Integer.toString(Year.now().getValue()))); } /** diff --git a/src/main/java/com/codedead/opal/utils/SharedVariables.java b/src/main/java/com/codedead/opal/utils/SharedVariables.java index 6b4f5ee..afc70fd 100644 --- a/src/main/java/com/codedead/opal/utils/SharedVariables.java +++ b/src/main/java/com/codedead/opal/utils/SharedVariables.java @@ -1,9 +1,14 @@ package com.codedead.opal.utils; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + public final class SharedVariables { public static final String ICON_URL = "/images/opal.png"; - public static final String CURRENT_VERSION = "1.5.1.0"; + public static final String APP_VERSION = loadVersion(); + public static final String CURRENT_VERSION = APP_VERSION + ".0"; public static final boolean PORTABLE = false; public static final String DEFAULT_LOCALE = "en-US"; @@ -21,6 +26,31 @@ public final class SharedVariables { public static final String LICENSE_RESOURCE_LOCATION = "/documents/license.pdf"; public static final String LICENSE_FILE_LOCATION = PROPERTIES_BASE_PATH + "/license.pdf"; + /** + * Load the application version from the bundled version.properties file + * + * @return The application version + */ + private static String loadVersion() { + try (final InputStream inputStream = SharedVariables.class.getResourceAsStream("/version.properties")) { + if (inputStream == null) { + throw new IllegalStateException("Unable to find version.properties"); + } + + final Properties properties = new Properties(); + properties.load(inputStream); + + final String version = properties.getProperty("version"); + if (version == null || version.isBlank()) { + throw new IllegalStateException("The version property is missing from version.properties"); + } + + return version; + } catch (final IOException ex) { + throw new IllegalStateException("Unable to load version.properties", ex); + } + } + /** * Initialize a new SharedVariables */ diff --git a/src/main/resources/translations/OpalApplication.properties b/src/main/resources/translations/OpalApplication.properties index 867c0d0..7759acb 100644 --- a/src/main/resources/translations/OpalApplication.properties +++ b/src/main/resources/translations/OpalApplication.properties @@ -1,5 +1,5 @@ About=About -AboutText=Opal was created by DeadLine\n\nAudio: ZapSplat.com\nImages: Remix Icon\nTheme: AtlantaFX\nVersion: 1.5.1\n\nCopyright © 2026 CodeDead +AboutText=Opal was created by DeadLine\n\nAudio: ZapSplat.com\nImages: Remix Icon\nTheme: AtlantaFX\nVersion: {version}\n\nCopyright © {year} CodeDead AboutWindowError=Unable to open the About Window! AboutWindowTitle=Opal - About AutoUpdate=Automatically check for updates diff --git a/src/main/resources/translations/OpalApplication_de_DE.properties b/src/main/resources/translations/OpalApplication_de_DE.properties index c68dcc9..6660200 100644 --- a/src/main/resources/translations/OpalApplication_de_DE.properties +++ b/src/main/resources/translations/OpalApplication_de_DE.properties @@ -1,5 +1,5 @@ About=Über -AboutText=Opal wurde erstellt von: DeadLine\n\nAudio: ZapSplat.com\nBilder: Remix Icon\nDesign: AtlantaFX\nÜbersetzung: github.com/uDEV2019\nVersion: 1.5.1\n\nCopyright © 2026 CodeDead +AboutText=Opal wurde erstellt von: DeadLine\n\nAudio: ZapSplat.com\nBilder: Remix Icon\nDesign: AtlantaFX\nÜbersetzung: github.com/uDEV2019\nVersion: {version}\n\nCopyright © {year} CodeDead AboutWindowError=Über-Dialog konnte nicht geöffnet werden! AboutWindowTitle=Opal - Über AutoUpdate=Automatisch auf Aktualisierungen prüfen diff --git a/src/main/resources/translations/OpalApplication_en_US.properties b/src/main/resources/translations/OpalApplication_en_US.properties index 867c0d0..7759acb 100644 --- a/src/main/resources/translations/OpalApplication_en_US.properties +++ b/src/main/resources/translations/OpalApplication_en_US.properties @@ -1,5 +1,5 @@ About=About -AboutText=Opal was created by DeadLine\n\nAudio: ZapSplat.com\nImages: Remix Icon\nTheme: AtlantaFX\nVersion: 1.5.1\n\nCopyright © 2026 CodeDead +AboutText=Opal was created by DeadLine\n\nAudio: ZapSplat.com\nImages: Remix Icon\nTheme: AtlantaFX\nVersion: {version}\n\nCopyright © {year} CodeDead AboutWindowError=Unable to open the About Window! AboutWindowTitle=Opal - About AutoUpdate=Automatically check for updates diff --git a/src/main/resources/translations/OpalApplication_es_ES.properties b/src/main/resources/translations/OpalApplication_es_ES.properties index 770e722..f84e56e 100644 --- a/src/main/resources/translations/OpalApplication_es_ES.properties +++ b/src/main/resources/translations/OpalApplication_es_ES.properties @@ -1,5 +1,5 @@ About=Acerca de -AboutText=Opal fue creado por DeadLine\n\nAudio: ZapSplat.com\nImágenes: Remix Icon\nTema: AtlantaFX\nVersión: 1.5.1\n\nCopyright © 2026 CodeDead +AboutText=Opal fue creado por DeadLine\n\nAudio: ZapSplat.com\nImágenes: Remix Icon\nTema: AtlantaFX\nVersión: {version}\n\nCopyright © {year} CodeDead AboutWindowError=¡No se puede abrir la ventana Acerca de! AboutWindowTitle=Opal - Acerca de AutoUpdate=Buscar actualizaciones automáticamente diff --git a/src/main/resources/translations/OpalApplication_fr_FR.properties b/src/main/resources/translations/OpalApplication_fr_FR.properties index 725ae0e..73116a1 100644 --- a/src/main/resources/translations/OpalApplication_fr_FR.properties +++ b/src/main/resources/translations/OpalApplication_fr_FR.properties @@ -1,5 +1,5 @@ About=À propos -AboutText=Opal a été créé par DeadLine\n\nAudio: ZapSplat.com\nImages: Remix Icon\nThème: AtlantaFX\nVersion: 1.5.1\n\nCopyright © 2026 CodeDead +AboutText=Opal a été créé par DeadLine\n\nAudio: ZapSplat.com\nImages: Remix Icon\nThème: AtlantaFX\nVersion: {version}\n\nCopyright © {year} CodeDead AboutWindowError=Impossible d'ouvrir la fenêtre À propos! AboutWindowTitle=Opal - À propos AutoUpdate=Rechercher automatiquement les mises à jour diff --git a/src/main/resources/translations/OpalApplication_hi_IN.properties b/src/main/resources/translations/OpalApplication_hi_IN.properties index c8eae90..ae6c6fe 100644 --- a/src/main/resources/translations/OpalApplication_hi_IN.properties +++ b/src/main/resources/translations/OpalApplication_hi_IN.properties @@ -1,5 +1,5 @@ About=के बारे में -AboutText=ओपल को डेडलाइन द्वारा बनाया गया था\n\nऑडियो: ZapSplat.com\nछवियाँ: रीमिक्स आइकन\nथीम: अटलांटाFX\nसंस्करण: 1.5.1\n\nCopyright © 2026 CodeDead +AboutText=ओपल को डेडलाइन द्वारा बनाया गया था\n\nऑडियो: ZapSplat.com\nछवियाँ: रीमिक्स आइकन\nथीम: अटलांटाFX\nसंस्करण: {version}\n\nCopyright © {year} CodeDead AboutWindowError=About विंडो खोलने में असमर्थ! AboutWindowTitle=Opal - के बारे में AutoUpdate=अपडेट के लिए स्वचालित रूप से जाँच करें diff --git a/src/main/resources/translations/OpalApplication_ja_JP.properties b/src/main/resources/translations/OpalApplication_ja_JP.properties index d603769..9784877 100644 --- a/src/main/resources/translations/OpalApplication_ja_JP.properties +++ b/src/main/resources/translations/OpalApplication_ja_JP.properties @@ -1,5 +1,5 @@ About=このアプリについて -AboutText=Opal は DeadLine によって作成されました\n\nオーディオ: ZapSplat.com\n画像: リミックス アイコン\nテーマ: AtlantaFX\nバージョン: 1.5.1\n\nCopyright © 2026 CodeDead +AboutText=Opal は DeadLine によって作成されました\n\nオーディオ: ZapSplat.com\n画像: リミックス アイコン\nテーマ: AtlantaFX\nバージョン: {version}\n\nCopyright © {year} CodeDead AboutWindowError=このアプリについてのウィンドウを開けません! AboutWindowTitle=Opal - このアプリについて AutoUpdate=アップデートを自動的に確認する diff --git a/src/main/resources/translations/OpalApplication_nl_NL.properties b/src/main/resources/translations/OpalApplication_nl_NL.properties index 5119ca9..6f02d64 100644 --- a/src/main/resources/translations/OpalApplication_nl_NL.properties +++ b/src/main/resources/translations/OpalApplication_nl_NL.properties @@ -1,5 +1,5 @@ About=Over -AboutText=Opal is gemaakt door DeadLine\n\nAudio: ZapSplat.com\nAfbeeldingen: Remix Icon\nThema: AtlantaFX\nVersie: 1.5.1\n\nCopyright © 2026 CodeDead +AboutText=Opal is gemaakt door DeadLine\n\nAudio: ZapSplat.com\nAfbeeldingen: Remix Icon\nThema: AtlantaFX\nVersie: {version}\n\nCopyright © {year} CodeDead AboutWindowError=Kan het Over venster niet openen! AboutWindowTitle=Opal - Over AutoUpdate=Automatisch controleren op updates diff --git a/src/main/resources/translations/OpalApplication_ru_RU.properties b/src/main/resources/translations/OpalApplication_ru_RU.properties index 64b5b52..1056284 100644 --- a/src/main/resources/translations/OpalApplication_ru_RU.properties +++ b/src/main/resources/translations/OpalApplication_ru_RU.properties @@ -1,5 +1,5 @@ About=О программе -AboutText=Opal был создан DeadLine\n\nАудио: ZapSplat.com\nИзображения: Remix Icon\nТема: AtlantaFX\nВерсия: 1.5.1\n\nАвторские права © 2026 CodeDead +AboutText=Opal был создан DeadLine\n\nАудио: ZapSplat.com\nИзображения: Remix Icon\nТема: AtlantaFX\nВерсия: {version}\n\nАвторские права © {year} CodeDead AboutWindowError=Не удается открыть окно «О программе»! AboutWindowTitle=Opal - О программе AutoUpdate=Автоматически проверять наличие обновлений diff --git a/src/main/resources/translations/OpalApplication_tr_TR.properties b/src/main/resources/translations/OpalApplication_tr_TR.properties index 6987703..6a8400b 100644 --- a/src/main/resources/translations/OpalApplication_tr_TR.properties +++ b/src/main/resources/translations/OpalApplication_tr_TR.properties @@ -1,5 +1,5 @@ About=Hakkında -AboutText=Opal, DeadLine tarafından oluşturuldu\n\nSes: ZapSplat.com\nGörüntüler: Remix Simgesi\nTema: AtlantaFX\nSürüm: 1.5.1\n\nTelif hakkı © 2026 CodeDead +AboutText=Opal, DeadLine tarafından oluşturuldu\n\nSes: ZapSplat.com\nGörüntüler: Remix Simgesi\nTema: AtlantaFX\nSürüm: {version}\n\nTelif hakkı © {year} CodeDead AboutWindowError=Hakkında Penceresi açılamıyor! AboutWindowTitle=Opal - Hakkında AutoUpdate=Güncellemeleri otomatik olarak kontrol et diff --git a/src/main/resources/translations/OpalApplication_uk_UA.properties b/src/main/resources/translations/OpalApplication_uk_UA.properties index 61200c2..f8c7f76 100644 --- a/src/main/resources/translations/OpalApplication_uk_UA.properties +++ b/src/main/resources/translations/OpalApplication_uk_UA.properties @@ -1,5 +1,5 @@ About=Про -AboutText=Opal був створений компанією DeadLine\n\nАудіо: ZapSplat.com\nЗображення: Remix Icon\nТема: AtlantaFX\nВерсія: 1.5.1\n\nCopyright © 2026 CodeDead +AboutText=Opal був створений компанією DeadLine\n\nАудіо: ZapSplat.com\nЗображення: Remix Icon\nТема: AtlantaFX\nВерсія: {version}\n\nCopyright © {year} CodeDead AboutWindowError=Не вдається відкрити вікно "Про програму"! AboutWindowTitle=Opal - Про AutoUpdate=Автоматично перевіряти наявність оновлень diff --git a/src/main/resources/translations/OpalApplication_zh_CN.properties b/src/main/resources/translations/OpalApplication_zh_CN.properties index 35efe79..6926dff 100644 --- a/src/main/resources/translations/OpalApplication_zh_CN.properties +++ b/src/main/resources/translations/OpalApplication_zh_CN.properties @@ -1,5 +1,5 @@ About=关于 -AboutText=Opal 由 DeadLine 制作\n\n音频:ZapSplat.com\n图像:Remix Icon\n主题:AtlantaFX\n版本:1.5.1\n\nCopyright © 2026 CodeDead +AboutText=Opal 由 DeadLine 制作\n\n音频:ZapSplat.com\n图像:Remix Icon\n主题:AtlantaFX\n版本:{version}\n\nCopyright © {year} CodeDead AboutWindowError=无法打开“关于”窗口! AboutWindowTitle=Opal - 关于 AutoUpdate=自动检查更新 diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties new file mode 100644 index 0000000..a50bf5c --- /dev/null +++ b/src/main/resources/version.properties @@ -0,0 +1 @@ +version=${version} diff --git a/src/main/resources/windows/AboutWindow.fxml b/src/main/resources/windows/AboutWindow.fxml index 24035de..eb3b312 100644 --- a/src/main/resources/windows/AboutWindow.fxml +++ b/src/main/resources/windows/AboutWindow.fxml @@ -40,7 +40,7 @@ -