首页>代码>Idea插件,延长试用时间>/ide-eval-resetter-master/src/main/java/io/zhile/research/intellij/MainComponent.java
package io.zhile.research.intellij;

import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
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;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.prefs.Preferences;

public class MainComponent implements ApplicationComponent {
    private static final long RESET_PERIOD = 2160000000L; // 25 days

    public void initComponent() {
        Preferences prefs = Preferences.userRoot().node(Constants.PLUGIN_NAME);
        long lastResetTime = prefs.getLong(Constants.PRODUCT_NAME + Constants.PRODUCT_HASH, 0L);

        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                if (lastResetTime > 0) {
                    Date date = new Date(lastResetTime);
                    DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    NotificationHelper.showInfo(null, "The last reset time: " + format.format(date));
                }

                new ResetTimerTask(lastResetTime).run();
            }
        }, 3000);
    }

    protected static class ResetTimerTask extends TimerTask {
        private final long lastResetTime;

        public ResetTimerTask(long lastResetTime) {
            this.lastResetTime = lastResetTime;
        }

        @Override
        public void run() {
            if (System.currentTimeMillis() - lastResetTime > RESET_PERIOD) {
                String message = "It has been a long time since the last reset!\nWould you like to reset it again?";
                Notification notification = NotificationHelper.NOTIFICATION_GROUP.createNotification(Constants.PLUGIN_NAME, null, message, NotificationType.INFORMATION);
                notification.addAction(new ResetAction());
                notification.notify(null);
            }

            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
    }
}
最近下载更多
最近浏览更多
FlyHeLanMan  LV11 昨天
JOEH60  LV10 昨天
林kkkkkk  LV6 10月31日
Peny_ZH  LV5 10月30日
best2018  LV46 10月30日
locklock  LV2 10月30日
MrReady  LV14 10月28日
dfaghrs  LV19 10月28日
BestClever  LV32 10月28日
Rommel  LV27 10月27日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友