add more reset records

This commit is contained in:
pengzhile 2021-10-19 15:17:13 +08:00
parent 494a42f673
commit ab68a58532
8 changed files with 77 additions and 12 deletions

View File

@ -1,6 +1,6 @@
# Reset Your IDE Eval Information # Reset Your IDE Eval Information
1. Download and install plugin from [Download Link](https://plugins.zhile.io/files/ide-eval-resetter-2.3.2-10863c.zip). 1. Download and install plugin from [Download Link](https://plugins.zhile.io/files/ide-eval-resetter-2.3.3-3d9348.zip).
* Alternative installation method: * Alternative installation method:
* Add "Custom Plugin Repository": `https://plugins.zhile.io` manually (`Settings/Preferences` -> `Plugins`) * Add "Custom Plugin Repository": `https://plugins.zhile.io` manually (`Settings/Preferences` -> `Plugins`)
* Search and install plugin: `IDE Eval Reset` * Search and install plugin: `IDE Eval Reset`

View File

@ -4,7 +4,7 @@ plugins {
} }
group 'io.zhile.research.intellij' group 'io.zhile.research.intellij'
version '2.3.2' version '2.3.3'
sourceCompatibility = 1.7 sourceCompatibility = 1.7
targetCompatibility = 1.7 targetCompatibility = 1.7
@ -29,6 +29,8 @@ intellij {
patchPluginXml { patchPluginXml {
changeNotes = """<pre> changeNotes = """<pre>
Release v2.3.3
1. add more reset records
Release v2.3.2 Release v2.3.2
1. fix plugin version 1. fix plugin version
Release v2.3.1 Release v2.3.1

View File

@ -0,0 +1,5 @@
package io.zhile.research.intellij.ier.common;
public interface KeepCondition {
boolean needKeep();
}

View File

@ -11,14 +11,20 @@ public class PreferenceRecord implements EvalRecord {
private final String key; private final String key;
private final String value; private final String value;
private final boolean isRaw; private final boolean isRaw;
private final KeepCondition keepCondition;
public PreferenceRecord(String key) { public PreferenceRecord(String key) {
this(key, false); this(key, false, null);
} }
public PreferenceRecord(String key, boolean isRaw) { public PreferenceRecord(String key, boolean isRaw) {
this(key, isRaw, null);
}
public PreferenceRecord(String key, boolean isRaw, KeepCondition keepCondition) {
this.key = key; this.key = key;
this.isRaw = isRaw; this.isRaw = isRaw;
this.keepCondition = keepCondition;
this.value = isRaw ? Preferences.userRoot().get(key, DEFAULT_VALUE) : Prefs.get(key, DEFAULT_VALUE); this.value = isRaw ? Preferences.userRoot().get(key, DEFAULT_VALUE) : Prefs.get(key, DEFAULT_VALUE);
} }
@ -32,6 +38,10 @@ public class PreferenceRecord implements EvalRecord {
@Override @Override
public void reset() throws Exception { public void reset() throws Exception {
if (null != keepCondition && keepCondition.needKeep()) {
return;
}
if (isRaw) { if (isRaw) {
Preferences.userRoot().remove(key); Preferences.userRoot().remove(key);
} else { } else {
@ -43,6 +53,8 @@ public class PreferenceRecord implements EvalRecord {
@Override @Override
public String toString() { public String toString() {
return type + ": " + key + " = " + (null == value ? "" : value); String v = null == value ? "" : value;
return type + ": " + key + " = " + v.substring(0, Math.min(36, v.length()));
} }
} }

View File

@ -22,10 +22,9 @@ import java.util.prefs.Preferences;
public class Resetter { public class Resetter {
private static final String DEFAULT_VENDOR = "jetbrains"; private static final String DEFAULT_VENDOR = "jetbrains";
private static final String OLD_MACHINE_ID_KEY = "JetBrains.UserIdOnMachine"; private static final String OLD_MACHINE_ID_KEY = "JetBrains.UserIdOnMachine";
private static final String NEW_MACHINE_ID_KEY = DEFAULT_VENDOR + ".user_id_on_machine";
private static final String DEVICE_ID_KEY = DEFAULT_VENDOR + ".device_id";
private static final String EVAL_KEY = "evlsprt"; private static final String EVAL_KEY = "evlsprt";
private static final String AUTO_RESET_KEY = Constants.PLUGIN_PREFS_PREFIX + ".auto_reset." + Constants.IDE_NAME_LOWER + "." + Constants.IDE_HASH; private static final String AUTO_RESET_KEY = Constants.PLUGIN_PREFS_PREFIX + ".auto_reset." + Constants.IDE_NAME_LOWER;
private static final String AUTO_LOGOUT_KEY = Constants.PLUGIN_PREFS_PREFIX + ".auto_logout";
private static final Method METHOD_GET_PRODUCT_CODE = ReflectionHelper.getMethod(IdeaPluginDescriptor.class, "getProductCode"); private static final Method METHOD_GET_PRODUCT_CODE = ReflectionHelper.getMethod(IdeaPluginDescriptor.class, "getProductCode");
private static final Method METHOD_GET_RELEASE_DATE = ReflectionHelper.getMethod(IdeaPluginDescriptor.class, "getReleaseDate"); private static final Method METHOD_GET_RELEASE_DATE = ReflectionHelper.getMethod(IdeaPluginDescriptor.class, "getReleaseDate");
@ -92,10 +91,24 @@ public class Resetter {
} }
} }
KeepCondition keepCondition = new KeepCondition() {
@Override
public boolean needKeep() {
return !isAutoLogout();
}
};
PreferenceRecord[] prefsValue = new PreferenceRecord[]{ PreferenceRecord[] prefsValue = new PreferenceRecord[]{
new PreferenceRecord(OLD_MACHINE_ID_KEY, true), new PreferenceRecord(OLD_MACHINE_ID_KEY, true),
new PreferenceRecord(NEW_MACHINE_ID_KEY), new PreferenceRecord(DEFAULT_VENDOR + ".user_id_on_machine"),
new PreferenceRecord(DEVICE_ID_KEY), new PreferenceRecord(DEFAULT_VENDOR + ".device_id"),
new PreferenceRecord(DEFAULT_VENDOR + ".marketplacedownloads_device_id"),
new PreferenceRecord(DEFAULT_VENDOR + ".mlse_device_id"),
new PreferenceRecord(DEFAULT_VENDOR + ".auth-tokens.account_jetbrains_com"),
new PreferenceRecord(DEFAULT_VENDOR + ".feature_usage_event_log_salt"),
new PreferenceRecord(DEFAULT_VENDOR + ".mlse_feature_usage_event_log_salt"),
new PreferenceRecord(DEFAULT_VENDOR + ".jetprofile.idtoken"),
new PreferenceRecord(DEFAULT_VENDOR + ".jetprofile.userid", false, keepCondition),
new PreferenceRecord(DEFAULT_VENDOR + ".jetprofile.userlogin", false, keepCondition),
}; };
for (PreferenceRecord record : prefsValue) { for (PreferenceRecord record : prefsValue) {
if (record.getValue() == null) { if (record.getValue() == null) {
@ -226,6 +239,15 @@ public class Resetter {
syncPrefs(); syncPrefs();
} }
public static boolean isAutoLogout() {
return Prefs.getBoolean(AUTO_LOGOUT_KEY, false);
}
public static void setAutoLogout(boolean isAutoClear) {
Prefs.putBoolean(AUTO_LOGOUT_KEY, isAutoClear);
syncPrefs();
}
public static void syncPrefs() { public static void syncPrefs() {
try { try {
Preferences.userRoot().sync(); Preferences.userRoot().sync();

View File

@ -48,7 +48,12 @@ public class PluginListener implements DynamicPluginListener, PluginStateListene
} }
ActionManager.getInstance().getAction(Constants.RESET_ACTION_ID); ActionManager.getInstance().getAction(Constants.RESET_ACTION_ID);
NotificationHelper.showInfo(null, "Plugin installed successfully! Now enjoy it~<br>For more information, visit <a href='https://zhile.io/2020/11/18/jetbrains-eval-reset-da33a93d.html'>here</a>.");
String link = "https://zhile.io/2020/11/18/jetbrains-eval-reset-da33a93d.html";
String autoResetTip = "Auto reset switch state: " + (Resetter.isAutoReset() ? "<b>on</b>" : "<b>off<b>");
String autoLogoutTip = "Auto logout switch state: " + (Resetter.isAutoLogout() ? "<b>on</b>" : "<b>off<b>");
String content = String.format("Plugin installed successfully!<br>For more information, visit <a href='%s'>this link</a>.<br><br>%s<br>%s", link, autoResetTip, autoLogoutTip);
NotificationHelper.showInfo(null, content);
} }
@Override @Override

View File

@ -2,7 +2,7 @@
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="io.zhile.research.intellij.ier.ui.form.MainForm"> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="io.zhile.research.intellij.ier.ui.form.MainForm">
<grid id="27dc6" binding="rootPanel" layout-manager="BorderLayout" hgap="0" vgap="0"> <grid id="27dc6" binding="rootPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints> <constraints>
<xy x="20" y="20" width="500" height="400"/> <xy x="20" y="20" width="567" height="400"/>
</constraints> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
@ -79,22 +79,32 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="a1621" class="javax.swing.JCheckBox" binding="chkAutoLogout">
<constraints/>
<properties>
<text value="Logout when reset"/>
<toolTipText value="Logout account when reset(Global)"/>
</properties>
</component>
<component id="3e8db" class="javax.swing.JCheckBox" binding="chkResetAuto"> <component id="3e8db" class="javax.swing.JCheckBox" binding="chkResetAuto">
<constraints/> <constraints/>
<properties> <properties>
<text value="Auto reset before per restart"/> <text value="Auto reset before per restart"/>
<toolTipText value="Auto reset before per restart(For this IDE)"/>
</properties> </properties>
</component> </component>
<component id="382d3" class="javax.swing.JButton" binding="btnReload"> <component id="382d3" class="javax.swing.JButton" binding="btnReload">
<constraints/> <constraints/>
<properties> <properties>
<text value="Reload"/> <text value="Reload"/>
<toolTipText value="Reload eval records list"/>
</properties> </properties>
</component> </component>
<component id="7f8d9" class="javax.swing.JButton" binding="btnReset"> <component id="7f8d9" class="javax.swing.JButton" binding="btnReset">
<constraints/> <constraints/>
<properties> <properties>
<text value="Reset"/> <text value="Reset"/>
<toolTipText value="Reset eval info and restart IDE"/>
</properties> </properties>
</component> </component>
</children> </children>

View File

@ -27,6 +27,7 @@ public class MainForm {
private JLabel lblLastResetTimeLabel; private JLabel lblLastResetTimeLabel;
private JCheckBox chkResetAuto; private JCheckBox chkResetAuto;
private JLabel lblVersion; private JLabel lblVersion;
private JCheckBox chkAutoLogout;
private DialogWrapper dialogWrapper; private DialogWrapper dialogWrapper;
private DefaultListModel<String> listModel = new DefaultListModel<>(); private DefaultListModel<String> listModel = new DefaultListModel<>();
@ -78,6 +79,14 @@ public class MainForm {
lblVersion.setText("v" + PluginHelper.getPluginVersion()); lblVersion.setText("v" + PluginHelper.getPluginVersion());
chkAutoLogout.setSelected(Resetter.isAutoLogout());
addActionEventListener(chkAutoLogout, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Resetter.setAutoLogout(chkAutoLogout.isSelected());
}
}, disposable);
chkResetAuto.setSelected(Resetter.isAutoReset()); chkResetAuto.setSelected(Resetter.isAutoReset());
addActionEventListener(chkResetAuto, new ActionListener() { addActionEventListener(chkResetAuto, new ActionListener() {
@Override @Override
@ -108,7 +117,7 @@ public class MainForm {
if (null != dialogWrapper) { if (null != dialogWrapper) {
dialogWrapper.getRootPane().setDefaultButton(btnReset); dialogWrapper.getRootPane().setDefaultButton(btnReset);
rootPanel.setMinimumSize(new Dimension(600, 240)); rootPanel.setMinimumSize(new Dimension(640, 260));
} }
return rootPanel; return rootPanel;