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) {