Skip to content

Commit

Permalink
SLE-1020: Only show new version hint every two weeks (#790)
Browse files Browse the repository at this point in the history
Prior to this change it was shown every day until the user updated to a new version or when the internal system property was not used.
  • Loading branch information
thahnen authored Jan 2, 2025
1 parent 8ea26be commit cb550ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -472,22 +475,38 @@ public static boolean sonarLintVersionHintHidden() {
: Boolean.parseBoolean(property);
}

public static boolean isSonarLintVersionHintDateToday() {
/**
* Check whether it was already two weeks ago that the user got a hint about the new SonarQube
* for Eclipse version. If it has not yet been two weeks, we don't want to show it again.
*/
public static boolean isNextSonarLintVersionHintDateToday() {
var date = getPreferenceString(PREF_SONARLINT_VERSION_HINT_DATE);
if (date.isBlank()) {
return false;
return true;
}

try {
var today = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime());
return date.equals(today);
var savedDate = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH).parse(date);
var todayDate = Calendar.getInstance().getTime();

return todayDate.after(savedDate);
} catch (Exception ignored) {
return false;
}
}

public static void setSonarLintVersionHintDate() {
var date = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime());
/**
* Only show hint about the new SonarQube for Eclipse version every two weeks in order to not
* annoy users with a daily notification.
*/
public static void setNextSonarLintVersionHintDate() {
var date = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH)
.format(Date.from(
LocalDate.now().plusDays(14)
.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant()));

setPreferenceString(getApplicationLevelPreferenceNode(), PREF_SONARLINT_VERSION_HINT_DATE, date);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public IStatus run(IProgressMonitor monitor) {
// Check if newer version is available and then show a notification raising awareness about it. The
// notification will only be displayed once a day in order to not annoy the user!
if (!SonarLintGlobalConfiguration.sonarLintVersionHintHidden()
&& !SonarLintGlobalConfiguration.isSonarLintVersionHintDateToday()) {
&& SonarLintGlobalConfiguration.isNextSonarLintVersionHintDateToday()) {
var newestSonarLintVersion = EclipseUpdateSite.getNewestVersion();
var currentSonarLintVersion = BundleUtils.getBundleVersion();
SonarLintLogger.get().debug("Current version (" + currentSonarLintVersion + "), newest version ("
Expand All @@ -293,13 +293,13 @@ public IStatus run(IProgressMonitor monitor) {
+ SonarLintDocumentation.GITHUB_RELEASES + ")!");
} else if (newestSonarLintVersion.isNewerThan(currentSonarLintVersion)) {
NewerVersionAvailablePopup.displayPopupIfNotAlreadyShown(newestSonarLintVersion.toString());
SonarLintGlobalConfiguration.setNextSonarLintVersionHintDate();
}
}
}

// We want to update the locally saved SonarLint version reference once everything is done!
SonarLintGlobalConfiguration.setSonarLintVersion();
SonarLintGlobalConfiguration.setSonarLintVersionHintDate();

// Display user survey pop-up (comment out if not needed, comment in again if needed and replace link)
// Display.getDefault().syncExec(() -> SurveyPopup.displaySurveyPopupIfNotAlreadyAccessed(""));
Expand Down

0 comments on commit cb550ea

Please sign in to comment.