parent
1ad670a257
commit
fd5e2d27b1
|
@ -4,7 +4,7 @@ plugins {
|
|||
}
|
||||
|
||||
group 'io.zhile.research.intellij'
|
||||
version '1.0.1'
|
||||
version '1.0.2'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.intellij.openapi.components.ApplicationComponent;
|
|||
import io.zhile.research.intellij.action.ResetAction;
|
||||
import io.zhile.research.intellij.helper.Constants;
|
||||
import io.zhile.research.intellij.helper.NotificationHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -19,8 +20,7 @@ public class MainComponent implements ApplicationComponent {
|
|||
|
||||
public void initComponent() {
|
||||
Preferences prefs = Preferences.userRoot().node(Constants.PLUGIN_NAME);
|
||||
long lastResetTime = prefs.getLong(Constants.PRODUCT_NAME + Constants.RESET_TIME_KEY, 0L);
|
||||
|
||||
long lastResetTime = prefs.getLong(Constants.PRODUCT_NAME + Constants.PRODUCT_HASH, 0L);
|
||||
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
|
@ -55,4 +55,15 @@ public class MainComponent implements ApplicationComponent {
|
|||
new Timer().schedule(new ResetTimerTask(lastResetTime), 3600000); // 60 min
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeComponent() {
|
||||
// for compatibility
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull
|
||||
String getComponentName() {
|
||||
return getClass().getName(); // for compatibility
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.intellij.openapi.application.PathManager;
|
|||
import com.intellij.openapi.application.ex.ApplicationInfoEx;
|
||||
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.MessageDialogBuilder;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
|
@ -18,11 +17,10 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.prefs.BackingStoreException;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
public class ResetAction extends AnAction {
|
||||
private static final String DEVICE_ID_KEY = "device_id";
|
||||
private static final String NEW_MACHINE_ID_KEY = "user_id_on_machine";
|
||||
private static final String OLD_MACHINE_ID_KEY = "JetBrains.UserIdOnMachine";
|
||||
private static final String DEFAULT_COMPANY_NAME = "jetbrains";
|
||||
|
||||
|
@ -45,13 +43,16 @@ public class ResetAction extends AnAction {
|
|||
|
||||
String companyName = appInfo.getShortCompanyName();
|
||||
String node = StringUtil.isEmptyOrSpaces(companyName) ? DEFAULT_COMPANY_NAME : companyName.toLowerCase();
|
||||
Preferences prefs = Preferences.userRoot().node(node);
|
||||
|
||||
try {
|
||||
Preferences.userRoot().remove(OLD_MACHINE_ID_KEY);
|
||||
prefs.remove(NEW_MACHINE_ID_KEY);
|
||||
prefs.remove(DEVICE_ID_KEY);
|
||||
Preferences.userRoot().node(node).removeNode();
|
||||
} catch (BackingStoreException e) {
|
||||
NotificationHelper.showError(project, e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
Preferences.userRoot().node(Constants.PLUGIN_NAME).put(Constants.PRODUCT_NAME + Constants.RESET_TIME_KEY, Long.toString(System.currentTimeMillis()));
|
||||
Preferences.userRoot().node(Constants.PLUGIN_NAME).put(Constants.PRODUCT_NAME + Constants.PRODUCT_HASH, Long.toString(System.currentTimeMillis()));
|
||||
|
||||
if (appInfo.isVendorJetBrains() && SystemInfo.isWindows) {
|
||||
String[] names = new String[]{"PermanentUserId", "PermanentDeviceId"};
|
||||
|
@ -61,13 +62,12 @@ public class ResetAction extends AnAction {
|
|||
}
|
||||
|
||||
NotificationHelper.showError(project, "Remove " + name + " file failed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MessageDialogBuilder.YesNo dialog = MessageDialogBuilder.yesNo(Constants.PLUGIN_NAME, "Reset successfully!\nWould you like to restart your IDE?");
|
||||
if (dialog.isYes()) {
|
||||
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().exit(true, false, true));
|
||||
}
|
||||
NotificationHelper.showInfo(project, "Reset successfully!\nPlease restart your IDE and enjoy it!");
|
||||
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().restart());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
package io.zhile.research.intellij.helper;
|
||||
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor;
|
||||
import com.intellij.ide.plugins.PluginManager;
|
||||
import com.intellij.ide.plugins.cl.PluginClassLoader;
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.extensions.PluginId;
|
||||
|
||||
public class Constants {
|
||||
public static final PluginClassLoader CLASS_LOADER = (PluginClassLoader) Constants.class.getClassLoader();
|
||||
public static final IdeaPluginDescriptor PLUGIN_DESCRIPTOR = CLASS_LOADER.getPluginDescriptor();
|
||||
public static final PluginId PLUGIN_ID = CLASS_LOADER.getPluginId();
|
||||
public static final String PLUGIN_NAME = PLUGIN_DESCRIPTOR == null ? "ide-eval-resetter" : PLUGIN_DESCRIPTOR.getName();
|
||||
public static final String PRODUCT_NAME = ApplicationNamesInfo.getInstance().getProductName();
|
||||
|
||||
public static final String RESET_TIME_KEY = "trail_reset_time";
|
||||
public static final String PLUGIN_NAME = PluginManager.getPlugin(PLUGIN_ID).getName();
|
||||
public static final String PRODUCT_NAME = ApplicationNamesInfo.getInstance().getFullProductName();
|
||||
public static final String PRODUCT_HASH = Integer.toString(PathManager.getConfigPath().hashCode());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.zhile.research.intellij.helper;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationDisplayType;
|
||||
import com.intellij.notification.NotificationGroup;
|
||||
|
@ -8,7 +9,7 @@ import com.intellij.openapi.project.Project;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class NotificationHelper {
|
||||
public static final NotificationGroup NOTIFICATION_GROUP = new NotificationGroup(Constants.PLUGIN_ID.getIdString(), NotificationDisplayType.BALLOON, true);
|
||||
public static final NotificationGroup NOTIFICATION_GROUP = new NotificationGroup(Constants.PLUGIN_ID.getIdString(), NotificationDisplayType.BALLOON, true, null, AllIcons.General.Reset);
|
||||
|
||||
public static Notification show(@Nullable Project project, String title, String subtitle, String content, NotificationType type) {
|
||||
if (title == null) {
|
||||
|
|
Loading…
Reference in New Issue