Fix update popup showing for same version - add version comparison checks

This commit is contained in:
chasem-dev
2026-01-22 10:36:18 -05:00
parent d7a904c641
commit ce052add0d
3 changed files with 55 additions and 12 deletions

View File

@@ -335,7 +335,12 @@ class ClientUpdateManager {
async checkForUpdatesOnDemand() { async checkForUpdatesOnDemand() {
try { try {
const updateInfo = await window.electronAPI.checkForUpdates(); const updateInfo = await window.electronAPI.checkForUpdates();
if (updateInfo.updateAvailable) {
// Double-check that versions are actually different before showing popup
if (updateInfo.updateAvailable &&
updateInfo.newVersion &&
updateInfo.currentVersion &&
updateInfo.newVersion !== updateInfo.currentVersion) {
this.showUpdatePopup(updateInfo); this.showUpdatePopup(updateInfo);
} }
return updateInfo; return updateInfo;

View File

@@ -43,23 +43,32 @@ class AppUpdater {
autoUpdater.on('update-available', (info) => { autoUpdater.on('update-available', (info) => {
console.log('Update available:', info.version); console.log('Update available:', info.version);
const currentVersion = app.getVersion();
const newVersion = info.version;
// Only proceed if the new version is actually different from current
if (newVersion === currentVersion) {
console.log('Update version matches current version, ignoring update-available event');
return;
}
this.updateAvailable = true; this.updateAvailable = true;
this.updateVersion = info.version; this.updateVersion = newVersion;
this.autoUpdateAvailable = true; // Reset flag when new update is available this.autoUpdateAvailable = true; // Reset flag when new update is available
if (this.mainWindow && !this.mainWindow.isDestroyed()) { if (this.mainWindow && !this.mainWindow.isDestroyed()) {
this.mainWindow.webContents.send('update-available', { this.mainWindow.webContents.send('update-available', {
version: info.version, version: newVersion,
newVersion: info.version, newVersion: newVersion,
currentVersion: app.getVersion(), currentVersion: currentVersion,
releaseName: info.releaseName, releaseName: info.releaseName,
releaseNotes: info.releaseNotes releaseNotes: info.releaseNotes
}); });
// Also send to the old popup handler for compatibility // Also send to the old popup handler for compatibility
this.mainWindow.webContents.send('show-update-popup', { this.mainWindow.webContents.send('show-update-popup', {
currentVersion: app.getVersion(), currentVersion: currentVersion,
newVersion: info.version, newVersion: newVersion,
version: info.version version: newVersion
}); });
} }
}); });

37
main.js
View File

@@ -728,11 +728,19 @@ ipcMain.handle('check-for-updates', async () => {
try { try {
if (appUpdater) { if (appUpdater) {
const result = await appUpdater.checkForUpdates(); const result = await appUpdater.checkForUpdates();
const currentVersion = app.getVersion();
const remoteVersion = result?.updateInfo?.version;
// Only show update if remote version is actually newer than current
const updateAvailable = remoteVersion &&
remoteVersion !== currentVersion &&
isVersionNewer(remoteVersion, currentVersion);
return { return {
updateAvailable: result?.updateInfo ? true : false, updateAvailable: updateAvailable,
version: result?.updateInfo?.version, version: remoteVersion,
newVersion: result?.updateInfo?.version, newVersion: remoteVersion,
currentVersion: app.getVersion() currentVersion: currentVersion
}; };
} }
return { updateAvailable: false, error: 'AppUpdater not initialized' }; return { updateAvailable: false, error: 'AppUpdater not initialized' };
@@ -742,6 +750,27 @@ ipcMain.handle('check-for-updates', async () => {
} }
}); });
// Helper function to compare semantic versions
function isVersionNewer(version1, version2) {
// Simple semantic version comparison
// Remove any non-numeric suffixes for comparison
const v1Parts = version1.replace(/[^0-9.]/g, '').split('.').map(Number);
const v2Parts = version2.replace(/[^0-9.]/g, '').split('.').map(Number);
// Pad arrays to same length
const maxLength = Math.max(v1Parts.length, v2Parts.length);
while (v1Parts.length < maxLength) v1Parts.push(0);
while (v2Parts.length < maxLength) v2Parts.push(0);
// Compare each part
for (let i = 0; i < maxLength; i++) {
if (v1Parts[i] > v2Parts[i]) return true;
if (v1Parts[i] < v2Parts[i]) return false;
}
return false; // Versions are equal
}
ipcMain.handle('open-download-page', async () => { ipcMain.handle('open-download-page', async () => {
try { try {
// Open GitHub releases page // Open GitHub releases page