Skip to content

Commit 56d84c1

Browse files
authored
Merge pull request #492 from shuzijun/gradle
domain name change
2 parents afe995f + cea39dd commit 56d84c1

File tree

13 files changed

+76
-27
lines changed

13 files changed

+76
-27
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- [Custom Code](https://github.com/shuzijun/leetcode-editor/blob/master/doc/CustomCode.md) ([demo](https://github.com/shuzijun/leetcode-question))
99

1010
## Introduction
11-
Do Leetcode exercises in IDE, support `leetcode.com` and `leetcode-cn.com`, to meet the basic needs of doing exercises.
11+
Do Leetcode exercises in IDE, support `leetcode.com` and `leetcode.cn`, to meet the basic needs of doing exercises.
1212
Support theoretically: IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion GoLand DataGrip Rider MPS Android Studio.
1313
<a href="http://shuzijun.cn/leetcode-editor/monitor.html" target="_blank">be with you!</a>
1414

@@ -35,7 +35,7 @@
3535
</p>
3636

3737
- **Configuration path**: `File` -> `settings`->`tools`->`leetcode plugin`
38-
- **`URL options`**: `leetcode.com`OR`leetcode-cn.com`
38+
- **`URL options`**: `leetcode.com`OR`leetcode.cn`
3939
- **`Code Type`**: `Java`,`Python`,`C++`,`Python3`,`C`,`C#`,`JavaScript`,`Ruby`,`Swift`,`Go` ,`Scala`,`Kotlin`,`Rust`,`PHP`,`Bash`,`SQL`
4040
- **`LoginName`**: Login Username
4141
- **`Password`**: Login password

README_ZH.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- [自定义代码生成](https://github.com/shuzijun/leetcode-editor/blob/master/doc/CustomCode_ZH.md) ([示例](https://github.com/shuzijun/leetcode-question))
99

1010
## 简介
11-
在IDE中解决LeetCode问题,支持`leetcode.com``leetcode-cn.com`,满足基本的做题需求。
11+
在IDE中解决LeetCode问题,支持`leetcode.com``leetcode.cn`,满足基本的做题需求。
1212
理论上支持: IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion GoLand DataGrip Rider MPS Android Studio。
1313
[be with you!](http://shuzijun.cn/leetcode-editor/monitor.html)
1414

@@ -35,7 +35,7 @@
3535
</p>
3636

3737
- **配置路径**: `File` -> `settings`->`tools`->`leetcode plugin`
38-
- **`URL可选项`**: `leetcode.com``leetcode-cn.com`
38+
- **`URL可选项`**: `leetcode.com``leetcode.cn`
3939
- **`Code Type`**: `Java`,`Python`,`C++`,`Python3`,`C`,`C#`,`JavaScript`,`Ruby`,`Swift`,`Go` ,`Scala`,`Kotlin`,`Rust`,`PHP`,`Bash`,`SQL`
4040
- **`LoginName`**: 登录用户名
4141
- **`Password`**: 登录密码

doc/LoginHelp_ZH.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- [中文文档](#登录配置)
44
登录方式:配置用户名密码登录,cookie登录,浏览器登录
55
## 用户名密码登录
6-
在leetcode插件配置页配置用户名密码,如登录失败将加载下面两种登录方式,此方式仅支持leetcode-cn.com
6+
在leetcode插件配置页配置用户名密码,如登录失败将加载下面两种登录方式,此方式仅支持leetcode.cn
77
## cookie登录
88
首先在浏览器中登录leetcode,打开浏览器控制台,复制cookie到登录弹出框,点击login.[参考](https://developers.google.com/web/tools/chrome-devtools/network?hl=zh_cn)
99
<p align="center">

src/main/java/com/shuzijun/leetcode/plugin/actions/editor/AbstractEditAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void actionPerformed(AnActionEvent anActionEvent, Config config) {
3434
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null"));
3535
return;
3636
}
37-
if(!URLUtils.getLeetcodeHost().equals(leetcodeEditor.getHost())){
37+
if(!URLUtils.equalsHost(leetcodeEditor.getHost())){
3838
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.host"));
3939
return;
4040
}

src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenSolutionAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void update(@NotNull AnActionEvent anActionEvent) {
3232
return;
3333
}
3434
LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(anActionEvent.getProject()).getEditor(vf.getPath());
35-
if (leetcodeEditor == null || StringUtils.isBlank(leetcodeEditor.getTitleSlug()) || !URLUtils.getLeetcodeHost().equals(leetcodeEditor.getHost())) {
35+
if (leetcodeEditor == null || StringUtils.isBlank(leetcodeEditor.getTitleSlug()) || !URLUtils.equalsHost(leetcodeEditor.getHost())) {
3636
anActionEvent.getPresentation().setEnabled(false);
3737
return;
3838
}

src/main/java/com/shuzijun/leetcode/plugin/model/Config.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ public boolean isModified(Config config){
375375
if(config ==null){
376376
return false;
377377
}
378-
if (!Objects.equals(version, config.version)) return false;
379378
if (!Objects.equals(loginName, config.loginName)) return false;
380379
if (!Objects.equals(filePath, config.filePath)) return false;
381380
if (!Objects.equals(codeType, config.codeType)) return false;

src/main/java/com/shuzijun/leetcode/plugin/model/Constant.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public class Constant {
7171
public static final Integer PLUGIN_CONFIG_VERSION_1 = 1;
7272
//第二版本,不兼容之前的临时目录,从此版本开始更换新临时目录
7373
public static final Integer PLUGIN_CONFIG_VERSION_2 = 2;
74+
//第三版本,域名更新,需要将cookie更改一下域名
75+
public static final Integer PLUGIN_CONFIG_VERSION_3 = 3;
7476

7577
/**
7678
* 默认题目颜色

src/main/java/com/shuzijun/leetcode/plugin/setting/PersistentConfig.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
import com.intellij.openapi.components.*;
77
import com.intellij.util.xmlb.XmlSerializerUtil;
88
import com.shuzijun.leetcode.plugin.model.Config;
9+
import com.shuzijun.leetcode.plugin.model.Constant;
910
import com.shuzijun.leetcode.plugin.model.PluginConstant;
1011
import com.shuzijun.leetcode.plugin.utils.MessageUtils;
1112
import com.shuzijun.leetcode.plugin.utils.PropertiesUtils;
13+
import com.shuzijun.leetcode.plugin.utils.URLUtils;
14+
import org.apache.commons.lang3.StringUtils;
1215
import org.jetbrains.annotations.NotNull;
1316
import org.jetbrains.annotations.Nullable;
1417

1518
import java.io.File;
1619
import java.util.HashMap;
20+
import java.util.Iterator;
1721
import java.util.Map;
1822

1923
/**
@@ -46,11 +50,27 @@ public void loadState(@NotNull PersistentConfig persistentConfig) {
4650
}
4751

4852
public Config getInitConfig() {
49-
return initConfig.get(INITNAME);
53+
Config config = initConfig.get(INITNAME);
54+
if (config != null && config.getVersion() != null && config.getVersion() < Constant.PLUGIN_CONFIG_VERSION_3) {
55+
if (URLUtils.leetcodecnOld.equals(config.getUrl())) {
56+
config.setUrl(URLUtils.leetcodecn);
57+
}
58+
Iterator<String> iterator = config.getUserCookie().keySet().iterator();
59+
while (iterator.hasNext()) {
60+
String key = iterator.next();
61+
String value = config.getCookie(key);
62+
if (StringUtils.isBlank(value) || key.startsWith(URLUtils.leetcodecnOld)) {
63+
iterator.remove();
64+
}
65+
}
66+
config.setVersion(Constant.PLUGIN_CONFIG_VERSION_3);
67+
setInitConfig(config);
68+
}
69+
return config;
5070
}
5171

5272
public Config getConfig() {
53-
Config config = initConfig.get(INITNAME);
73+
Config config = getInitConfig();
5474
if (config == null) {
5575
MessageUtils.showAllWarnMsg("warning", PropertiesUtils.getInfo("config.first"));
5676
throw new UnsupportedOperationException("not configured:File -> settings->tools->leetcode plugin");
@@ -69,10 +89,10 @@ public String getTempFilePath() {
6989
}
7090

7191
public void savePassword(String password, String username) {
72-
if(username == null || password == null){
92+
if (username == null || password == null) {
7393
return;
7494
}
75-
PasswordSafe.getInstance().set(new CredentialAttributes(PluginConstant.PLUGIN_ID, username, this.getClass()), new Credentials(username, password==null?"":password));
95+
PasswordSafe.getInstance().set(new CredentialAttributes(PluginConstant.PLUGIN_ID, username, this.getClass()), new Credentials(username, password == null ? "" : password));
7696
}
7797

7898
public String getPassword(String username) {

src/main/java/com/shuzijun/leetcode/plugin/setting/ProjectConfig.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
package com.shuzijun.leetcode.plugin.setting;
22

3-
import com.intellij.openapi.components.*;
3+
import com.intellij.openapi.components.PersistentStateComponent;
4+
import com.intellij.openapi.components.State;
5+
import com.intellij.openapi.components.Storage;
46
import com.intellij.openapi.project.Project;
57
import com.intellij.util.xmlb.annotations.MapAnnotation;
68
import com.shuzijun.leetcode.plugin.model.LeetcodeEditor;
79
import com.shuzijun.leetcode.plugin.model.PluginConstant;
10+
import com.shuzijun.leetcode.plugin.utils.URLUtils;
811
import org.apache.commons.lang3.StringUtils;
912
import org.jetbrains.annotations.NotNull;
1013
import org.jetbrains.annotations.Nullable;
1114

1215
import java.util.HashMap;
16+
import java.util.Iterator;
1317
import java.util.Map;
1418

1519
/**
1620
* @author shuzijun
1721
*/
18-
@State(name = "LeetcodeEditor" + PluginConstant.ACTION_SUFFIX, storages = {@Storage(value = PluginConstant.ACTION_PREFIX+"/editor.xml")})
19-
public class ProjectConfig implements PersistentStateComponent<ProjectConfig.InnerState> {
22+
@State(name = "LeetcodeEditor" + PluginConstant.ACTION_SUFFIX, storages = {@Storage(value = PluginConstant.ACTION_PREFIX + "/editor.xml")})
23+
public class ProjectConfig implements PersistentStateComponent<ProjectConfig.InnerState> {
2024

2125
public Map<String, LeetcodeEditor> idProjectConfig = new HashMap<>();
2226

@@ -37,24 +41,34 @@ public ProjectConfig.InnerState getState() {
3741
public void loadState(@NotNull ProjectConfig.InnerState innerState) {
3842
this.innerState = innerState;
3943
idProjectConfig.clear();
40-
this.innerState.projectConfig.forEach((s, leetcodeEditor) -> {
41-
idProjectConfig.put(leetcodeEditor.getFrontendQuestionId(),leetcodeEditor);
42-
});
44+
Iterator<String> iter = this.innerState.projectConfig.keySet().iterator();
45+
while (iter.hasNext()) {
46+
String key = iter.next();
47+
LeetcodeEditor leetcodeEditor = this.innerState.projectConfig.get(key);
48+
if (StringUtils.isBlank(leetcodeEditor.getFrontendQuestionId())) {
49+
iter.remove();
50+
continue;
51+
} else if (leetcodeEditor.getFrontendQuestionId().startsWith(URLUtils.leetcodecnOld)) {
52+
leetcodeEditor.setHost(URLUtils.leetcodecn);
53+
leetcodeEditor.setFrontendQuestionId(leetcodeEditor.getFrontendQuestionId().replace(URLUtils.leetcodecnOld, URLUtils.leetcodecn));
54+
}
55+
idProjectConfig.put(leetcodeEditor.getFrontendQuestionId(), leetcodeEditor);
56+
}
4357
}
4458

4559

4660
public LeetcodeEditor getDefEditor(String frontendQuestionId) {
4761
LeetcodeEditor leetcodeEditor = idProjectConfig.get(frontendQuestionId);
4862
if (leetcodeEditor == null) {
4963
leetcodeEditor = new LeetcodeEditor();
50-
idProjectConfig.put(frontendQuestionId,leetcodeEditor);
64+
idProjectConfig.put(frontendQuestionId, leetcodeEditor);
5165
}
5266
return leetcodeEditor;
5367
}
5468

5569
public void addLeetcodeEditor(LeetcodeEditor leetcodeEditor) {
5670
idProjectConfig.put(leetcodeEditor.getFrontendQuestionId(), leetcodeEditor);
57-
if(StringUtils.isNotBlank(leetcodeEditor.getPath())) {
71+
if (StringUtils.isNotBlank(leetcodeEditor.getPath())) {
5872
innerState.projectConfig.put(leetcodeEditor.getPath(), leetcodeEditor);
5973
}
6074
}

src/main/java/com/shuzijun/leetcode/plugin/setting/SettingUI.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ public void apply() {
251251
}
252252

253253
public void process(Config config) {
254-
config.setVersion(Constant.PLUGIN_CONFIG_VERSION_2);
254+
if(config.getVersion() == null) {
255+
config.setVersion(Constant.PLUGIN_CONFIG_VERSION_3);
256+
}
255257
config.setLoginName(userNameField.getText());
256258
config.setFilePath(fileFolderBtn.getText());
257259
config.setCodeType(codeComboBox.getSelectedItem().toString());

0 commit comments

Comments
 (0)