diff --git a/README.md b/README.md index 3c047d5..7c06705 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Reset Your IDE Eval Information -1. Download and install plugin from [Download Link](https://plugins.zhile.io/files/ide-eval-resetter-2.1.11.zip). +1. Download and install plugin from [Download Link](https://plugins.zhile.io/files/ide-eval-resetter-2.1.12.zip). * Alternative installation method: * Add "Custom Plugin Repository": `https://plugins.zhile.io` manually (`Settings/Preferences` -> `Plugins`) * Search and install plugin: `IDE Eval Reset` diff --git a/build.gradle b/build.gradle index 3dd337b..6773cfd 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'io.zhile.research.intellij' -version '2.1.11' +version '2.1.12' sourceCompatibility = 1.7 targetCompatibility = 1.7 @@ -29,6 +29,8 @@ intellij { patchPluginXml { changeNotes """
+Release v2.1.12 + 1. fix disable plugins Release v2.1.11 1. fix for block list: https://plugins.jetbrains.com/files/brokenPlugins.json Release v2.1.10 diff --git a/src/main/java/io/zhile/research/intellij/ier/action/ResetAction.java b/src/main/java/io/zhile/research/intellij/ier/action/ResetAction.java index 61493a8..3c2eead 100644 --- a/src/main/java/io/zhile/research/intellij/ier/action/ResetAction.java +++ b/src/main/java/io/zhile/research/intellij/ier/action/ResetAction.java @@ -15,18 +15,22 @@ import com.intellij.openapi.wm.ex.ToolWindowManagerEx; import io.zhile.research.intellij.ier.helper.*; import io.zhile.research.intellij.ier.listener.AppActivationListener; import io.zhile.research.intellij.ier.listener.AppEventListener; +import io.zhile.research.intellij.ier.listener.BrokenPluginsListener; import io.zhile.research.intellij.ier.tw.MainToolWindowFactory; import io.zhile.research.intellij.ier.ui.dialog.MainDialog; import org.jetbrains.annotations.NotNull; public class ResetAction extends AnAction implements DumbAware { static { + BrokenPlugins.fix(); + BrokenPluginsListener.getInstance().listen(); + AppEventListener.getInstance().listen(); AppActivationListener.getInstance().listen(); try { - CustomProperties.checkAndUpdate(); + CustomProperties.fix(); } catch (Exception e) { - NotificationHelper.showError(null, "Set broken plugins failed!"); + // } CustomRepository.checkAndAdd(CustomRepository.DEFAULT_HOST); } diff --git a/src/main/java/io/zhile/research/intellij/ier/common/Resetter.java b/src/main/java/io/zhile/research/intellij/ier/common/Resetter.java index 84c3727..0bcadcd 100644 --- a/src/main/java/io/zhile/research/intellij/ier/common/Resetter.java +++ b/src/main/java/io/zhile/research/intellij/ier/common/Resetter.java @@ -105,7 +105,7 @@ public class Resetter { try { ListprefsList = new ArrayList<>(); - for (String name:Preferences.userRoot().node(DEFAULT_VENDOR).childrenNames()) { + for (String name : Preferences.userRoot().node(DEFAULT_VENDOR).childrenNames()) { if (!name.toLowerCase().startsWith(Constants.IDE_NAME_LOWER)) { continue; } diff --git a/src/main/java/io/zhile/research/intellij/ier/helper/AppHelper.java b/src/main/java/io/zhile/research/intellij/ier/helper/AppHelper.java index b96568f..d38bf8b 100644 --- a/src/main/java/io/zhile/research/intellij/ier/helper/AppHelper.java +++ b/src/main/java/io/zhile/research/intellij/ier/helper/AppHelper.java @@ -4,9 +4,11 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.Disposer; import io.zhile.research.intellij.ier.listener.AppActivationListener; import io.zhile.research.intellij.ier.listener.AppEventListener; +import io.zhile.research.intellij.ier.listener.BrokenPluginsListener; public class AppHelper { public static void restart() { + Disposer.dispose(BrokenPluginsListener.getInstance()); Disposer.dispose(AppActivationListener.getInstance()); Disposer.dispose(AppEventListener.getInstance()); diff --git a/src/main/java/io/zhile/research/intellij/ier/helper/BrokenPlugins.java b/src/main/java/io/zhile/research/intellij/ier/helper/BrokenPlugins.java new file mode 100644 index 0000000..bc3aee9 --- /dev/null +++ b/src/main/java/io/zhile/research/intellij/ier/helper/BrokenPlugins.java @@ -0,0 +1,30 @@ +package io.zhile.research.intellij.ier.helper; + +import com.intellij.openapi.application.PathManager; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + +public class BrokenPlugins { + public static void fix() { + String content = "[]"; + String fileName = "brokenPlugins.json"; + Path brokenPluginsPath = Paths.get(PathManager.getPluginsPath(), fileName); + File brokenPluginsFile = brokenPluginsPath.toFile(); + if (!brokenPluginsFile.exists() || content.length() == brokenPluginsFile.length()) { + return; + } + + try { + Path bak = brokenPluginsPath.getParent().resolve(fileName + ".tmp"); + Files.write(bak, content.getBytes()); + Files.move(bak, brokenPluginsPath, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); + } catch (IOException e) { + NotificationHelper.showError(null, "Set broken plugins failed!"); + } + } +} diff --git a/src/main/java/io/zhile/research/intellij/ier/helper/CustomProperties.java b/src/main/java/io/zhile/research/intellij/ier/helper/CustomProperties.java index 665311f..5413e3c 100644 --- a/src/main/java/io/zhile/research/intellij/ier/helper/CustomProperties.java +++ b/src/main/java/io/zhile/research/intellij/ier/helper/CustomProperties.java @@ -13,9 +13,9 @@ import java.util.List; import java.util.Properties; public class CustomProperties { - public static void checkAndUpdate() throws Exception { - String key = "idea.ignore.disabled.plugins", value = "true"; - System.setProperty(key, value); + public static void fix() throws Exception { + String key = "idea.ignore.disabled.plugins"; + System.clearProperty(key); List paths = new ArrayList<>(); paths.add(Paths.get(SystemProperties.getUserHome(), PathManager.PROPERTIES_FILE_NAME)); @@ -28,7 +28,7 @@ public class CustomProperties { for (Path path : paths) { File file = path.toFile(); if (!file.exists()) { - new FileOutputStream(file).close(); + continue; } Properties props = new Properties(); @@ -36,7 +36,12 @@ public class CustomProperties { props.load(fis); } - props.setProperty(key, value); + props.remove(key); + + if (props.isEmpty()) { + file.delete(); + continue; + } try (FileOutputStream fos = new FileOutputStream(file)) { props.store(fos, null); diff --git a/src/main/java/io/zhile/research/intellij/ier/listener/AppEventListener.java b/src/main/java/io/zhile/research/intellij/ier/listener/AppEventListener.java index b2a68d1..740c513 100644 --- a/src/main/java/io/zhile/research/intellij/ier/listener/AppEventListener.java +++ b/src/main/java/io/zhile/research/intellij/ier/listener/AppEventListener.java @@ -7,6 +7,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Ref; import com.intellij.util.messages.MessageBusConnection; import io.zhile.research.intellij.ier.common.Resetter; +import io.zhile.research.intellij.ier.helper.BrokenPlugins; import io.zhile.research.intellij.ier.helper.ResetTimeHelper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -62,6 +63,8 @@ public class AppEventListener implements AppLifecycleListener, Disposable { } public void appClosing() { + BrokenPlugins.fix(); + if (!Resetter.isAutoReset()) { return; } diff --git a/src/main/java/io/zhile/research/intellij/ier/listener/BrokenPluginsListener.java b/src/main/java/io/zhile/research/intellij/ier/listener/BrokenPluginsListener.java new file mode 100644 index 0000000..39be008 --- /dev/null +++ b/src/main/java/io/zhile/research/intellij/ier/listener/BrokenPluginsListener.java @@ -0,0 +1,58 @@ +package io.zhile.research.intellij.ier.listener; + +import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.ApplicationActivationListener; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.wm.IdeFrame; +import com.intellij.util.messages.MessageBusConnection; +import io.zhile.research.intellij.ier.helper.BrokenPlugins; +import org.jetbrains.annotations.NotNull; + +public class BrokenPluginsListener implements ApplicationActivationListener, Disposable { + private static BrokenPluginsListener instance = new BrokenPluginsListener(); + private static MessageBusConnection connection; + + protected BrokenPluginsListener() { + + } + + public static BrokenPluginsListener getInstance() { + return instance; + } + + public synchronized void listen() { + if (connection != null) { + return; + } + + connection = ApplicationManager.getApplication().getMessageBus().connect(); + connection.subscribe(ApplicationActivationListener.TOPIC, this); + } + + public synchronized void stop() { + if (connection == null) { + return; + } + + connection.disconnect(); + connection = null; + } + + public void applicationActivated(@NotNull IdeFrame ideFrame) { + BrokenPlugins.fix(); + } + + public void applicationDeactivated(@NotNull IdeFrame ideFrame) { + applicationActivated(ideFrame); + } + + public void delayedApplicationDeactivated(@NotNull IdeFrame ideFrame) { + + } + + @Override + public void dispose() { + stop(); + instance = null; + } +} diff --git a/src/main/java/io/zhile/research/intellij/ier/listener/PluginListener.java b/src/main/java/io/zhile/research/intellij/ier/listener/PluginListener.java index 17f6755..b74eb50 100644 --- a/src/main/java/io/zhile/research/intellij/ier/listener/PluginListener.java +++ b/src/main/java/io/zhile/research/intellij/ier/listener/PluginListener.java @@ -34,6 +34,7 @@ public class PluginListener implements DynamicPluginListener { ((DefaultActionGroup) optionsGroup).remove(ActionManager.getInstance().getAction(Constants.RESET_ACTION_ID)); } + Disposer.dispose(BrokenPluginsListener.getInstance()); Disposer.dispose(AppActivationListener.getInstance()); Disposer.dispose(AppEventListener.getInstance()); MainToolWindowFactory.unregisterAll();