Create a Run like UI with background task
I'm working on a plugin which outputs logs. I want these logs to be accessible from a text field something like Run/Debug has in the ToolWindow. Is there a way I can reuse that text field? So which class do I have to extend to modify the original Run/Debug log panel.
The other thing I want is this text box to be refreshed even if it is not visible, other plugins are opened in the ToolWindow etc. For this I have tried to run my program in a background thread (so it does not block the UI thread), and output the logs like this:
I have started a new thread with IntelliJ API:
ApplicationManager.getApplication().executeOnPooledThread { dialogLogWriter.display() }
And called the method again, until the tab it is running in is closed:
fun tailLogs() {
if (shouldRun) {
fetchLogs();
Thread.sleep(1000)
ProgressManager
.getInstance()
.runInReadActionWithWriteActionPriority({ tailLogs() },null)
}
}
The problem is when I switch tabs in the plugin it cancels the runInReadActionWithWriteActionPriority and does not resume. How to make sure it does not stop my background process.
Also is there a cleaner way (dedicated way in IntelliJ) to schedule the function call to 1 second instead of Thread.sleep()?
请先登录再写评论。