Skip to content

Commit c8c7314

Browse files
committed
add click url feedback
1 parent ce08ea2 commit c8c7314

File tree

3 files changed

+43
-30
lines changed

3 files changed

+43
-30
lines changed

src/main/kotlin/wu/seal/jsontokotlin/feedback/Actions.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import java.util.*
1111
const val ACTION_START = "action_start"
1212
const val ACTION_SUCCESS_COMPLETE = "action_success_complete"
1313
const val ACTION_FORMAT_JSON = "action_format_json"
14+
const val ACTION_CLICK_PROJECT_URL = "action_click_project_url"
1415

1516
data class StartAction(
1617
val uuid: String = UUID,
@@ -34,4 +35,12 @@ data class FormatJSONAction(
3435
val actionType: String = ACTION_FORMAT_JSON,
3536
val time: String = Date().time.toString(),
3637
val daytime: String = SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(Date())
38+
)
39+
40+
data class ClickProjectURLAction(
41+
val uuid: String = UUID,
42+
val pluginVersion: String = PLUGIN_VERSION,
43+
val actionType: String = ACTION_CLICK_PROJECT_URL,
44+
val time: String = Date().time.toString(),
45+
val daytime: String = SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(Date())
3746
)

src/main/kotlin/wu/seal/jsontokotlin/feedback/NetWork.kt

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,43 +48,45 @@ fun sendHistoryActionInfo() {
4848
}
4949

5050
fun sendData(url: String, log: String) {
51-
try {
52-
with(URL(url).openConnection() as HttpURLConnection) {
53-
when (url) {
54-
actionInfoUrl, configLogUrl -> {
55-
doOutput = true
56-
requestMethod = "POST"
57-
addRequestProperty("Content-Type", "application/json;charset=UTF-8")
51+
Thread {
52+
try {
53+
with(URL(url).openConnection() as HttpURLConnection) {
54+
when (url) {
55+
actionInfoUrl, configLogUrl -> {
56+
doOutput = true
57+
requestMethod = "POST"
58+
addRequestProperty("Content-Type", "application/json;charset=UTF-8")
59+
}
60+
61+
exceptionLogUrl -> {
62+
doOutput = true
63+
doInput = true
64+
addRequestProperty("Content-Type", "application/text")
65+
}
5866
}
59-
60-
exceptionLogUrl -> {
61-
doOutput = true
62-
doInput = true
63-
addRequestProperty("Content-Type", "application/text")
67+
outputStream.use {
68+
val writer = it.writer()
69+
writer.write(log)
70+
writer.flush()
6471
}
72+
if (responseCode != HttpURLConnection.HTTP_OK) {
73+
val a = responseMessage + "\n" + errorStream.use { it.reader().readText() }
74+
println(a)
75+
}
76+
disconnect()
6577
}
66-
outputStream.use {
67-
val writer = it.writer()
68-
writer.write(log)
69-
writer.flush()
70-
}
71-
if (responseCode != HttpURLConnection.HTTP_OK) {
72-
val a = responseMessage + "\n" + errorStream.use { it.reader().readText() }
73-
println(a)
74-
}
75-
disconnect()
76-
}
77-
} catch (e: Exception) {
78+
} catch (e: Exception) {
7879

79-
e.printStackTrace()
80+
e.printStackTrace()
8081

81-
when (url) {
82+
when (url) {
8283

83-
actionInfoUrl -> PersistCache.saveActionInfo(log)
84+
actionInfoUrl -> PersistCache.saveActionInfo(log)
8485

85-
exceptionLogUrl -> PersistCache.saveExceptionInfo(log)
86+
exceptionLogUrl -> PersistCache.saveExceptionInfo(log)
8687

87-
else -> Unit//Do nothing
88+
else -> Unit//Do nothing
89+
}
8890
}
89-
}
91+
}.start()
9092
}

src/main/kotlin/wu/seal/jsontokotlin/ui/JsonInputDialog.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.intellij.openapi.util.IconLoader
1515
import com.intellij.ui.components.JBLabel
1616
import com.intellij.util.ui.JBDimension
1717
import com.intellij.util.ui.JBEmptyBorder
18+
import wu.seal.jsontokotlin.feedback.ClickProjectURLAction
1819
import wu.seal.jsontokotlin.feedback.FormatJSONAction
1920
import wu.seal.jsontokotlin.feedback.sendActionInfo
2021
import wu.seal.jsontokotlin.utils.addComponentIntoVerticalBoxAlignmentLeft
@@ -198,6 +199,7 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
198199

199200
projectLink.addMouseListener(object : MouseAdapter() {
200201
override fun mouseClicked(e: MouseEvent?) {
202+
sendActionInfo(prettyGson.toJson(ClickProjectURLAction()))
201203
Desktop.getDesktop().browse(URI("https://github.com/wuseal/JsonToKotlinClass"))
202204
}
203205

0 commit comments

Comments
 (0)