Skip to content

Commit 13b2ba6

Browse files
committed
refactor: replace MainScope with UIScope in multiple files
fix: filter tag content not fully displayed
1 parent 2866dcf commit 13b2ba6

File tree

22 files changed

+56
-307
lines changed

22 files changed

+56
-307
lines changed

app/src/main/kotlin/me/gegenbauer/catspy/ui/MainFrame.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package me.gegenbauer.catspy.ui
22

3-
import kotlinx.coroutines.*
3+
import kotlinx.coroutines.Dispatchers
4+
import kotlinx.coroutines.cancel
5+
import kotlinx.coroutines.launch
6+
import kotlinx.coroutines.withContext
47
import me.gegenbauer.catspy.concurrency.*
58
import me.gegenbauer.catspy.conf.MainConfSync
69
import me.gegenbauer.catspy.configuration.GlobalStrings
@@ -62,7 +65,7 @@ class MainFrame(
6265
private val globalStatus = ServiceManager.getContextService(StatusPanel::class.java)
6366
private val mainViewModel = ServiceManager.getContextService(this, MainViewModel::class.java)
6467
private val memoryStatusBar = MemoryStatusBar()
65-
private val scope = MainScope()
68+
private val scope = UIScope()
6669

6770
init {
6871
configureWindow()

app/src/main/kotlin/me/gegenbauer/catspy/ui/dialog/GThemeSettingsDialog.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package me.gegenbauer.catspy.ui.dialog
22

3-
import kotlinx.coroutines.MainScope
43
import kotlinx.coroutines.cancel
54
import kotlinx.coroutines.launch
65
import me.gegenbauer.catspy.configuration.*
76
import me.gegenbauer.catspy.file.gson
87
import me.gegenbauer.catspy.java.ext.EMPTY_STRING
98
import me.gegenbauer.catspy.concurrency.GlobalMessageManager
109
import me.gegenbauer.catspy.concurrency.Message
10+
import me.gegenbauer.catspy.concurrency.UIScope
1111
import me.gegenbauer.catspy.java.ext.copyFields
1212
import me.gegenbauer.catspy.strings.STRINGS
1313
import me.gegenbauer.catspy.strings.globalLocale
@@ -26,14 +26,15 @@ class GThemeSettingsDialog(
2626
private var tree = SettingsTree()
2727

2828
private var startSettings = SettingsManager.string
29-
private val scope = MainScope()
29+
private val scope = UIScope()
3030

3131
init {
3232
title = STRINGS.ui.preferences
3333

3434
initUI()
3535

36-
defaultCloseOperation = WindowConstants.DISPOSE_ON_CLOSE
36+
defaultCloseOperation = DISPOSE_ON_CLOSE
37+
installKeyStrokeEscClosing(this)
3738
modalityType = ModalityType.APPLICATION_MODAL
3839
pack()
3940

app/src/main/kotlin/me/gegenbauer/catspy/ui/panel/HomePanel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package me.gegenbauer.catspy.ui.panel
33
import info.clearthought.layout.TableLayout
44
import info.clearthought.layout.TableLayoutConstants.FILL
55
import info.clearthought.layout.TableLayoutConstants.PREFERRED
6-
import kotlinx.coroutines.MainScope
76
import kotlinx.coroutines.cancel
7+
import me.gegenbauer.catspy.concurrency.UIScope
88
import me.gegenbauer.catspy.context.ServiceManager
99
import me.gegenbauer.catspy.java.ext.Bundle
1010
import me.gegenbauer.catspy.log.ui.tab.DeviceLogGuidancePanel
@@ -30,7 +30,7 @@ class HomePanel : BaseTabPanel() {
3030
private val tabManager: TabManager
3131
get() = contexts.getContext(MainFrame::class.java)!!
3232
private val statusBar = ServiceManager.getContextService(StatusPanel::class.java)
33-
private val scope = MainScope()
33+
private val scope = UIScope()
3434

3535
override fun onSetup(bundle: Bundle?) {
3636
layout = TableLayout(

app/src/main/kotlin/me/gegenbauer/catspy/ui/panel/MemoryStatusBar.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package me.gegenbauer.catspy.ui.panel
22

33
import kotlinx.coroutines.Dispatchers
4-
import kotlinx.coroutines.MainScope
54
import kotlinx.coroutines.cancel
65
import kotlinx.coroutines.launch
76
import me.gegenbauer.catspy.concurrency.CPU
7+
import me.gegenbauer.catspy.concurrency.UIScope
88
import me.gegenbauer.catspy.context.*
99
import me.gegenbauer.catspy.file.GB
1010
import me.gegenbauer.catspy.file.KB
@@ -18,7 +18,7 @@ import java.awt.event.MouseEvent
1818
import javax.swing.JProgressBar
1919

2020
class MemoryStatusBar(override val contexts: Contexts = Contexts.default) : JProgressBar(), Context {
21-
private val scope = MainScope()
21+
private val scope = UIScope()
2222
private val memoryLimit by lazy {
2323
(Runtime.getRuntime().maxMemory() - MemoryMonitor.minFreeMemory).also {
2424
GLog.d(TAG, "[memoryLimit] ${it / GB} GB")

app/src/main/kotlin/me/gegenbauer/catspy/ui/panel/TabManagerPane.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package me.gegenbauer.catspy.ui.panel
22

33
import com.formdev.flatlaf.FlatClientProperties.*
44
import com.github.weisj.darklaf.iconset.AllIcons
5-
import kotlinx.coroutines.MainScope
65
import kotlinx.coroutines.cancel
76
import kotlinx.coroutines.launch
7+
import me.gegenbauer.catspy.concurrency.UIScope
88
import me.gegenbauer.catspy.context.Contexts
99
import me.gegenbauer.catspy.context.ServiceManager
1010
import me.gegenbauer.catspy.glog.GLog
@@ -17,7 +17,6 @@ import me.gegenbauer.catspy.log.serialize.toLogMetadata
1717
import me.gegenbauer.catspy.log.ui.tab.DeviceLogMainPanel
1818
import me.gegenbauer.catspy.log.ui.tab.FileLogMainPanel
1919
import me.gegenbauer.catspy.platform.currentPlatform
20-
import me.gegenbauer.catspy.script.ui.ScriptTabPanel
2120
import me.gegenbauer.catspy.strings.STRINGS
2221
import me.gegenbauer.catspy.ui.MainFrame
2322
import me.gegenbauer.catspy.ui.menu.TabSelectorPopupMenu
@@ -65,7 +64,7 @@ class TabManagerPane(override val contexts: Contexts = Contexts.default) : TabMa
6564
}
6665

6766
private val selectMenu = TabSelectorPopupMenu()
68-
private val scope = MainScope()
67+
private val scope = UIScope()
6968
private val addTabButton = JButton().apply {
7069
icon = AllIcons.Action.Add.get(TAB_ICON_SIZE, TAB_ICON_SIZE)
7170
addActionListener(createNewTabAction())

concurrency/src/main/kotlin/me/gegenbauer/catspy/concurrency/ScopeDomain.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ open class ModelScope : CoroutineScope {
5656
}
5757
}
5858

59+
class UIScope : CoroutineScope {
60+
override val coroutineContext: CoroutineContext
61+
= CoroutineName(TAG) + Dispatchers.UI + loggingExceptionHandler + SupervisorJob()
62+
63+
private companion object {
64+
private const val TAG = "UIScope"
65+
}
66+
}
67+
5968
/**
6069
* Scope of ViewModel. Use [Dispatchers.UI] as default. Its lifecycle is as long as ViewModel.
6170
*/

task/src/main/kotlin/me/gegenbauer/catspy/task/LoadProcessPackageTask.kt

Lines changed: 0 additions & 50 deletions
This file was deleted.

task/src/main/kotlin/me/gegenbauer/catspy/task/OneTimeTask.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.

task/src/main/kotlin/me/gegenbauer/catspy/task/ReadFileTask.kt

Lines changed: 0 additions & 46 deletions
This file was deleted.

ui/log/src/main/kotlin/me/gegenbauer/catspy/log/datasource/AndroidProcessFetcher.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,20 @@ class AndroidProcessFetcher(private val device: String) {
9494

9595
private suspend fun updatePidToPackageMap(reason: String) {
9696
withContext(Dispatchers.GIO) {
97-
kotlin.runCatching {
97+
runCatching {
9898
if (device.isEmpty()) {
9999
return@withContext
100100
}
101101
Log.d(TAG, "[updatePidToPackageMap] $reason, query package info from device.")
102102
val process = Runtime.getRuntime().exec("${SettingsManager.adbPath} -s $device shell ps")
103-
val reader = BufferedReader(InputStreamReader(process.inputStream))
104-
reader.forEachLine {
105-
parseLineToPidPackage(it)?.let { (pid, packageName) ->
106-
packageNameCache[pid] = packageName
103+
BufferedReader(InputStreamReader(process.inputStream)).use { reader ->
104+
reader.forEachLine {
105+
parseLineToPidPackage(it)?.let { (pid, packageName) ->
106+
packageNameCache[pid] = packageName
107+
}
107108
}
108109
}
110+
process.errorStream.bufferedReader().use { it.readText() }
109111
}.onFailure {
110112
Log.e(TAG, "[updatePidToPackageMap] failed", it)
111113
}
@@ -135,7 +137,7 @@ class AndroidProcessFetcher(private val device: String) {
135137
* adb shell "date +'%m-%d %H:%M:%S' | awk '{printf \"%s.\", \$0}'; date +'%N' | cut -c1-3"
136138
*/
137139
private fun fetchTimeOnDevice(): String {
138-
return kotlin.runCatching {
140+
return runCatching {
139141
val dateTimeProcess = Runtime.getRuntime().exec(
140142
"${SettingsManager.adbPath} -s " +
141143
"$device shell date +'%m-%d %H:%M:%S'"

0 commit comments

Comments
 (0)