generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from bluelhf/main
Add inactivity state and fix hostname bug
- Loading branch information
Showing
9 changed files
with
216 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
22 changes: 18 additions & 4 deletions
22
src/main/kotlin/fi/testaustime/plugin_intellij/network/models/ActivityPostPayload.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
package fi.testaustime.plugin_intellij.network.models | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import com.intellij.openapi.project.Project | ||
import fi.testaustime.plugin_intellij.utils.ContextInformation | ||
import fi.testaustime.plugin_intellij.utils.ContextInformation.getFriendlyName | ||
|
||
class ActivityPostPayload( | ||
data class ActivityPostPayload( | ||
@SerializedName("hostname") val hostname: String?, | ||
@SerializedName("language") val programmingLanguage: String?, | ||
@SerializedName("hostname") val host: String, | ||
@SerializedName("editor_name") val IDEName: String, | ||
@SerializedName("project_name") val projectName: String, | ||
) | ||
@SerializedName("editor_name") val application: String, | ||
) { | ||
companion object { | ||
fun fromProject(project: Project): ActivityPostPayload { | ||
return ActivityPostPayload( | ||
hostname = ContextInformation.getHostname(), | ||
programmingLanguage = ContextInformation.getProgrammingLanguage(), | ||
application = ContextInformation.getApplicationName(), | ||
projectName = project.getFriendlyName() | ||
) | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/fi/testaustime/plugin_intellij/services/CaretMoveListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package fi.testaustime.plugin_intellij.services | ||
|
||
import com.intellij.openapi.editor.EditorFactory | ||
import com.intellij.openapi.editor.event.CaretEvent | ||
import com.intellij.openapi.editor.event.EditorFactoryEvent | ||
import com.intellij.openapi.editor.event.EditorFactoryListener | ||
import java.time.Duration | ||
import java.time.Duration.ofSeconds | ||
import java.time.Instant | ||
import java.time.Instant.now | ||
|
||
class CaretMoveListener(service: TestaustimeProjectService) : com.intellij.openapi.editor.event.CaretListener { | ||
companion object { | ||
val TIMEOUT: Duration = ofSeconds(30) | ||
} | ||
|
||
init { | ||
EditorFactory.getInstance().addEditorFactoryListener(object : EditorFactoryListener { | ||
override fun editorCreated(event: EditorFactoryEvent) { | ||
event.editor.caretModel.addCaretListener(this@CaretMoveListener) | ||
} | ||
}, service) | ||
} | ||
|
||
private var lastActive: Instant = now() | ||
|
||
override fun caretPositionChanged(event: CaretEvent) { | ||
lastActive = now() | ||
} | ||
|
||
fun isActive(): Boolean { | ||
return Duration.between(lastActive, now()) <= TIMEOUT | ||
} | ||
} |
145 changes: 66 additions & 79 deletions
145
src/main/kotlin/fi/testaustime/plugin_intellij/services/TestaustimeApplicationService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 15 additions & 2 deletions
17
src/main/kotlin/fi/testaustime/plugin_intellij/services/TestaustimeProjectService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,45 @@ | ||
package fi.testaustime.plugin_intellij.services | ||
|
||
import com.intellij.notification.NotificationType | ||
import com.intellij.openapi.Disposable | ||
import com.intellij.openapi.project.Project | ||
import fi.testaustime.plugin_intellij.TestaustimeBundle.message | ||
import fi.testaustime.plugin_intellij.utils.ContextInformation.getFriendlyName | ||
import fi.testaustime.plugin_intellij.utils.TestaustimeNotifier | ||
|
||
|
||
class TestaustimeProjectService(private val project: Project) { | ||
class TestaustimeProjectService(private val project: Project) : Disposable { | ||
private val caretListener: CaretMoveListener | ||
|
||
init { | ||
projects.add(project); | ||
caretListener = CaretMoveListener(this); | ||
} | ||
|
||
fun terminate() { | ||
projects.remove(project); | ||
} | ||
|
||
fun isActive(): Boolean { | ||
return caretListener.isActive() | ||
} | ||
|
||
companion object { | ||
var projects: MutableList<Project> = ArrayList(); | ||
fun broadcast(tokenValid: Boolean) { | ||
for (project in projects) { | ||
if (tokenValid) { | ||
TestaustimeNotifier.notifyInfo(project, message("projectService.active.title"), | ||
message("projectService.active.message", project.name)); | ||
message("projectService.active.message", project.getFriendlyName())); | ||
} else { | ||
TestaustimeNotifier.notification(NotificationType.ERROR, project, message("projectService.invalid.title"), | ||
message("projectService.invalid.message", project.name)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun dispose() { | ||
terminate() | ||
} | ||
} |
Oops, something went wrong.