Skip to content

Commit 9fdea1c

Browse files
committed
feat: update
1 parent ac36e20 commit 9fdea1c

File tree

7 files changed

+98
-26
lines changed

7 files changed

+98
-26
lines changed

CHANGELOG.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@
44

55
## [Unreleased]
66
### Added
7+
- Add hint information at the configuration window
78

89
### Changed
10+
- Change deprecated api
11+
- Modify the minimum compatible IDE version
912

10-
### Deprecated
11-
12-
### Removed
13-
14-
### Fixed
15-
16-
### Security
1713
## [0.0.4]
1814
### Changed
1915
- Modify the minimum compatible IDE version
2016

21-
## [0.0.3] - 2020-12-16
17+
## [0.0.3]
2218
### Removed
2319
- remove unnecessary code
2420

build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,9 @@ tasks {
130130
// https://jetbrains.org/intellij/sdk/docs/tutorials/build_system/deployment.html#specifying-a-release-channel
131131
channels(pluginVersion.split('-').getOrElse(1) { "default" }.split('.').first())
132132
}
133+
134+
runIde {
135+
// need restart ide
136+
autoReloadPlugins = false
137+
}
133138
}

gradle.properties

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
pluginGroup = com.github.si9ma.codetimejetbrains
55
pluginName_ = codetime
6-
pluginVersion = 0.0.4
7-
pluginSinceBuild = 162
6+
pluginVersion = 0.0.5
7+
pluginSinceBuild = 193
88
pluginUntilBuild = 203.*
99
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
1010
# See https://jb.gg/intellij-platform-builds-list for available build versions
11-
pluginVerifierIdeVersions = 2016.1.4, 2020.1.4, 2020.2.3, 2020.3
11+
pluginVerifierIdeVersions = 2020.2.1, 2020.1.4, 2020.2.3, 2020.3
1212

1313
platformType = IC
1414
platformVersion = 2020.1
@@ -20,3 +20,9 @@ platformPlugins =
2020
# Opt-out flag for bundling Kotlin standard library.
2121
# See https://kotlinlang.org/docs/reference/using-gradle.html#dependency-on-the-standard-library for details.
2222
kotlin.stdlib.default.dependency = false
23+
24+
# proxy
25+
systemProp.http.proxyHost=127.0.0.1
26+
systemProp.http.proxyPort=8001
27+
systemProp.https.proxyHost=127.0.0.1
28+
systemProp.https.proxyPort=8001
Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,107 @@
11
package com.github.si9ma.codetimejetbrains
22

3+
import com.github.kittinunf.fuel.Fuel
4+
import com.github.kittinunf.fuel.json.responseJson
5+
import com.github.kittinunf.result.Result
6+
import com.intellij.openapi.diagnostic.Logger
37
import com.intellij.openapi.project.Project
48
import com.intellij.openapi.ui.DialogWrapper
59
import org.jetbrains.annotations.Nullable
10+
import java.awt.Color
11+
import java.awt.Cursor
12+
import java.awt.Desktop
613
import java.awt.GridLayout
14+
import java.awt.event.MouseAdapter
15+
import java.awt.event.MouseEvent
16+
import java.io.IOException
17+
import java.net.URI
18+
import java.net.URISyntaxException
719
import javax.swing.JCheckBox
820
import javax.swing.JComponent
921
import javax.swing.JLabel
22+
import javax.swing.JOptionPane
1023
import javax.swing.JPanel
1124
import javax.swing.JTextField
1225

1326
const val TOKEN_FIELD_COLUMNS = 30
27+
const val TIP_TEXT = "Go to codetime to get a token"
1428

