|
7 | 7 | import com.intellij.openapi.progress.Task; |
8 | 8 | import com.intellij.openapi.project.Project; |
9 | 9 | import com.intellij.openapi.ui.DialogWrapper; |
| 10 | +import com.intellij.openapi.util.Disposer; |
10 | 11 | import com.intellij.ui.components.JBScrollPane; |
11 | 12 | import com.intellij.ui.components.JBTextArea; |
12 | 13 | import com.intellij.ui.jcef.JCEFHtmlPanel; |
@@ -58,6 +59,7 @@ public LoginPanel(@Nullable Project project) { |
58 | 59 | } catch (IllegalArgumentException e) { |
59 | 60 | jcefPanel = new JcefPanel(project, okAction,true); |
60 | 61 | } |
| 62 | + Disposer.register(getDisposable(),jcefPanel); |
61 | 63 | jcefPanel.getComponent().setMinimumSize(new Dimension(1000, 500)); |
62 | 64 | jcefPanel.getComponent().setPreferredSize(new Dimension(1000, 500)); |
63 | 65 | panel.addToCenter(new JBScrollPane(jcefPanel.getComponent(), JBScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JBScrollPane.HORIZONTAL_SCROLLBAR_NEVER)); |
@@ -140,6 +142,8 @@ public void actionPerformed(ActionEvent e) { |
140 | 142 | } |
141 | 143 |
|
142 | 144 |
|
| 145 | + |
| 146 | + |
143 | 147 | private static class JcefPanel extends JCEFHtmlPanel { |
144 | 148 |
|
145 | 149 |
|
@@ -185,27 +189,26 @@ public void onLoadingStateChange(CefBrowser browser, boolean isLoading, boolean |
185 | 189 | @Override |
186 | 190 | public boolean visit(CefCookie cefCookie, int count, int total, BoolRef boolRef) { |
187 | 191 |
|
188 | | - boolean isSession = Boolean.FALSE; |
189 | 192 | if (cefCookie.domain.contains("leetcode")) { |
190 | 193 | HttpCookie cookie = new HttpCookie(cefCookie.name, cefCookie.value); |
191 | 194 | cookie.setDomain(cefCookie.domain); |
192 | 195 | cookie.setPath(cefCookie.path); |
193 | 196 | cookieList.add(cookie); |
194 | | - if ("LEETCODE_SESSION".equals(cefCookie.name)) { |
195 | | - isSession = Boolean.TRUE; |
196 | | - } |
197 | 197 | } |
198 | | - if (count == total - 1 && isSession) { |
199 | | - HttpRequestUtils.setCookie(cookieList); |
200 | | - if (HttpRequestUtils.isLogin(project)) { |
201 | | - HttpLogin.loginSuccess(project, cookieList); |
202 | | - MessageUtils.getInstance(project).showWarnMsg("", PropertiesUtils.getInfo("browser.login.success")); |
203 | | - ApplicationManager.getApplication().invokeLater(() -> okAction.actionPerformed(null)); |
204 | | - successDispose = true; |
205 | | - } else { |
206 | | - cookieList.clear(); |
207 | | - LogUtils.LOG.info("login failure"); |
208 | | - } |
| 198 | + if (count == total - 1) { |
| 199 | + if (cookieList.stream().anyMatch(cookie -> cookie.getName().equals("LEETCODE_SESSION")) && |
| 200 | + !HttpRequestUtils.isLogin(project)) { |
| 201 | + HttpRequestUtils.setCookie(cookieList); |
| 202 | + if (HttpRequestUtils.isLogin(project)) { |
| 203 | + HttpLogin.loginSuccess(project, cookieList); |
| 204 | + MessageUtils.getInstance(project).showWarnMsg("", PropertiesUtils.getInfo("browser.login.success")); |
| 205 | + ApplicationManager.getApplication().invokeLater(() -> okAction.actionPerformed(null)); |
| 206 | + successDispose = true; |
| 207 | + } else { |
| 208 | + cookieList.clear(); |
| 209 | + LogUtils.LOG.info("login failure"); |
| 210 | + } |
| 211 | + } |
209 | 212 | } |
210 | 213 | return true; |
211 | 214 | } |
|
0 commit comments