diff --git a/src/main/kotlin/com/github/qczone/switch2cursor/actions/OpenFileInCursorAction.kt b/src/main/kotlin/com/github/qczone/switch2cursor/actions/OpenFileInCursorAction.kt index bae398d..c8ab4c9 100644 --- a/src/main/kotlin/com/github/qczone/switch2cursor/actions/OpenFileInCursorAction.kt +++ b/src/main/kotlin/com/github/qczone/switch2cursor/actions/OpenFileInCursorAction.kt @@ -54,15 +54,15 @@ class OpenFileInCursorAction : AnAction() { ${ex.message} Please check: - 1. Cursor path is correctly configured in Settings > Tools > Switch2Cursor - 2. Cursor is properly installed on your system - 3. The configured path points to a valid Cursor executable + 1. Cursor/Trae path is correctly configured in Settings > Tools > Switch2Cursor + 2. Cursor/Trae is properly installed on your system + 3. The configured path points to a valid Cursor/Trae executable """.trimIndent(), "Error" ) } - WindowUtils.activeWindow() + WindowUtils.activeWindow(cursorPath) } override fun update(e: AnActionEvent) { diff --git a/src/main/kotlin/com/github/qczone/switch2cursor/actions/OpenProjectInCursorAction.kt b/src/main/kotlin/com/github/qczone/switch2cursor/actions/OpenProjectInCursorAction.kt index a386939..d298863 100644 --- a/src/main/kotlin/com/github/qczone/switch2cursor/actions/OpenProjectInCursorAction.kt +++ b/src/main/kotlin/com/github/qczone/switch2cursor/actions/OpenProjectInCursorAction.kt @@ -46,15 +46,15 @@ class OpenProjectInCursorAction : AnAction() { ${ex.message} Please check: - 1. Cursor path is correctly configured in Settings > Tools > Switch2Cursor - 2. Cursor is properly installed on your system - 3. The configured path points to a valid Cursor executable + 1. Cursor/Trae path is correctly configured in Settings > Tools > Switch2Cursor + 2. Cursor/Trae is properly installed on your system + 3. The configured path points to a valid Cursor/Trae executable """.trimIndent(), "Error" ) } - WindowUtils.activeWindow() + WindowUtils.activeWindow(cursorPath) } override fun update(e: AnActionEvent) { diff --git a/src/main/kotlin/com/github/qczone/switch2cursor/settings/AppSettingsConfigurable.kt b/src/main/kotlin/com/github/qczone/switch2cursor/settings/AppSettingsConfigurable.kt index f9612a7..108758f 100644 --- a/src/main/kotlin/com/github/qczone/switch2cursor/settings/AppSettingsConfigurable.kt +++ b/src/main/kotlin/com/github/qczone/switch2cursor/settings/AppSettingsConfigurable.kt @@ -10,7 +10,7 @@ import com.intellij.util.ui.FormBuilder class AppSettingsConfigurable : Configurable { private var mySettingsComponent: AppSettingsComponent? = null - override fun getDisplayName(): String = "Open In Cursor" + override fun getDisplayName(): String = "Open In Cursor/Trae" override fun createComponent(): JComponent { mySettingsComponent = AppSettingsComponent() @@ -43,7 +43,7 @@ class AppSettingsComponent { init { panel = FormBuilder.createFormBuilder() - .addLabeledComponent(JBLabel("Cursor Path: "), cursorPathText, 1, false) + .addLabeledComponent(JBLabel("Cursor/Trae Path: "), cursorPathText, 1, false) .addComponentFillVertically(JPanel(), 0) .panel } diff --git a/src/main/kotlin/com/github/qczone/switch2cursor/utils/WindowUtils.kt b/src/main/kotlin/com/github/qczone/switch2cursor/utils/WindowUtils.kt index 86c8268..c9dd5ef 100644 --- a/src/main/kotlin/com/github/qczone/switch2cursor/utils/WindowUtils.kt +++ b/src/main/kotlin/com/github/qczone/switch2cursor/utils/WindowUtils.kt @@ -1,30 +1,38 @@ package com.github.qczone.switch2cursor.utils -import com.intellij.openapi.util.SystemInfo import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.util.SystemInfo object WindowUtils { private val logger = Logger.getInstance(WindowUtils::class.java) - fun activeWindow() { + fun activeWindow(cursorPath: String) { if (!SystemInfo.isWindows) { return } + val processName: String + val containTrae = cursorPath.contains("Trae") + if (containTrae) { + processName = "Trae CN" + } else { + processName = "Cursor" + } try { - val command = """Get-Process | Where-Object { ${'$'}_.ProcessName -eq '"Cursor"' -and ${'$'}_.MainWindowTitle -match '"Cursor"' } | Sort-Object { ${'$'}_.StartTime } -Descending | Select-Object -First 1 | ForEach-Object { (New-Object -ComObject WScript.Shell).AppActivate(${'$'}_.Id) }""" + val command = + """Get-Process | Where-Object { ${'$'}_.ProcessName -eq '"$processName"' -and ${'$'}_.MainWindowTitle -match '"$processName"' } | Sort-Object { ${'$'}_.StartTime } -Descending | Select-Object -First 1 | ForEach-Object { (New-Object -ComObject WScript.Shell).AppActivate(${'$'}_.Id) }""" logger.info("Executing PowerShell command: $command") - + val processBuilder = ProcessBuilder("powershell", "-command", command) processBuilder.redirectErrorStream(true) - + val process = processBuilder.start() val output = process.inputStream.bufferedReader().use { it.readText() } logger.info("Command output: $output") - + val exitCode = process.waitFor() logger.info("Command completed with exit code: $exitCode") - + if (exitCode != 0) { logger.error("Command failed with exit code: $exitCode") }