1529
class ConfigWindow constructor(project: Project) : DialogWrapper(project, true) {
1630
private lateinit var tokenField: JTextField
1731
private lateinit var debugCheckBox: JCheckBox
32+
private val log: Logger = Logger.getInstance("CodeTime")
1833

1934
@Nullable
20-
protected override fun createCenterPanel(): JComponent {
35+
override fun createCenterPanel(): JComponent {
2136
val panel = JPanel()
2237

2338
// token
2439
panel.layout = GridLayout(0, 2)
25-
var tokenLabel = JLabel("Token:", JLabel.CENTER)
40+
val tokenLabel = JLabel("Token:", JLabel.CENTER)
2641
tokenField = JTextField(TOKEN_FIELD_COLUMNS)
2742
panel.add(tokenLabel)
2843
tokenField.text = PluginStateComponent.instance.state.token
2944
panel.add(tokenField)
3045

3146
// debug
32-
var debugLabel = JLabel("Debug:", JLabel.CENTER)
47+
val debugLabel = JLabel("Debug:", JLabel.CENTER)
3348
panel.add(debugLabel)
3449
debugCheckBox = JCheckBox()
3550
debugCheckBox.isSelected = PluginStateComponent.instance.state.debug
3651
panel.add(debugCheckBox)
52+
53+
// tip
54+
val tipLabel = JLabel("No Token?", JLabel.CENTER)
55+
val tipLink = JLabel(TIP_TEXT)
56+
tipLink.foreground = Color.BLUE.darker()
57+
tipLink.cursor = Cursor(Cursor.HAND_CURSOR)
58+
tipLink.addMouseListener(
59+
object : MouseAdapter() {
60+
override fun mouseClicked(e: MouseEvent?) {
61+
try {
62+
Desktop.getDesktop().browse(URI("https://codetime.datreks.com/"))
63+
} catch (e1: IOException) {
64+
log.warn("click link failed:${e1.printStackTrace()}")
65+
} catch (e1: URISyntaxException) {
66+
log.warn("click link failed:${e1.printStackTrace()}")
67+
}
68+
}
69+
70+
override fun mouseExited(e: MouseEvent?) {
71+
tipLink.text = TIP_TEXT
72+
}
73+
74+
override fun mouseEntered(e: MouseEvent?) {
75+
tipLink.text = "<html><a href=''>$TIP_TEXT</a></html>"
76+
}
77+
}
78+
)
79+
panel.add(tipLabel)
80+
panel.add(tipLink)
81+
3782
return panel
3883
}
3984

4085
override fun doOKAction() {
41-
PluginStateComponent.instance.state.token = tokenField.text
42-
PluginStateComponent.instance.state.debug = debugCheckBox.isSelected
43-
super.doOKAction()
86+
// check if token is valid
87+
val (_, _, result) = Fuel.get("https://codetime-api.datreks.com/checkLogin").header("token", tokenField.text)
88+
.responseJson()
89+
when (result) {
90+
is Result.Failure -> {
91+
log.warn("check token failed:${result.error}")
92+
JOptionPane.showMessageDialog(null, "Invalid token")
93+
}
94+
is Result.Success -> {
95+
log.info("check token success")
96+
PluginStateComponent.instance.state.token = tokenField.text
97+
PluginStateComponent.instance.state.debug = debugCheckBox.isSelected
98+
super.doOKAction()
99+
}
100+
}
44101
}
45102

46103
init {
47104
init()
48-
setTitle("CodeTime Configuration")
105+
title = "CodeTime Configuration"
49106
}
50107
}

src/main/kotlin/com/github/si9ma/codetimejetbrains/PluginStateComponent.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.si9ma.codetimejetbrains
22

3+
import com.intellij.openapi.Disposable
34
import com.intellij.openapi.components.PersistentStateComponent
45
import com.intellij.openapi.components.ServiceManager
56
import com.intellij.openapi.components.State
@@ -9,15 +10,15 @@ import com.intellij.openapi.components.Storage
910
name = "PluginStateComponent",
1011
storages = [Storage("codetime.xml")]
1112
)
12-
open class PluginStateComponent : PersistentStateComponent<PluginStateComponent.PluginState> {
13+
open class PluginStateComponent : PersistentStateComponent<PluginStateComponent.PluginState>, Disposable {
1314
// this is how we're going to call the component from different classes
1415
companion object {
1516
val instance: PluginStateComponent
1617
get() = ServiceManager.getService(PluginStateComponent::class.java)
1718
}
1819

1920
// the component will always keep our state as a variable
20-
var pluginState: PluginState = PluginState()
21+
private var pluginState: PluginState = PluginState()
2122

2223
override fun getState(): PluginState {
2324
return pluginState
@@ -31,4 +32,8 @@ open class PluginStateComponent : PersistentStateComponent<PluginStateComponent.
3132
var token = ""
3233
var debug = false
3334
}
35+
36+
override fun dispose() {
37+
TODO("Not yet implemented")
38+
}
3439
}

src/main/kotlin/com/github/si9ma/codetimejetbrains/listeners/CodeTimeProjectManagerListener.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import com.github.si9ma.codetimejetbrains.ConfigWindow
88
import com.github.si9ma.codetimejetbrains.PluginStateComponent
99
import com.github.si9ma.codetimejetbrains.Queue
1010
import com.google.common.primitives.UnsignedInts.toLong
11-
import com.intellij.ide.plugins.PluginManager
11+
import com.intellij.ide.plugins.PluginManagerCore
1212
import com.intellij.openapi.application.ApplicationInfo
13+
import com.intellij.openapi.application.ApplicationNamesInfo
1314
import com.intellij.openapi.diagnostic.Logger
1415
import com.intellij.openapi.editor.EditorFactory
1516
import com.intellij.openapi.extensions.PluginId
1617
import com.intellij.openapi.project.Project
1718
import com.intellij.openapi.project.ProjectManagerListener
1819
import com.intellij.openapi.project.guessProjectDir
1920
import com.intellij.openapi.ui.Messages
20-
import com.intellij.util.PlatformUtils
2121
import java.util.Timer
2222
import java.util.UUID
2323
import kotlin.concurrent.timerTask
@@ -55,9 +55,12 @@ class CodeTimeProjectManagerListener : ProjectManagerListener {
5555
}
5656

5757
init {
58-
val version = PluginManager.getPlugin(PluginId.getId("com.github.si9ma.codetimejetbrains"))?.version
58+
val version = PluginManagerCore.getPlugin(PluginId.getId("com.github.si9ma.codetimejetbrains"))?.version
5959
log.info("Initializing CodeTime plugin:$version (https://codetime.datreks.com/)")
60-
EditorFactory.getInstance().eventMulticaster.addVisibleAreaListener(CodeTimeVisibleAreaListener())
60+
EditorFactory.getInstance().eventMulticaster.addVisibleAreaListener(
61+
CodeTimeVisibleAreaListener(),
62+
PluginStateComponent.instance
63+
)
6164
}
6265

6366
private fun submitEventLog(project: Project, uuid: String, event: MutableMap<String, Any>) {
@@ -67,7 +70,7 @@ class CodeTimeProjectManagerListener : ProjectManagerListener {
6770
event["platform"] = System.getProperty("os.name")
6871
event["platformVersion"] = System.getProperty("os.version")
6972
event["platformArch"] = System.getProperty("os.arch")
70-
event["editor"] = PlatformUtils.getPlatformPrefix()
73+
event["editor"] = ApplicationNamesInfo.getInstance().fullProductName
7174
event["editorVersion"] = ApplicationInfo.getInstance().fullVersion
7275
event["sessionID"] = uuid
7376
event["relativeFile"] = projectPath?.let { absoluteFile.toString().removePrefix(it) } ?: ""

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<idea-plugin>
1+
<idea-plugin require-restart="true">
22
<id>com.github.si9ma.codetimejetbrains</id>
33
<name>codetime</name>
44
<vendor>si9ma</vendor>

0 commit comments

Comments
 (0)