feat: display notification on plugin updates

This commit is contained in:
Carl-Robert Linnupuu 2023-12-02 00:54:57 +02:00
parent 10b090e2d2
commit 1392775940
8 changed files with 125 additions and 4 deletions

View file

@ -5,11 +5,15 @@ import static java.util.Objects.requireNonNull;
import com.intellij.ide.plugins.PluginManagerCore;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import ee.carlrobert.codegpt.telemetry.core.util.Directories;
import com.intellij.openapi.updateSettings.impl.PluginDownloader;
import com.intellij.openapi.updateSettings.impl.UpdateChecker;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Optional;
import org.jetbrains.annotations.NotNull;
public final class CodeGPTPlugin {
@ -46,4 +50,18 @@ public final class CodeGPTPlugin {
public static @NotNull String getProjectIndexStorePath(@NotNull Project project) {
return getIndexStorePath() + File.separator + project.getName();
}
public static Optional<PluginDownloader> tryFindAvailableUpdate(
@NotNull ProgressIndicator indicator) {
return findAvailableUpdates(indicator).stream()
.filter((update) -> CODEGPT_ID.equals(update.getId()))
.findFirst();
}
private static @NotNull Collection<PluginDownloader> findAvailableUpdates(
@NotNull ProgressIndicator indicator) {
return UpdateChecker.getInternalPluginUpdates(null, indicator)
.getPluginUpdates()
.getAllEnabled();
}
}