parent
dee34a27f9
commit
f145eac269
@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue