feat: Implement version checking and update notification in dashboard

- Added functionality to fetch the latest GitHub release version.
- Enhanced the dashboard to display current and latest version information.
- Updated the version comparison logic to handle special cases and non-semver formats.
- Improved the dashboard template to link to the latest release on GitHub.
This commit is contained in:
StarFleetCPTN committed 2025-04-11 20:29:47 -07:00
1 parent 82f73cfe60
commit e9a005b658
3 files changed
+54 -4

No files matched your search

+12 -1
View File
@@ -50,6 +50,11 @@ func isNewerVersionAvailable(current, latest string) bool {
return false
}
// Special case for DEV versions - always show update available
if current == "DEV" {
return true
}
// Strip 'v' prefix if present for comparison
if strings.HasPrefix(current, "v") {
current = current[1:]
@@ -62,6 +67,12 @@ func isNewerVersionAvailable(current, latest string) bool {
currentParts := strings.Split(current, ".")
latestParts := strings.Split(latest, ".")
// Handle non-semver format in either version
if len(currentParts) < 2 || len(latestParts) < 2 {
// If format doesn't match semver pattern, do string comparison
return current != latest && latest != ""
}
// Compare major, minor, patch versions
for i := 0; i < len(currentParts) && i < len(latestParts); i++ {
// Parse to integers
@@ -310,7 +321,7 @@ templ Dashboard(ctx context.Context, data DashboardData) {
<i class="fas fa-exclamation-triangle w-3 h-3 mr-1"></i>
{ data.CurrentVersion }
</span>
<a href="https://github.com/starfleetcptn/gomft/releases/tag/{ data.LatestVersion }" target="_blank"
<a href={ templ.SafeURL(fmt.Sprintf("https://github.com/starfleetcptn/gomft/releases/tag/%s", data.LatestVersion)) } target="_blank"
class="bg-green-100 text-green-800 text-xs font-medium inline-flex items-center px-2.5 py-0.5 rounded-full dark:bg-green-900 dark:text-green-300 hover:bg-green-200 dark:hover:bg-green-800">
<i class="fas fa-arrow-circle-up w-3 h-3 mr-1"></i>
{ data.LatestVersion } Available
+3 -3
View File
@@ -364,7 +364,7 @@ templ LayoutWithContext(title string, ctx context.Context) {
hx-get="/notifications/dropdown"
hx-trigger="click once"
hx-target="#notification-dropdown-content"
data-dropdown-placement="bottom-end"
data-dropdown-placement="bottom-start"
>
<span class="sr-only">View notifications</span>
<i class="fas fa-bell"></i>
@@ -375,10 +375,10 @@ templ LayoutWithContext(title string, ctx context.Context) {
</div>
<!-- Notification dropdown -->
<div
class="hidden overflow-hidden z-50 my-4 max-w-sm md:max-w-md w-full text-base list-none bg-white rounded divide-y divide-gray-100 shadow-lg dark:divide-gray-600 dark:bg-gray-700 rounded-xl"
class="hidden overflow-hidden z-50 my-4 max-w-sm md:max-w-md w-full text-base list-none bg-white rounded divide-y divide-gray-100 shadow-lg dark:divide-gray-600 dark:bg-gray-700 rounded-xl fixed"
id="notification-dropdown"
style="min-width: 320px; width: 100%;"
data-dropdown-placement="bottom-end"
data-dropdown-placement="bottom-start"
>
<div id="notification-dropdown-content">
<!-- Content will be loaded dynamically via HTMX -->