Skip to content

Commit 60be94a

Browse files
authored
Merge pull request #639 from shuzijun/gradle
fix #638
2 parents f4158ec + a0c6d4e commit 60be94a

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

‎src/main/java/com/shuzijun/leetcode/plugin/window/login/LoginPanel.java

+18-15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.intellij.openapi.progress.Task;
88
import com.intellij.openapi.project.Project;
99
import com.intellij.openapi.ui.DialogWrapper;
10+
import com.intellij.openapi.util.Disposer;
1011
import com.intellij.ui.components.JBScrollPane;
1112
import com.intellij.ui.components.JBTextArea;
1213
import com.intellij.ui.jcef.JCEFHtmlPanel;
@@ -58,6 +59,7 @@ public LoginPanel(@Nullable Project project) {
5859
} catch (IllegalArgumentException e) {
5960
jcefPanel = new JcefPanel(project, okAction,true);
6061
}
62+
Disposer.register(getDisposable(),jcefPanel);
6163
jcefPanel.getComponent().setMinimumSize(new Dimension(1000, 500));
6264
jcefPanel.getComponent().setPreferredSize(new Dimension(1000, 500));
6365
panel.addToCenter(new JBScrollPane(jcefPanel.getComponent(), JBScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JBScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
@@ -140,6 +142,8 @@ public void actionPerformed(ActionEvent e) {
140142
}
141143

142144

145+
146+
143147
private static class JcefPanel extends JCEFHtmlPanel {
144148

145149

@@ -185,27 +189,26 @@ public void onLoadingStateChange(CefBrowser browser, boolean isLoading, boolean
185189
@Override
186190
public boolean visit(CefCookie cefCookie, int count, int total, BoolRef boolRef) {
187191

188-
boolean isSession = Boolean.FALSE;
189192
if (cefCookie.domain.contains("leetcode")) {
190193
HttpCookie cookie = new HttpCookie(cefCookie.name, cefCookie.value);
191194
cookie.setDomain(cefCookie.domain);
192195
cookie.setPath(cefCookie.path);
193196
cookieList.add(cookie);
194-
if ("LEETCODE_SESSION".equals(cefCookie.name)) {
195-
isSession = Boolean.TRUE;
196-
}
197197
}
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+
}
209212
}
210213
return true;
211214
}

0 commit comments

Comments
 (0)