feat: enhance configuration management, add update checks, and improve UI components
This commit is contained in:
27
utils/version.ts
Normal file
27
utils/version.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Compare two version strings.
|
||||
* Returns true if 'latest' is greater than 'current' (an update is available).
|
||||
*/
|
||||
export const isUpdateAvailable = (currentVersion: string | undefined, latestVersion: string) => {
|
||||
if (!currentVersion || !latestVersion) return false;
|
||||
|
||||
// Split strings into an array of numbers: "1.2.10" -> [1, 2, 10]
|
||||
const currentParts = currentVersion.split('.').map(Number);
|
||||
const latestParts = latestVersion.split('.').map(Number);
|
||||
const maxLength = Math.max(currentParts.length, latestParts.length);
|
||||
|
||||
for (let i = 0; i < maxLength; i++) {
|
||||
// If a part is missing, we consider it as 0 (e.g. "1.0" -> [1, 0, 0])
|
||||
const current = currentParts[i] || 0;
|
||||
const latest = latestParts[i] || 0;
|
||||
|
||||
if (current < latest) {
|
||||
return true; // It needs an update
|
||||
}
|
||||
if (current > latest) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
Reference in New Issue
Block a user