From f5d61c4b9941f3dffe6106cb1b0833fbb37d2e50 Mon Sep 17 00:00:00 2001 From: pengzhile Date: Tue, 19 Oct 2021 16:28:59 +0800 Subject: [PATCH] update the logic of auto reset option --- README.md | 2 +- build.gradle | 4 +++- .../research/intellij/ier/common/Resetter.java | 2 +- .../research/intellij/ier/helper/AppHelper.java | 10 +++++----- .../research/intellij/ier/helper/Constants.java | 1 + .../intellij/ier/helper/ResetTimeHelper.java | 2 +- .../intellij/ier/listener/PluginListener.java | 17 ++++++++++------- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index ae905df..c700e8c 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.3.3-3d9348.zip). +1. Download and install plugin from [Download Link](https://plugins.zhile.io/files/ide-eval-resetter-2.3.4-62e7c8.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 1dccaee..748630b 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'io.zhile.research.intellij' -version '2.3.3' +version '2.3.4' sourceCompatibility = 1.7 targetCompatibility = 1.7 @@ -29,6 +29,8 @@ intellij { patchPluginXml { changeNotes = """
+Release v2.3.4
+  1. update the logic of auto reset option
 Release v2.3.3
   1. add more reset records
 Release v2.3.2
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 5d11661..64effdd 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
@@ -179,7 +179,7 @@ public class Resetter {
                 evalDir.mkdirs();
             }
 
-            LICENSE_FILES.add(String.format("%s%s.evaluation.key", AppHelper.getProductCode(), AppHelper.getBuildNumber().getBaselineVersion()));
+            LICENSE_FILES.add(String.format("%s%s.evaluation.key", AppHelper.getProductName(), Constants.IDE_BASELINE_VERSION));
 
             for (IdeaPluginDescriptor descriptor : PluginManager.getPlugins()) {
                 addPluginLicense(descriptor);
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 f1ee766..d2fed5d 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
@@ -14,14 +14,14 @@ public class AppHelper {
         });
     }
 
-    public static String getProductCode() {
-        String productCode = Constants.IDE_NAME;
+    public static String getProductName() {
+        String productName = Constants.IDE_NAME;
 
-        if ("IDEA".equals(productCode)) {
-            return productCode.toLowerCase();
+        if ("IDEA".equals(productName)) {
+            return productName.toLowerCase();
         }
 
-        return productCode;
+        return productName;
     }
 
     public static BuildNumber getBuildNumber() {
diff --git a/src/main/java/io/zhile/research/intellij/ier/helper/Constants.java b/src/main/java/io/zhile/research/intellij/ier/helper/Constants.java
index 1c4119d..23f2cad 100644
--- a/src/main/java/io/zhile/research/intellij/ier/helper/Constants.java
+++ b/src/main/java/io/zhile/research/intellij/ier/helper/Constants.java
@@ -10,6 +10,7 @@ public class Constants {
     public static final String IDE_NAME = ApplicationNamesInfo.getInstance().getProductName();
     public static final String IDE_NAME_LOWER = IDE_NAME.toLowerCase();
     public static final String IDE_HASH = Integer.toHexString(FileUtil.pathHashCode(PathManager.getHomePath()));
+    public static final int IDE_BASELINE_VERSION = AppHelper.getBuildNumber().getBaselineVersion();
     public static final String PLUGIN_PREFS_PREFIX = "Ide-Eval-Reset";
     public static final String RESET_ACTION_ID = "io.zhile.research.intellij.ier.action.ResetAction";
     public static final String RESTART_ACTION_ID = "io.zhile.research.intellij.ier.action.RestartAction";
diff --git a/src/main/java/io/zhile/research/intellij/ier/helper/ResetTimeHelper.java b/src/main/java/io/zhile/research/intellij/ier/helper/ResetTimeHelper.java
index 0b2245c..cfe615f 100644
--- a/src/main/java/io/zhile/research/intellij/ier/helper/ResetTimeHelper.java
+++ b/src/main/java/io/zhile/research/intellij/ier/helper/ResetTimeHelper.java
@@ -5,7 +5,7 @@ import io.zhile.research.intellij.ier.common.Resetter;
 
 public class ResetTimeHelper {
     public static final long RESET_PERIOD = 2160000000L; // 25 days
-    private static final String RESET_KEY = Constants.PLUGIN_PREFS_PREFIX + "." + Constants.IDE_NAME_LOWER + "." + Constants.IDE_HASH;
+    private static final String RESET_KEY = Constants.PLUGIN_PREFS_PREFIX + ".reset_time." + Constants.IDE_NAME + Constants.IDE_BASELINE_VERSION;
 
     public static long getLastResetTime() {
         return Prefs.getLong(RESET_KEY, 0L);
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 c9139e5..d08e0bb 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
@@ -12,6 +12,7 @@ import io.zhile.research.intellij.ier.common.Resetter;
 import io.zhile.research.intellij.ier.helper.Constants;
 import io.zhile.research.intellij.ier.helper.NotificationHelper;
 import io.zhile.research.intellij.ier.helper.PluginHelper;
+import io.zhile.research.intellij.ier.helper.ResetTimeHelper;
 import io.zhile.research.intellij.ier.tw.MainToolWindowFactory;
 import org.jetbrains.annotations.NotNull;
 
@@ -42,23 +43,25 @@ public class PluginListener implements DynamicPluginListener, PluginStateListene
     }
 
     @Override
-    public void pluginLoaded(@NotNull IdeaPluginDescriptor pluginDescriptor) {
-        if (!PluginHelper.myself(pluginDescriptor)) {
+    public void pluginLoaded(@NotNull IdeaPluginDescriptor descriptor) {
+        if (!PluginHelper.myself(descriptor)) {
             return;
         }
 
         ActionManager.getInstance().getAction(Constants.RESET_ACTION_ID);
 
         String link = "https://zhile.io/2020/11/18/jetbrains-eval-reset-da33a93d.html";
-        String autoResetTip = "Auto reset switch state: " + (Resetter.isAutoReset() ? "on" : "off");
-        String autoLogoutTip = "Auto logout switch state: " + (Resetter.isAutoLogout() ? "on" : "off");
-        String content = String.format("Plugin installed successfully!
For more information, visit this link.

%s
%s", link, autoResetTip, autoLogoutTip); + String versionTip = "Plugin version: v" + descriptor.getVersion() + ""; + String autoResetTip = "Auto reset option state: " + (Resetter.isAutoReset() ? "on" : "off"); + String autoLogoutTip = "Auto logout option state: " + (Resetter.isAutoLogout() ? "on" : "off"); + String lastResetTime = "Last reset time: " + ResetTimeHelper.getLastResetTimeStr() + ""; + String content = String.format("Plugin installed successfully!
For more information, visit here.

%s
%s
%s
%s", link, versionTip, autoResetTip, autoLogoutTip, lastResetTime); NotificationHelper.showInfo(null, content); } @Override - public void beforePluginUnload(@NotNull IdeaPluginDescriptor pluginDescriptor, boolean isUpdate) { - if (!PluginHelper.myself(pluginDescriptor)) { + public void beforePluginUnload(@NotNull IdeaPluginDescriptor descriptor, boolean isUpdate) { + if (!PluginHelper.myself(descriptor)) { return; }