diff --git a/build.gradle b/build.gradle index 4f30ee4..8d6310d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id 'java-library' id 'org.jetbrains.intellij' version '1.14.2' + id("org.jetbrains.kotlin.jvm") version "1.9.23" id 'org.jetbrains.changelog' version "1.3.1" id "de.undercouch.download" version "4.0.2" } diff --git a/gradle.properties b/gradle.properties index 8bd85fd..0a3d74a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ pluginUntilBuild = pluginDescription = doc/description.html platformType = IU -platformVersion = 2022.1 +platformVersion = 2022.2 # ,-Dide.browser.jcef.log.level=verbose,-Duser.language=en-US runIdeJvmArgs = -Dfile.encoding=utf-8 \ No newline at end of file diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/AbstractAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/AbstractAction.java index d3402b7..c7f60e9 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/AbstractAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/AbstractAction.java @@ -1,5 +1,6 @@ package com.shuzijun.leetcode.plugin.actions; +import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.options.ShowSettingsUtil; @@ -47,5 +48,10 @@ public void run(@NotNull ProgressIndicator progressIndicator) { } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; + } + public abstract void actionPerformed(AnActionEvent anActionEvent, Config config); } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/EditorMenuActionGroup.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/EditorMenuActionGroup.java index 41f584b..9ac3f1d 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/EditorMenuActionGroup.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/EditorMenuActionGroup.java @@ -1,11 +1,13 @@ package com.shuzijun.leetcode.plugin.actions.editor; +import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.vfs.VirtualFile; import com.shuzijun.leetcode.plugin.model.LeetcodeEditor; import com.shuzijun.leetcode.plugin.setting.ProjectConfig; +import org.jetbrains.annotations.NotNull; /** * @author shuzijun @@ -24,4 +26,9 @@ public void update(AnActionEvent e) { } e.getPresentation().setEnabledAndVisible(menuAllowed); } + + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; + } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindAction.java index 8143580..8f7f6a1 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindAction.java @@ -1,11 +1,13 @@ package com.shuzijun.leetcode.plugin.actions.toolbar; +import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.ToggleAction; import com.intellij.openapi.project.DumbAware; import com.shuzijun.leetcode.plugin.manager.NavigatorAction; import com.shuzijun.leetcode.plugin.utils.DataKeys; import com.shuzijun.leetcode.plugin.window.WindowFactory; +import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -46,4 +48,8 @@ public void setSelected(AnActionEvent anActionEvent, boolean b) { panel.setVisible(b); } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; + } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindActionGroup.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindActionGroup.java index 34c04e5..5e74b13 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindActionGroup.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindActionGroup.java @@ -2,6 +2,7 @@ import com.google.common.collect.Lists; import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.project.DumbAware; @@ -13,6 +14,7 @@ import com.shuzijun.leetcode.plugin.utils.DataKeys; import com.shuzijun.leetcode.plugin.window.WindowFactory; import icons.LeetCodeEditorIcons; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -97,4 +99,9 @@ private String getFilterKey(String id) { private String getKey(String id) { return id.replace(PluginConstant.LEETCODE_FIND_PREFIX, "").replace(PluginConstant.LEETCODE_ALL_FIND_PREFIX, "").replace(PluginConstant.LEETCODE_CODETOP_FIND_PREFIX, ""); } + + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; + } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindTagAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindTagAction.java index 7050c31..38fbad2 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindTagAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindTagAction.java @@ -1,5 +1,6 @@ package com.shuzijun.leetcode.plugin.actions.toolbar; +import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.ToggleAction; import com.intellij.openapi.progress.ProgressIndicator; @@ -61,5 +62,10 @@ public void run(@NotNull ProgressIndicator progressIndicator) { }); } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; + } + } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteAction.java index 531b855..210ec92 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteAction.java @@ -1,5 +1,6 @@ package com.shuzijun.leetcode.plugin.actions.tree; +import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.ToggleAction; import com.intellij.openapi.progress.ProgressIndicator; @@ -65,4 +66,9 @@ public void run(@NotNull ProgressIndicator progressIndicator) { }); } + + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; + } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteActionGroup.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteActionGroup.java index 8c610c3..0c551c4 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteActionGroup.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteActionGroup.java @@ -2,6 +2,7 @@ import com.google.common.collect.Lists; import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.project.DumbAware; @@ -10,6 +11,7 @@ import com.shuzijun.leetcode.plugin.model.Tag; import com.shuzijun.leetcode.plugin.utils.DataKeys; import com.shuzijun.leetcode.plugin.window.WindowFactory; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -39,4 +41,9 @@ public AnAction[] getChildren(AnActionEvent anActionEvent) { } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; + } + } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/listener/RegisterPluginInstallerStateListener.java b/src/main/java/com/shuzijun/leetcode/plugin/listener/RegisterPluginInstallerStateListener.java deleted file mode 100644 index 2836c4b..0000000 --- a/src/main/java/com/shuzijun/leetcode/plugin/listener/RegisterPluginInstallerStateListener.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.shuzijun.leetcode.plugin.listener; - -import com.intellij.ide.plugins.PluginManagerCore; -import com.intellij.ide.util.PropertiesComponent; -import com.intellij.openapi.extensions.PluginId; -import com.intellij.openapi.fileEditor.impl.HTMLEditorProvider; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.startup.StartupActivity; -import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.PluginConstant; -import com.shuzijun.leetcode.plugin.setting.PersistentConfig; -import org.jetbrains.annotations.NotNull; - -/** - * @author shuzijun - */ -public class RegisterPluginInstallerStateListener implements StartupActivity { - - private final static String ShowNewHTMLEditorKey = PluginConstant.PLUGIN_ID + "ShowNewHTMLEditor"; - - private final static String CHANGELOGURL = "https://github.com/shuzijun/leetcode-editor/blob/master/CHANGELOG.md"; - - @Override - public void runActivity(@NotNull Project project) { - String newVersion = PluginManagerCore.getPlugin(PluginId.getId(PluginConstant.PLUGIN_ID)).getVersion(); - Config config = PersistentConfig.getInstance().getInitConfig(); - String oldVersion; - if (config == null) { - oldVersion = PropertiesComponent.getInstance().getValue(ShowNewHTMLEditorKey); - PropertiesComponent.getInstance().setValue(ShowNewHTMLEditorKey, newVersion); - } else { - oldVersion = config.getPluginVersion(); - config.setPluginVersion(newVersion); - } - - if (!newVersion.equals(oldVersion)) { - HTMLEditorProvider.openEditor(project, - "What's New in " + PluginConstant.PLUGIN_ID, - CHANGELOGURL, - "'
" + - "
Failed to load!
" + - "'
Open in browser
" + - "
" - ); - } - - - /* PluginInstaller.addStateListener(new PluginStateListener() { - @Override - public void install(@NotNull IdeaPluginDescriptor ideaPluginDescriptor) { - } - - @Override - public void uninstall(@NotNull IdeaPluginDescriptor ideaPluginDescriptor) { - System.out.println("uninstall"); - } - });*/ - } -} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/setting/PersistentConfig.java b/src/main/java/com/shuzijun/leetcode/plugin/setting/PersistentConfig.java index 97a4e7a..204edb6 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/setting/PersistentConfig.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/setting/PersistentConfig.java @@ -94,7 +94,7 @@ public void savePassword(String password, String username) { if (username == null || password == null) { return; } - PasswordSafe.getInstance().set(new CredentialAttributes(PluginConstant.PLUGIN_ID, username, this.getClass()), new Credentials(username, password == null ? "" : password)); + PasswordSafe.getInstance().set(new CredentialAttributes(PluginConstant.PLUGIN_ID, username, this.getClass()), new Credentials(username, password)); } public String getPassword(String username) { diff --git a/src/main/java/com/shuzijun/leetcode/plugin/utils/HttpRequestUtils.java b/src/main/java/com/shuzijun/leetcode/plugin/utils/HttpRequestUtils.java index fdb5f09..b5ab6b2 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/utils/HttpRequestUtils.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/utils/HttpRequestUtils.java @@ -2,24 +2,30 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import com.intellij.openapi.application.Application; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.util.net.HttpConfigurable; -import com.intellij.util.net.IdeaWideAuthenticator; import com.intellij.util.net.IdeaWideProxySelector; +import com.intellij.util.proxy.NonStaticAuthenticator; import com.shuzijun.lc.LcClient; import com.shuzijun.lc.errors.LcException; import com.shuzijun.lc.http.DefaultExecutoHttp; import com.shuzijun.lc.http.HttpClient; import com.shuzijun.leetcode.plugin.model.HttpRequest; +import com.shuzijun.leetcode.plugin.model.PluginConstant; +import okhttp3.Challenge; import okhttp3.Credentials; import okhttp3.OkHttpClient; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import java.net.CookieHandler; import java.net.CookieManager; import java.net.HttpCookie; import java.net.PasswordAuthentication; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Objects; @@ -54,7 +60,7 @@ private static HttpResponse buildResp(com.shuzijun.lc.http.HttpResponse response } private static Map getHeader(String url) { - if (url.contains(HttpClient.SiteEnum.EN.defaultEndpoint)){ + if (url.contains(HttpClient.SiteEnum.EN.defaultEndpoint)) { return enLcClient.getClient().getHeader(); } else { return cnLcClient.getClient().getHeader(); @@ -123,7 +129,7 @@ public static HttpResponse executePut(HttpRequest httpRequest) { } public static String getToken() { - Map headerMap = getHeader(URLUtils.getLeetcodeHost()); + Map headerMap = getHeader(URLUtils.getLeetcodeHost()); return headerMap.get("x-csrftoken"); } @@ -137,7 +143,7 @@ public static boolean isLogin(Project project) { public static void setCookie(List cookieList) { enLcClient.getClient().cookieStore().clearCookie(URLUtils.getLeetcodeHost()); - enLcClient.getClient().cookieStore().addCookie(URLUtils.getLeetcodeHost(),cookieList); + enLcClient.getClient().cookieStore().addCookie(URLUtils.getLeetcodeHost(), cookieList); } public static void resetHttpclient() { @@ -181,33 +187,111 @@ private static class MyExecutorHttp extends DefaultExecutoHttp { @Override public OkHttpClient getRequestClient() { final HttpConfigurable httpConfigurable = HttpConfigurable.getInstance(); - if (!httpConfigurable.USE_HTTP_PROXY && !httpConfigurable.USE_PROXY_PAC) { + if (!httpConfigurable.USE_HTTP_PROXY && !httpConfigurable.USE_PROXY_PAC) { return super.getRequestClient(); } final IdeaWideProxySelector ideaWideProxySelector = new IdeaWideProxySelector(httpConfigurable); OkHttpClient.Builder builder = super.getRequestClient().newBuilder().proxySelector(ideaWideProxySelector); if (httpConfigurable.PROXY_AUTHENTICATION) { - final IdeaWideAuthenticator ideaWideAuthenticator = new IdeaWideAuthenticator(httpConfigurable); + final MyAuthenticator ideaWideAuthenticator = new MyAuthenticator(httpConfigurable); final okhttp3.Authenticator proxyAuthenticator = getProxyAuthenticator(ideaWideAuthenticator); builder.proxyAuthenticator(proxyAuthenticator); } return builder.build(); } - private okhttp3.Authenticator getProxyAuthenticator(IdeaWideAuthenticator ideaWideAuthenticator) { + private okhttp3.Authenticator getProxyAuthenticator(MyAuthenticator ideaWideAuthenticator) { okhttp3.Authenticator proxyAuthenticator = null; if (Objects.nonNull(ideaWideAuthenticator)) { proxyAuthenticator = (route, response) -> { + ideaWideAuthenticator.SetResponse(response); final PasswordAuthentication authentication = ideaWideAuthenticator.getPasswordAuthentication(); - final String credential = Credentials.basic(authentication.getUserName(), Arrays.toString(authentication.getPassword())); - return response.request().newBuilder() - .header("Proxy-Authorization", credential) - .build(); + final String credential = Credentials.basic(authentication.getUserName(), new String(authentication.getPassword())); + + for (Challenge challenge : response.challenges()) { + if (challenge.scheme().equalsIgnoreCase("OkHttp-Preemptive")) { + return response.request().newBuilder() + .header("Proxy-Authorization", credential) + .build(); + } + } + return null; }; } return proxyAuthenticator; } } + + private static class MyAuthenticator extends NonStaticAuthenticator { + private static final Logger LOG = Logger.getInstance(com.intellij.util.net.IdeaWideAuthenticator.class); + private final HttpConfigurable myHttpConfigurable; + + private okhttp3.Response response; + + public MyAuthenticator(@NotNull HttpConfigurable configurable) { + super(); + this.myHttpConfigurable = configurable; + } + + + public void SetResponse(okhttp3.Response response) { + this.response = response; + } + + public PasswordAuthentication getPasswordAuthentication() { + okhttp3.HttpUrl url = response.request().url(); + Application application = ApplicationManager.getApplication(); + + if (StringUtils.isNoneBlank(myHttpConfigurable.getPlainProxyPassword()) && StringUtils.isNoneBlank(myHttpConfigurable.getProxyLogin())) { + return new PasswordAuthentication(myHttpConfigurable.getProxyLogin(), myHttpConfigurable.getPlainProxyPassword().toCharArray()); + } + + if (this.myHttpConfigurable.USE_HTTP_PROXY) { + LOG.debug("CommonAuthenticator.getPasswordAuthentication will return common defined proxy"); + return this.myHttpConfigurable.getPromptedAuthentication(url.host() + ":" + url.port(), this.getRequestingPrompt()); + } + + if (this.myHttpConfigurable.USE_PROXY_PAC) { + LOG.debug("CommonAuthenticator.getPasswordAuthentication will return autodetected proxy"); + if (this.myHttpConfigurable.isGenericPasswordCanceled(this.getRequestingHost(), this.getRequestingPort())) { + return null; + } + + PasswordAuthentication password = this.myHttpConfigurable.getGenericPassword(this.getRequestingHost(), this.getRequestingPort()); + if (password != null) { + return password; + } + + if (application != null && !application.isDisposed()) { + return this.myHttpConfigurable.getGenericPromptedAuthentication(PluginConstant.PLUGIN_ID, this.getRequestingHost(), this.getRequestingPrompt(), this.getRequestingPort(), true); + } + + return null; + } + + if (application != null && !application.isDisposed()) { + LOG.debug("CommonAuthenticator.getPasswordAuthentication generic authentication will be asked"); + return null; + } else { + return null; + } + } + + @Override + protected String getRequestingHost() { + return response.request().url().host(); + } + + @Override + protected int getRequestingPort() { + return response.request().url().port(); + } + + @Override + protected @Nls String getRequestingPrompt() { + return PluginConstant.PLUGIN_ID; + } + } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/window/navigator/AllNavigatorPanel.java b/src/main/java/com/shuzijun/leetcode/plugin/window/navigator/AllNavigatorPanel.java index 3363a44..7ca00c7 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/window/navigator/AllNavigatorPanel.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/window/navigator/AllNavigatorPanel.java @@ -31,6 +31,8 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; import java.util.Map; /** @@ -71,6 +73,12 @@ public AllNavigatorPanel(ToolWindow toolWindow, Project project) { queryField.setToolTipText("Enter Search"); queryField.addKeyListener(new QueryKeyListener(queryField, myNavigatorAction, project)); queryPanel.add(queryField); + queryPanel.addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + queryField.requestFocusInWindow(); + } + }); findToolbar = actionManager.createActionToolbar(PluginConstant.LEETCODE_ALL_FIND_TOOLBAR, (DefaultActionGroup) actionManager.getAction(PluginConstant.LEETCODE_ALL_FIND_TOOLBAR), true); findToolbar.setTargetComponent(navigatorTable); diff --git a/src/main/java/com/shuzijun/leetcode/plugin/window/navigator/NavigatorPanel.java b/src/main/java/com/shuzijun/leetcode/plugin/window/navigator/NavigatorPanel.java index 2a30729..6d9a95c 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/window/navigator/NavigatorPanel.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/window/navigator/NavigatorPanel.java @@ -31,6 +31,8 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; import java.util.Map; /** @@ -71,6 +73,12 @@ public NavigatorPanel(ToolWindow toolWindow, Project project) { queryField.setToolTipText("Enter Search"); queryField.addKeyListener(new QueryKeyListener(queryField, myNavigatorAction, project)); queryPanel.add(queryField); + queryPanel.addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + queryField.requestFocusInWindow(); + } + }); findToolbar = actionManager.createActionToolbar(PluginConstant.LEETCODE_FIND_TOOLBAR, (DefaultActionGroup) actionManager.getAction(PluginConstant.LEETCODE_FIND_TOOLBAR), true); findToolbar.setTargetComponent(navigatorTable); diff --git a/src/main/kotlin/com/shuzijun/leetcode/plugin/listener/RegisterPluginInstallerStateListener.kt b/src/main/kotlin/com/shuzijun/leetcode/plugin/listener/RegisterPluginInstallerStateListener.kt new file mode 100644 index 0000000..07f60c8 --- /dev/null +++ b/src/main/kotlin/com/shuzijun/leetcode/plugin/listener/RegisterPluginInstallerStateListener.kt @@ -0,0 +1,50 @@ +package com.shuzijun.leetcode.plugin.listener + +import com.intellij.ide.plugins.PluginManagerCore.getPlugin +import com.intellij.ide.util.PropertiesComponent +import com.intellij.openapi.extensions.PluginId +import com.intellij.openapi.fileEditor.impl.HTMLEditorProvider +import com.intellij.openapi.project.Project +import com.intellij.openapi.startup.StartupActivity +import com.shuzijun.leetcode.plugin.model.PluginConstant +import com.shuzijun.leetcode.plugin.setting.PersistentConfig + +/** + * @author shuzijun + */ +class RegisterPluginInstallerStateListener : StartupActivity { + override fun runActivity(project: Project) { + val newVersion = getPlugin(PluginId.getId(PluginConstant.PLUGIN_ID))!!.version + val config = PersistentConfig.getInstance().initConfig + val oldVersion: String? + if (config == null) { + oldVersion = PropertiesComponent.getInstance() + .getValue(ShowNewHTMLEditorKey) + PropertiesComponent.getInstance() + .setValue(ShowNewHTMLEditorKey, newVersion) + } else { + oldVersion = config.pluginVersion + config.pluginVersion = newVersion + } + + if (newVersion != oldVersion) { + HTMLEditorProvider.openEditor( + project, + "What's New in " + PluginConstant.PLUGIN_ID, + CHANGELOGURL, + "'
" + + "
Failed to load!
" + + "'" + + "
" + ) + } + } + + companion object { + private const val ShowNewHTMLEditorKey = PluginConstant.PLUGIN_ID + "ShowNewHTMLEditor" + + private const val CHANGELOGURL = "https://github.com/shuzijun/leetcode-editor/blob/master/CHANGELOG.md" + } + +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index a6144b6..f87ed3e 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -22,7 +22,7 @@ - + diff --git a/src/test/java/com/shuzijun/leetcode/HttpTest.java b/src/test/java/com/shuzijun/leetcode/HttpTest.java new file mode 100644 index 0000000..a69ea22 --- /dev/null +++ b/src/test/java/com/shuzijun/leetcode/HttpTest.java @@ -0,0 +1,53 @@ +package com.shuzijun.leetcode; + +import com.shuzijun.lc.errors.LcException; +import com.shuzijun.lc.http.DefaultExecutoHttp; +import okhttp3.Authenticator; +import okhttp3.*; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.junit.Test; + +import java.io.IOException; +import java.net.*; +import java.util.Collections; +import java.util.List; + +public class HttpTest { + + @Test + public void testVerify() throws LcException, IOException { + + DefaultExecutoHttp defaultExecutoHttp = new DefaultExecutoHttp(); + OkHttpClient httpClient = defaultExecutoHttp.getRequestClient().newBuilder().proxySelector(new ProxySelector() { + @Override + public List select(URI uri) { + Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8888)); + return Collections.singletonList(proxy); + } + + @Override + public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { + + } + }).proxyAuthenticator(new Authenticator() { + @Nullable + @Override + public Request authenticate(@Nullable Route route, @NotNull Response response) throws IOException { + PasswordAuthentication authentication =new PasswordAuthentication("test", "test12345".toCharArray()); + final String credential = Credentials.basic(authentication.getUserName(),new String(authentication.getPassword())); + + for (Challenge challenge : response.challenges()) { + if (challenge.scheme().equalsIgnoreCase("OkHttp-Preemptive")) { + return response.request().newBuilder() + .header("Proxy-Authorization", credential) + .build(); + } + } + return null; + } + }).build(); + Response response = httpClient.newCall( (new Request.Builder()).url("https://www.baidu.com").method("get",null).build()).execute(); + System.out.println(response.body()); + } +}