Skip to content

Commit 62f4564

Browse files
authored
[Fix] End subprocesses properly (#34)
* end subprocesses * stop hwinfo when quitting the app
1 parent 6f2f2da commit 62f4564

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

core/common/src/main/kotlin/br/com/firstsoft/core/common/reporting/LoggerUtils.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ package br.com.firstsoft.core.common.reporting
22

33
import java.io.File
44

5+
fun logException(throwable: Throwable) {
6+
File("cleanmeter.error.${System.currentTimeMillis()}.log").printWriter()
7+
.use { it.print(throwable.stackTraceToString()) }
8+
}
9+
510
fun setDefaultUncaughtExceptionHandler() {
611
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
712
try {
8-
File("cleanmeter.error.${System.currentTimeMillis()}.log").printWriter()
9-
.use { it.print(throwable.stackTraceToString()) }
13+
logException(throwable)
1014
} catch (e: Exception) {
1115
e.printStackTrace()
1216
}

core/native/src/main/kotlin/br/com/firstsoft/core/os/hwinfo/HwInfoProcessManager.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ object HwInfoProcessManager {
3333
}
3434

3535
fun stop() {
36-
process?.destroy()
36+
process?.apply {
37+
descendants().forEach(ProcessHandle::destroy)
38+
destroy()
39+
}
40+
process = null
3741
}
3842

3943
private fun overwriteSettings() {

target/server/src/main/kotlin/br/com/firstsoft/target/server/ServerMain.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ fun main() {
4646
onOverlaySettings = {
4747
overlaySettings = it
4848
},
49-
getOverlayPosition = { overlayPosition }
49+
getOverlayPosition = { overlayPosition },
50+
onApplicationExit = {
51+
HwInfoProcessManager.stop()
52+
}
5053
)
5154
}
5255
}

target/server/src/main/kotlin/br/com/firstsoft/target/server/ui/settings/SettingsWindow.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fun ApplicationScope.SettingsWindow(
2323
overlaySettings: OverlaySettings,
2424
onOverlaySettings: (OverlaySettings) -> Unit,
2525
getOverlayPosition: () -> IntOffset,
26+
onApplicationExit: () -> Unit,
2627
) {
2728
var isVisible by remember {
2829
mutableStateOf(
@@ -65,6 +66,7 @@ fun ApplicationScope.SettingsWindow(
6566
GlobalScreen.unregisterNativeHook()
6667
} catch (e: Exception) {
6768
}
69+
onApplicationExit()
6870
exitApplication()
6971
})
7072
}

0 commit comments

Comments
 (0)