add option "Auto reset before per restart"

Signed-off-by: pengzhile <pengzhile@gmail.com>
pull/8/head
pengzhile 2020-11-11 20:19:39 +08:00
parent 18e124fa29
commit 32ac154f65
5 changed files with 63 additions and 12 deletions

View File

@ -4,7 +4,7 @@ plugins {
}
group 'io.zhile.research.intellij'
version '2.0.4'
version '2.1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
@ -29,6 +29,8 @@ intellij {
patchPluginXml {
changeNotes """<pre>
Release v2.1.0
1. add option "Auto reset before per restart"
Release v2.0.4
1. fix plugins reset
2. reset more gracefully

View File

@ -1,9 +1,11 @@
package io.zhile.research.intellij.ier.component;
import com.intellij.ide.AppLifecycleListener;
import com.intellij.ide.Prefs;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import io.zhile.research.intellij.ier.action.RestartAction;
@ -11,6 +13,7 @@ import io.zhile.research.intellij.ier.common.Resetter;
import io.zhile.research.intellij.ier.helper.Constants;
import io.zhile.research.intellij.ier.helper.DateTime;
import io.zhile.research.intellij.ier.helper.NotificationHelper;
import io.zhile.research.intellij.ier.listener.AppEventListener;
import java.util.Arrays;
import java.util.Timer;
@ -36,6 +39,8 @@ public class ResetTimer {
}
public void start(final AnAction resetAction) {
ApplicationManager.getApplication().getMessageBus().connect().subscribe(AppLifecycleListener.TOPIC, new AppEventListener());
new Timer().schedule(new TimerTask() {
@Override
public void run() {
@ -60,17 +65,8 @@ public class ResetTimer {
break;
}
AnAction action = resetAction;
AnAction action = Resetter.isAutoReset() ? new RestartAction() : resetAction;
String message = "It has been a long time since the last reset!\nWould you like to reset it again?";
if (Resetter.isAutoReset()) {
Resetter.reset(Resetter.getEvalRecords());
ResetTimer.resetLastResetTime();
action = new RestartAction();
message = "Automatic reset successfully!\nWould like to restart your IDE?";
}
Notification notification = NotificationHelper.NOTIFICATION_GROUP.createNotification(Constants.PLUGIN_NAME, null, message, NotificationType.INFORMATION);
notification.addAction(action);

View File

@ -0,0 +1,51 @@
package io.zhile.research.intellij.ier.listener;
import com.intellij.ide.AppLifecycleListener;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import io.zhile.research.intellij.ier.common.Resetter;
import io.zhile.research.intellij.ier.component.ResetTimer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class AppEventListener implements AppLifecycleListener {
private static boolean enabled = true;
public synchronized static void disable() {
enabled = false;
}
public void appFrameCreated(String[] commandLineArgs, @NotNull Ref<Boolean> willOpenProject) {
}
@Override
public void appStarting(@Nullable Project projectFromCommandLine) {
}
@Override
public void projectFrameClosed() {
}
@Override
public void projectOpenFailed() {
}
@Override
public void welcomeScreenDisplayed() {
}
@Override
public void appClosing() {
if (!enabled || !Resetter.isAutoReset()) {
return;
}
Resetter.reset(Resetter.getEvalRecords());
ResetTimer.resetLastResetTime();
}
}

View File

@ -34,7 +34,7 @@
<component id="3e8db" class="javax.swing.JCheckBox" binding="chkResetAuto">
<constraints/>
<properties>
<text value="Reset Automatically (per 25 days)"/>
<text value="Auto reset before per restart"/>
</properties>
</component>
<component id="382d3" class="javax.swing.JButton" binding="btnReload">

View File

@ -8,6 +8,7 @@ import io.zhile.research.intellij.ier.common.EvalRecord;
import io.zhile.research.intellij.ier.common.Resetter;
import io.zhile.research.intellij.ier.component.ResetTimer;
import io.zhile.research.intellij.ier.helper.Constants;
import io.zhile.research.intellij.ier.listener.AppEventListener;
import javax.swing.*;
import java.awt.*;
@ -96,6 +97,7 @@ public class MainForm {
dialogWrapper.close(0);
}
AppEventListener.disable();
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().restart());
}