Skip to content

Commit 9d4f906

Browse files
committed
Modify coroutines and updating
+ auto scroll
1 parent ee54127 commit 9d4f906

File tree

2 files changed

+30
-45
lines changed

2 files changed

+30
-45
lines changed

src/BookmarkOptions.kt

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package burp
22

3-
import kotlinx.coroutines.Dispatchers
4-
import kotlinx.coroutines.GlobalScope
5-
import kotlinx.coroutines.launch
6-
import kotlinx.coroutines.swing.Swing
73
import java.awt.FlowLayout
84
import javax.swing.*
95

@@ -27,10 +23,7 @@ class BookmarkOptions(
2723
clearButton.addActionListener { clearBookmarks() }
2824
searchBar.addActionListener { searchBookmarks() }
2925
searchButton.addActionListener { searchBookmarks() }
30-
resetButton.addActionListener {
31-
searchBar.text = ""
32-
resetSearch()
33-
}
26+
resetButton.addActionListener { resetSearch() }
3427
searchPanel.add(searchLabel)
3528
searchPanel.add(searchBar)
3629
searchPanel.add(searchButton)
@@ -43,44 +36,34 @@ class BookmarkOptions(
4336
}
4437

4538
private fun loadHighlightedRequests() {
46-
GlobalScope.launch {
47-
val bookmarks = bookmarksPanel.bookmarks
48-
val highlightedProxyHistory = callbacks.proxyHistory.filter { it.highlight != null }
49-
val bookmarkRequests = bookmarks.map { callbacks.helpers.bytesToString(it.requestResponse.request) }
50-
val bookmarksToAdd = highlightedProxyHistory
51-
.filter { !bookmarkRequests.contains(callbacks.helpers.bytesToString(it.request)) }.toTypedArray()
52-
launch(Dispatchers.Swing) {
53-
bookmarksPanel.addBookmark(bookmarksToAdd)
54-
bookmarksPanel.model.filteredBookmarks()
55-
}
56-
}
39+
val bookmarks = bookmarksPanel.bookmarks
40+
val highlightedProxyHistory = callbacks.proxyHistory.filter { it.highlight != null }
41+
val bookmarkRequests = bookmarks.map { callbacks.helpers.bytesToString(it.requestResponse.request) }
42+
val bookmarksToAdd = highlightedProxyHistory
43+
.filter { !bookmarkRequests.contains(callbacks.helpers.bytesToString(it.request)) }.toTypedArray()
44+
bookmarksPanel.addBookmark(bookmarksToAdd)
5745
}
5846

5947
private fun searchBookmarks() {
6048
val searchText = searchBar.text
6149
val bookmarks = this.bookmarksPanel.bookmarks
6250
if (searchText.isNotEmpty()) {
63-
GlobalScope.launch {
64-
val filteredBookmarks = bookmarks
65-
.filter {
66-
callbacks.helpers.bytesToString(it.requestResponse.request).contains(searchText) ||
67-
callbacks.helpers.bytesToString(it.requestResponse.response).contains(searchText)
68-
}.toMutableList()
69-
launch(Dispatchers.Swing) {
70-
bookmarksPanel.model.filteredBookmarks(filteredBookmarks)
71-
}
72-
}
73-
} else {
74-
bookmarksPanel.model.filteredBookmarks()
51+
val filteredBookmarks = bookmarks
52+
.filter {
53+
callbacks.helpers.bytesToString(it.requestResponse.request).contains(searchText) ||
54+
callbacks.helpers.bytesToString(it.requestResponse.response).contains(searchText)
55+
}.toMutableList()
56+
bookmarksPanel.model.refreshBookmarks(filteredBookmarks)
7557
}
7658
}
7759

7860
private fun resetSearch() {
79-
bookmarksPanel.model.filteredBookmarks()
61+
searchBar.text = ""
62+
bookmarksPanel.model.refreshBookmarks()
8063
}
8164

8265
private fun clearBookmarks() {
8366
bookmarksPanel.model.bookmarks.clear()
84-
bookmarksPanel.model.filteredBookmarks()
67+
bookmarksPanel.model.refreshBookmarks()
8568
}
8669
}

src/BookmarkTab.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import kotlinx.coroutines.Dispatchers
44
import kotlinx.coroutines.GlobalScope
55
import kotlinx.coroutines.launch
66
import kotlinx.coroutines.swing.Swing
7+
import kotlinx.coroutines.withContext
78
import java.awt.FlowLayout
89
import java.net.URL
910
import java.time.LocalDateTime
@@ -144,6 +145,10 @@ class BookmarksPanel(private val callbacks: IBurpExtenderCallbacks) {
144145
requestResponse.highlight = "magenta"
145146
requestResponse.comment = "[^]"
146147
}
148+
149+
SwingUtilities.invokeLater {
150+
table.scrollRectToVisible(table.getCellRect(table.rowCount - 1, table.columnCount, true))
151+
}
147152
}
148153

149154
private fun getTitle(response: ByteArray?): String {
@@ -158,11 +163,10 @@ class BookmarksPanel(private val callbacks: IBurpExtenderCallbacks) {
158163
private fun repeatRequest() {
159164
GlobalScope.launch(Dispatchers.IO) {
160165
val requestResponse = callbacks.makeHttpRequest(messageEditor.httpService, requestViewer?.message)
161-
responseViewer?.setMessage(requestResponse.response, false)
162-
if (repeatInTable.isSelected) {
163-
launch(Dispatchers.Swing) {
164-
createBookmark(requestResponse, true, false)
165-
model.filteredBookmarks()
166+
withContext(Dispatchers.Swing) {
167+
responseViewer?.setMessage(requestResponse.response, false)
168+
if (repeatInTable.isSelected) {
169+
createBookmark(requestResponse, repeated = true, proxyHistory = false)
166170
}
167171
}
168172
}
@@ -250,23 +254,21 @@ class BookmarksModel : AbstractTableModel() {
250254

251255
fun addBookmark(bookmark: Bookmark) {
252256
bookmarks.add(bookmark)
253-
filteredBookmarks()
254-
fireTableDataChanged()
257+
displayedBookmarks = bookmarks
258+
fireTableRowsInserted(displayedBookmarks.lastIndex, displayedBookmarks.lastIndex)
255259
}
256260

257261
fun removeBookmarks(selectedBookmarks: MutableList<Bookmark>) {
258262
bookmarks.removeAll(selectedBookmarks)
259-
filteredBookmarks()
260-
fireTableDataChanged()
263+
refreshBookmarks()
261264
}
262265

263266
fun clearBookmarks() {
264267
bookmarks.clear()
265-
filteredBookmarks()
266-
fireTableDataChanged()
268+
refreshBookmarks()
267269
}
268270

269-
fun filteredBookmarks(updatedBookmarks: MutableList<Bookmark> = bookmarks) {
271+
fun refreshBookmarks(updatedBookmarks: MutableList<Bookmark> = bookmarks) {
270272
displayedBookmarks = updatedBookmarks
271273
fireTableDataChanged()
272274
}

0 commit comments

Comments
 (0)