From 1c0459683beab168e0276351a3572952c71f9eb8 Mon Sep 17 00:00:00 2001 From: StarFleetCPTN Date: Fri, 11 Apr 2025 18:14:52 -0700 Subject: [PATCH] feat: Add version check functionality to dashboard - Introduced new fields for LatestVersion and CurrentVersion in DashboardData struct. - Implemented isNewerVersionAvailable function to compare current and latest versions. - Updated dashboard template to display application version and notify users of available updates with appropriate styling. --- components/dashboard.templ | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/components/dashboard.templ b/components/dashboard.templ index db5ca3c..9a8b6ac 100644 --- a/components/dashboard.templ +++ b/components/dashboard.templ @@ -16,6 +16,8 @@ type DashboardData struct { FailedTransfers int Configs map[uint]db.TransferConfig RcloneVersion string + LatestVersion string + CurrentVersion string } // GetRcloneVersion executes the rclone --version command and returns the version string @@ -41,6 +43,53 @@ func GetRcloneVersion() string { return "Unknown" } +// isNewerVersionAvailable checks if the latest version is newer than the current version +func isNewerVersionAvailable(current, latest string) bool { + // If either version is empty, we can't do a comparison + if current == "" || latest == "" { + return false + } + + // Strip 'v' prefix if present for comparison + if strings.HasPrefix(current, "v") { + current = current[1:] + } + if strings.HasPrefix(latest, "v") { + latest = latest[1:] + } + + // Split versions into components + currentParts := strings.Split(current, ".") + latestParts := strings.Split(latest, ".") + + // Compare major, minor, patch versions + for i := 0; i < len(currentParts) && i < len(latestParts); i++ { + // Parse to integers + currentNum, err1 := strconv.Atoi(currentParts[i]) + latestNum, err2 := strconv.Atoi(latestParts[i]) + + // If either can't be parsed, do string comparison + if err1 != nil || err2 != nil { + if currentParts[i] < latestParts[i] { + return true + } else if currentParts[i] > latestParts[i] { + return false + } + continue + } + + // Compare numbers + if latestNum > currentNum { + return true + } else if latestNum < currentNum { + return false + } + } + + // If all components are equal but latest has more components, it's newer + return len(latestParts) > len(currentParts) +} + templ Dashboard(ctx context.Context, data DashboardData) { @LayoutWithContext("Dashboard", ctx) {
@@ -253,6 +302,31 @@ templ Dashboard(ctx context.Context, data DashboardData) { }
+
+ Application Version + if data.CurrentVersion != "" && data.LatestVersion != "" && isNewerVersionAvailable(data.CurrentVersion, data.LatestVersion) { +
+ + + { data.CurrentVersion } + + + + { data.LatestVersion } Available + +
+ } else { + + + if data.CurrentVersion != "" { + { data.CurrentVersion } + } else { + Up to date + } + + } +