Skip to content

Commit

Permalink
fix: potential plugin crash when the project is closed. closes #26 (#27)
Browse files Browse the repository at this point in the history
* fix: potential plugin crash when the project is closed

* fix: formatting

* fix: plugin compatibility
  • Loading branch information
drinchev authored Sep 27, 2023
1 parent 0bf19f9 commit 7d3d430
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 22 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Project Label Changelog

## [Unreleased]
- Fix a potential issue of plugin crash, when switching projects

## [1.3.0] - 2023-08-08
- Option to choose colors from good-looking presets (or manually pick colors like before)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pluginGroup=com.drinchev.projectlabel
pluginName=Project Label
pluginRepositoryUrl=https://github.com/drinchev/project-label
# SemVer format -> https://semver.org
pluginVersion=1.3.0
pluginVersion=1.3.1
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild=223
pluginUntilBuild=
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/drinchev/projectlabel/ProjectLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.jetbrains.annotations.NotNull;

@Service(Level.PROJECT)
public class ProjectLabel {
public final class ProjectLabel {

private final Project project;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

import com.drinchev.projectlabel.resources.ui.ProjectLabelBackgroundImage;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.ProjectPostStartupActivity;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import com.intellij.openapi.startup.StartupActivity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ProjectLabelStartupActivity implements ProjectPostStartupActivity {

@Nullable
public class ProjectLabelStartupActivity implements StartupActivity {
@Override
public Object execute(@NotNull Project project, @NotNull Continuation<? super Unit> continuation) {
public void runActivity(@NotNull Project project) {
try {
project.getService(ProjectLabelBackgroundImage.class).showImage();
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.jetbrains.annotations.NotNull;

@Service(Level.PROJECT)
public class ProjectLabelBackgroundImage {
public final class ProjectLabelBackgroundImage {

public static final int MIN_HEIGHT = 30;

Expand Down Expand Up @@ -92,7 +92,10 @@ private boolean shouldShowBackgroundImage() {
}

private void setImageToIDE() {
PropertiesComponent prop = projectLevelPropertiesComponent();
if (project.isDisposed()) {
return;
}
PropertiesComponent prop = project.getService(PropertiesComponent.class);
String opacity = String.valueOf(preferences.backgroundImageOpacity());
String imageProp = String.format(
"%s,%s,plain,%s",
Expand All @@ -109,11 +112,6 @@ private void setImageToIDE() {
}
}

private PropertiesComponent projectLevelPropertiesComponent() {
PropertiesComponent prop = project.getService(PropertiesComponent.class);
return prop;
}

public void updateImage() {
LOG.info("Updating project label background image.");
bufferedImage = null;
Expand All @@ -122,7 +120,10 @@ public void updateImage() {
}

public void hideImage() {
PropertiesComponent prop = projectLevelPropertiesComponent();
if (project.isDisposed()) {
return;
}
PropertiesComponent prop = project.getService(PropertiesComponent.class);
String editorProp = prop.getValue(IdeBackgroundUtil.EDITOR_PROP, "");
String frameProp = prop.getValue(IdeBackgroundUtil.FRAME_PROP, "");
if (!isProjectLabelImage(editorProp, frameProp)) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceImplementation="com.drinchev.projectlabel.preferences.ApplicationPreferences"/>
<projectService serviceImplementation="com.drinchev.projectlabel.preferences.ProjectPreferences"/>
<projectService serviceImplementation="com.drinchev.projectlabel.ProjectLabel" />
<projectService serviceImplementation="com.drinchev.projectlabel.resources.ui.ProjectLabelBackgroundImage" />
<projectConfigurable id="ProjectLabel" displayName="Project Label"
instance="com.drinchev.projectlabel.ProjectLabelConfigurable"/>
<statusBarWidgetFactory implementation="com.drinchev.projectlabel.ProjectLabelWidgetFactory" order="last"/>
Expand Down

0 comments on commit 7d3d430

Please sign in to comment.