-
Notifications
You must be signed in to change notification settings - Fork 134
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 #1730 from JetBrains/feature/debug-dialog
Improve "Attach to Unity Process" dialog
- Loading branch information
Showing
12 changed files
with
513 additions
and
228 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
20 changes: 20 additions & 0 deletions
20
...r/src/main/kotlin/com/jetbrains/rider/plugins/unity/run/UnityDebuggableProcessListener.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,20 @@ | ||
package com.jetbrains.rider.plugins.unity.run | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.jetbrains.rd.util.lifetime.Lifetime | ||
import com.jetbrains.rd.util.lifetime.onTermination | ||
|
||
class UnityDebuggableProcessListener(project: Project, lifetime: Lifetime, | ||
onProcessAdded: (UnityProcess) -> Unit, | ||
onProcessRemoved: (UnityProcess) -> Unit) { | ||
|
||
private val editorListener: UnityEditorListener = UnityEditorListener(project, onProcessAdded, onProcessRemoved) | ||
private val playerListener: UnityPlayerListener = UnityPlayerListener(onProcessAdded, onProcessRemoved) | ||
|
||
init { | ||
lifetime.onTermination { | ||
editorListener.stop() | ||
playerListener.stop() | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/run/UnityEditorListener.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,71 @@ | ||
package com.jetbrains.rider.plugins.unity.run | ||
|
||
import com.intellij.execution.process.OSProcessUtil | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.project.Project | ||
import java.util.* | ||
|
||
class UnityEditorListener(private val project: Project, | ||
private val onEditorAdded: (UnityProcess) -> Unit, | ||
private val onEditorRemoved: (UnityProcess) -> Unit) { | ||
|
||
companion object { | ||
private val logger = Logger.getInstance(UnityEditorListener::class.java) | ||
} | ||
|
||
// Refresh once a second | ||
private val refreshPeriod: Long = 1000 | ||
private val editorProcesses = mutableMapOf<Int, UnityLocalProcess>() | ||
|
||
private val refreshTimer: Timer | ||
|
||
init { | ||
refreshTimer = kotlin.concurrent.timer("Listen for Unity Editor processes", true, 0L, refreshPeriod) { | ||
refreshUnityEditorProcesses() | ||
} | ||
} | ||
|
||
fun stop() { | ||
refreshTimer.cancel() | ||
} | ||
|
||
private fun refreshUnityEditorProcesses() { | ||
val start = System.currentTimeMillis() | ||
logger.trace("Refreshing local editor processes...") | ||
|
||
val processes = OSProcessUtil.getProcessList().filter { | ||
UnityRunUtil.isUnityEditorProcess(it) | ||
} | ||
|
||
editorProcesses.keys.filterNot { existingEditorPid -> | ||
processes.any { p -> p.pid == existingEditorPid } | ||
}.forEach { p -> | ||
editorProcesses[p]?.let { | ||
logger.trace("Removing old Unity editor ${it.displayName}:${it.pid}") | ||
onEditorRemoved(it) | ||
} | ||
} | ||
|
||
val newProcesses = processes.filter { !editorProcesses.containsKey(it.pid) } | ||
val unityProcessInfoMap = UnityRunUtil.getAllUnityProcessInfo(newProcesses, project) | ||
newProcesses.forEach { processInfo -> | ||
val unityProcessInfo = unityProcessInfoMap[processInfo.pid] | ||
val editorProcess = if (!unityProcessInfo?.roleName.isNullOrEmpty()) { | ||
UnityEditorHelper(processInfo.executableName, unityProcessInfo?.roleName!!, processInfo.pid, unityProcessInfo.projectName) | ||
} | ||
else { | ||
UnityEditor(processInfo.executableName, processInfo.pid, unityProcessInfo?.projectName) | ||
} | ||
|
||
logger.trace("Adding Unity editor process ${editorProcess.displayName}:${editorProcess.pid}") | ||
|
||
editorProcesses[processInfo.pid] = editorProcess | ||
onEditorAdded(editorProcess) | ||
} | ||
|
||
if (logger.isTraceEnabled) { | ||
val duration = System.currentTimeMillis() - start | ||
logger.trace("Finished refreshing local editor processes. Took ${duration}ms") | ||
} | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/run/UnityPlayer.kt
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.