Skip to content

support for trae cn #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
Expand Down