Skip to content

Commit

Permalink
Use client sets to manage clients
Browse files Browse the repository at this point in the history
A better habit makes it easier to understand the codes
  • Loading branch information
JingMatrix committed Aug 17, 2023
1 parent e32fc2c commit 0a5dbbb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/org/matrix/chromext/Chrome.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ object Chrome {
val lastClient = cspBypassed.find { it.tabId == tabId }
var client = lastClient ?: DevToolClient(tabId)
if (client.isClosed()) {
cspBypassed.remove(client)
hitDevTools().close()
client = DevToolClient(tabId)
}
Expand All @@ -103,6 +104,8 @@ object Chrome {
client.command(null, "Page.setBypassCSP", JSONObject().put("enabled", bypassCSP))
if (bypassCSP) {
cspBypassed.add(client)
} else {
cspBypassed.remove(client)
}
}
if (!bypassCSP) client.close()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/matrix/chromext/Listener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ object Listener {
}
thread {
target?.close()
devSessions.remove(target)
hitDevTools().close()
target = DevToolClient(targetTabId)
if (!target!!.isClosed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.security.SecureRandom
import kotlin.experimental.xor
import org.json.JSONObject
import org.matrix.chromext.Chrome
import org.matrix.chromext.Listener
import org.matrix.chromext.hook.UserScriptHook
import org.matrix.chromext.hook.WebViewHook
import org.matrix.chromext.utils.Log
Expand Down Expand Up @@ -43,10 +42,6 @@ class DevToolClient(tabId: String) : LocalSocket() {

override fun close() {
super.close()
if (!mClosed) {
Chrome.cspBypassed.remove(this)
Listener.devSessions.remove(this)
}
mClosed = true
}

Expand Down

0 comments on commit 0a5dbbb

Please sign in to comment.