Skip to content

Commit

Permalink
feat: finish startup check
Browse files Browse the repository at this point in the history
  • Loading branch information
MC-XiaoHei committed Jun 1, 2024
1 parent ddee296 commit a74cd16
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
package cn.xor7.xiaohei.leavesknife.activities

import cn.xor7.xiaohei.leavesknife.services.LEAVESKNIFE_CONFIG_FILE
import cn.xor7.xiaohei.leavesknife.services.leavesknifeConfigService
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.startup.ProjectActivity
import org.gradle.tooling.GradleConnector
import org.gradle.tooling.model.idea.IdeaProject
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths

class ProjectStartupActivity : ProjectActivity {
override suspend fun execute(project: Project) {
val projectDir = project.basePath ?: return
GradleConnector.newConnector()
.forProjectDirectory(File(projectDir))
.connect().use { connection ->
val ideaProject: IdeaProject = connection.getModel(IdeaProject::class.java)
project.leavesknifeConfigService.enablePlugin =
ideaProject.modules.any { it.name == "paper-api-generator" }
project.guessProjectDir()?.let {
if (Files.exists(
Paths.get(
it.path,
LEAVESKNIFE_CONFIG_FILE
)
)
) {
project.leavesknifeConfigService.enablePlugin = true
return@let
}
GradleConnector.newConnector()
.forProjectDirectory(File(it.path))
.connect().use { connection ->
val ideaProject: IdeaProject = connection.getModel(IdeaProject::class.java)
if (ideaProject.modules.any { it.name == "paper-api-generator" }) {

Check notice on line 31 in src/main/kotlin/cn/xor7/xiaohei/leavesknife/activities/ProjectStartupActivity.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nested lambda has shadowed implicit parameter

Implicit parameter 'it' of enclosing lambda is shadowed
// project.leavesknifeConfigService.enablePlugin = true
// TODO: 提示用户是否启用插件
return@let
}
}
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ class GradleTaskManager : GradleTaskManagerExtension {
return super.executeTasks(id, taskNames, projectPath, settings, jvmParametersSetup, listener)
}

override fun cancelTask(id: ExternalSystemTaskId, listener: ExternalSystemTaskNotificationListener): Boolean {
return false
}
override fun cancelTask(id: ExternalSystemTaskId, listener: ExternalSystemTaskNotificationListener): Boolean = false
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package cn.xor7.xiaohei.leavesknife.services

import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import java.nio.file.Files
import java.nio.file.Paths
import com.intellij.openapi.wm.ToolWindowManager

const val LEAVESKNIFE_CONFIG_FILE = "leavesknife.properties"

@Service(Service.Level.PROJECT)
class ProjectConfigService(project: Project) {
class ProjectConfigService(private val project: Project) {
var enablePlugin = false

init {
project.guessProjectDir()?.let {
enablePlugin = Files.exists(
Paths.get(
it.path,
LEAVESKNIFE_CONFIG_FILE
)
)
set(value) {
field = value
println("enablePlugin: $value")
runInEdt {
ToolWindowManager
.getInstance(project)
.getToolWindow("Patches")
?.isAvailable = value
}
}
}
}

val Project.leavesknifeConfigService: ProjectConfigService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cn.xor7.xiaohei.leavesknife.toolWindow

import cn.xor7.xiaohei.leavesknife.services.ProjectConfigService
import cn.xor7.xiaohei.leavesknife.services.leavesknifeConfigService
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
Expand All @@ -20,15 +19,15 @@ class PatchesToolWindowFactory : ToolWindowFactory {
toolWindow.contentManager.addContent(content)
}

override suspend fun isApplicableAsync(project: Project): Boolean =
project.leavesknifeConfigService.enablePlugin
override suspend fun isApplicableAsync(project: Project): Boolean = true

override fun shouldBeAvailable(project: Project) = false

class ServerPatchesToolWindow(toolWindow: ToolWindow) {
private val service = toolWindow.project.service<ProjectConfigService>()

Check warning on line 27 in src/main/kotlin/cn/xor7/xiaohei/leavesknife/toolWindow/PatchesToolWindowFactory.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "service" is never used

fun getContent() = JBPanel<JBPanel<*>>().apply {

}
}
}
5 changes: 1 addition & 4 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin>
<id>cn.xor7.xiaohei.leavesknife</id>
<name>LeavesKnife</name>
Expand All @@ -15,16 +14,14 @@
id="Patches"
anchor="right"
icon="AllIcons.Vcs.Patch"
canCloseContents="true"
/>
</extensions>

<extensions defaultExtensionNs="org.jetbrains.plugins.gradle">
<projectResolve implementation="cn.xor7.xiaohei.leavesknife.services.GradleProjectResolver"/>
<taskManager implementation="cn.xor7.xiaohei.leavesknife.services.GradleTaskManager"/>
</extensions>

<applicationListeners>
<listener class="cn.xor7.xiaohei.leavesknife.listeners.MyApplicationActivationListener"
topic="com.intellij.openapi.application.ApplicationActivationListener"/>
</applicationListeners>
</idea-plugin>
39 changes: 0 additions & 39 deletions src/test/kotlin/cn/xor7/xiaohei/leavesknife/MyPluginTest.kt

This file was deleted.

0 comments on commit a74cd16

Please sign in to comment.