diff --git a/CHANGELOG.md b/CHANGELOG.md
index 408fe73..184d2fc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,9 @@
# intellij-chatgpt Changelog
## [Unreleased]
+- Remove session token check because of Cloudflare
+- Add refresh button [#2](https://github.com/LiLittleCat/intellij-chatgpt/issues/2)
+- Support version 2020.2-2022.3 [#3](https://github.com/LiLittleCat/intellij-chatgpt/issues/3)
## [1.0.1] - 2022-12-12
diff --git a/build.gradle.kts b/build.gradle.kts
index c714303..bf426b8 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,7 +1,6 @@
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
-import org.jetbrains.kotlin.ir.backend.js.compile
fun properties(key: String) = project.findProperty(key).toString()
@@ -11,7 +10,7 @@ plugins {
// Kotlin support
id("org.jetbrains.kotlin.jvm") version "1.7.21"
// Gradle IntelliJ Plugin
- id("org.jetbrains.intellij") version "1.10.0"
+ id("org.jetbrains.intellij") version "1.10.1"
// Gradle Changelog Plugin
id("org.jetbrains.changelog") version "2.0.0"
// Gradle Qodana Plugin
diff --git a/gradle.properties b/gradle.properties
index f7434e0..2f2f6e1 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -4,15 +4,15 @@ pluginGroup = com.lilittlecat.intellij-chatgpt
pluginName = ChatGPT Tool
pluginRepositoryUrl = https://github.com/LiLittleCat/intellij-chatgpt
# SemVer format -> https://semver.org
-pluginVersion = 1.0.1
+pluginVersion = 1.0.2
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
-pluginSinceBuild = 221
+pluginSinceBuild = 202
pluginUntilBuild = 223.*
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
-platformVersion = 2022.1
+platformVersion = 2020.2
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
diff --git a/src/main/java/com/lilittlecat/chatgpt/action/RefreshAction.java b/src/main/java/com/lilittlecat/chatgpt/action/RefreshAction.java
new file mode 100644
index 0000000..07971c7
--- /dev/null
+++ b/src/main/java/com/lilittlecat/chatgpt/action/RefreshAction.java
@@ -0,0 +1,45 @@
+package com.lilittlecat.chatgpt.action;
+
+import com.intellij.icons.AllIcons;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.project.DumbAwareAction;
+import com.intellij.openapi.wm.ToolWindow;
+import com.intellij.openapi.wm.ToolWindowManager;
+import com.intellij.ui.content.Content;
+import com.intellij.ui.content.ContentFactory;
+import com.intellij.ui.content.ContentManager;
+import com.lilittlecat.chatgpt.message.ChatGPTBundle;
+import com.lilittlecat.chatgpt.window.ChatGPTToolWindow;
+import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Objects;
+
+/**
+ * @author LiLittleCat
+ * @link https://github.com/LiLittleCat
+ * @since 2022/12/15
+ */
+public class RefreshAction extends DumbAwareAction {
+ public RefreshAction(@NotNull @Nls String text) {
+ super(() -> text, AllIcons.Actions.Refresh);
+ }
+
+ @Override
+ public void actionPerformed(@NotNull AnActionEvent e) {
+ ToolWindowManager instance = ToolWindowManager.getInstance(Objects.requireNonNull(e.getProject()));
+ ToolWindow toolWindow = instance.getToolWindow("ChatGPT");
+ if (toolWindow != null) {
+ ContentManager contentManager = toolWindow.getContentManager();
+ Content browserContent = contentManager.findContent(ChatGPTBundle.message("browser.tab.name"));
+ if (browserContent != null) {
+ contentManager.removeContent(browserContent, false);
+ }
+ ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
+ Content browser = contentFactory.createContent(new ChatGPTToolWindow().getContent(),
+ ChatGPTBundle.message("browser.tab.name"), false);
+ contentManager.addContent(browser);
+ contentManager.setSelectedContent(browser);
+ }
+ }
+}
diff --git a/src/main/java/com/lilittlecat/chatgpt/window/ChatGPTToolWindow.java b/src/main/java/com/lilittlecat/chatgpt/window/ChatGPTToolWindow.java
index cc09e53..723f127 100644
--- a/src/main/java/com/lilittlecat/chatgpt/window/ChatGPTToolWindow.java
+++ b/src/main/java/com/lilittlecat/chatgpt/window/ChatGPTToolWindow.java
@@ -9,7 +9,6 @@
import com.lilittlecat.chatgpt.setting.ChatGPTSettingsState;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
-import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -59,25 +58,27 @@ public ChatGPTToolWindow() {
if (StringUtils.isNotBlank(sessionToken)) {
// check the token is right or not
- String cookie = sessionTokenName + "=" + sessionToken;
- HttpGet httpGet = new HttpGet("https://chat.openai.com/chat");
- httpGet.setHeader("Connection", "keep-alive");
- httpGet.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15");
- httpGet.setHeader("Cookie", cookie);
- httpGet.setHeader("Origin", "https://auth0.openai.com");
- httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
- httpGet.setHeader("Accept-Language", "en-US,en;q=0.9");
- try (CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
- HttpEntity httpEntity = httpResponse.getEntity();
- String bodyString = EntityUtils.toString(httpEntity);
- if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK && !bodyString.contains("Welcome to ChatGPT")) {
- JBCefCookie jbCefCookie = new JBCefCookie(sessionTokenName, sessionToken, "chat.openai.com", "/", true, true);
- jbCefCookieManager.setCookie("https://chat.openai.com", jbCefCookie);
- }
- } catch (IOException e) {
- LOG.error("Error when check session token: ", e);
- }
+ // 2022.12.16 with Cloudflare, can not check token by http get
+
+// String cookie = sessionTokenName + "=" + sessionToken;
+// HttpGet httpGet = new HttpGet("https://chat.openai.com/chat");
+// httpGet.setHeader("Connection", "keep-alive");
+// httpGet.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15");
+// httpGet.setHeader("Cookie", cookie);
+// httpGet.setHeader("Origin", "https://auth0.openai.com");
+// httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
+// httpGet.setHeader("Accept-Language", "en-US,en;q=0.9");
+// try (CloseableHttpClient httpClient = HttpClients.createDefault();
+// CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
+// HttpEntity httpEntity = httpResponse.getEntity();
+// String bodyString = EntityUtils.toString(httpEntity);
+// if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK && !bodyString.contains("Welcome to ChatGPT")) {
+ JBCefCookie jbCefCookie = new JBCefCookie(sessionTokenName, sessionToken, "chat.openai.com", "/", true, true);
+ jbCefCookieManager.setCookie("https://chat.openai.com", jbCefCookie, null);
+// }
+// } catch (IOException e) {
+// LOG.error("Error when check session token: ", e);
+// }
}
}
// get session token after login, fill it in settings
@@ -86,10 +87,12 @@ public ChatGPTToolWindow() {
String currentSessionToken = null;
while (currentSessionToken == null) {
List cookies = jbCefCookieManager.getCookies();
- for (JBCefCookie cookie : cookies) {
- if (cookie.getName().equals(sessionTokenName)) {
- currentSessionToken = cookie.getValue();
- ChatGPTSettingsState.getInstance().update(currentSessionToken);
+ if (!cookies.isEmpty()) {
+ for (JBCefCookie cookie : cookies) {
+ if (cookie.getName().equals(sessionTokenName)) {
+ currentSessionToken = cookie.getValue();
+ ChatGPTSettingsState.getInstance().update(currentSessionToken);
+ }
}
}
try {
diff --git a/src/main/java/com/lilittlecat/chatgpt/window/ChatGPTToolWindowFactory.java b/src/main/java/com/lilittlecat/chatgpt/window/ChatGPTToolWindowFactory.java
index 3e67207..2da193b 100644
--- a/src/main/java/com/lilittlecat/chatgpt/window/ChatGPTToolWindowFactory.java
+++ b/src/main/java/com/lilittlecat/chatgpt/window/ChatGPTToolWindowFactory.java
@@ -6,7 +6,9 @@
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentManager;
+import com.lilittlecat.chatgpt.action.RefreshAction;
import com.lilittlecat.chatgpt.action.SettingsAction;
+import com.lilittlecat.chatgpt.message.ChatGPTBundle;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -22,11 +24,12 @@ public class ChatGPTToolWindowFactory implements ToolWindowFactory {
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
ContentManager contentManager = toolWindow.getContentManager();
Content labelContent = contentManager.getFactory().createContent(
- new ChatGPTToolWindow().getContent(), null, false);
+ new ChatGPTToolWindow().getContent(), ChatGPTBundle.message("browser.tab.name"), false);
contentManager.addContent(labelContent);
// add actions to tool window
List anActionList = new ArrayList<>();
anActionList.add(new SettingsAction("Settings"));
+ anActionList.add(new RefreshAction("Refresh"));
toolWindow.setTitleActions(anActionList);
}
}
diff --git a/src/main/resources/messages/ChatGPTBundle.properties b/src/main/resources/messages/ChatGPTBundle.properties
index e360421..e2d149f 100644
--- a/src/main/resources/messages/ChatGPTBundle.properties
+++ b/src/main/resources/messages/ChatGPTBundle.properties
@@ -1,4 +1,5 @@
name=ChatGPT
setting.session.token.label=Session token:
-setting.menu.text=ChatGPT
\ No newline at end of file
+setting.menu.text=ChatGPT
+browser.tab.name=chat.openai.com
\ No newline at end of file