fix window activation

This commit is contained in:
Thomas Boksberger committed 2026-04-03 12:53:56 +02:00
1 parent cf500a75d1
commit aee88b8272
4 files changed
+26 -3

No files matched your search

+19
View File
@@ -61,14 +61,33 @@ fun main() {
alwaysOnTop = true,
undecorated = false,
) {
LaunchedEffect(isVisible) {
if (isVisible) {
activateMacOsApp()
window.toFront()
window.requestFocus()
}
}
TaskWindow(
client = client,
isVisible = isVisible,
onDismiss = { isVisible = false }
)
}
}
}
private fun activateMacOsApp() {
if (!System.getProperty("os.name").contains("Mac", ignoreCase = true)) return
try {
val appClass = Class.forName("com.apple.eawt.Application")
val app = appClass.getMethod("getApplication").invoke(null)
appClass.getMethod("requestForeground", Boolean::class.java).invoke(app, true)
} catch (e: Exception) {
logger.error("Failed to activate macOS app", e)
}
}
private fun setupSystemTray(onShow: () -> Unit, onExit: () -> Unit) {
if (!SystemTray.isSupported()) return
@@ -13,7 +13,7 @@ import ch.ergon.anytask.api.AnyTypeApi
import kotlinx.coroutines.launch
@Composable
fun TaskWindow(client: AnyTypeApi, onDismiss: () -> Unit) {
fun TaskWindow(client: AnyTypeApi, isVisible: Boolean, onDismiss: () -> Unit) {
val scope = rememberCoroutineScope()
var title by remember { mutableStateOf("") }
var details by remember { mutableStateOf("") }
@@ -43,7 +43,7 @@ fun TaskWindow(client: AnyTypeApi, onDismiss: () -> Unit) {
Column(
modifier = Modifier
.padding(24.dp)
.onKeyEvent { event ->
.onPreviewKeyEvent { event ->
when {
event.type == KeyEventType.KeyDown && event.key == Key.Escape -> {
onDismiss(); true
@@ -96,5 +96,5 @@ fun TaskWindow(client: AnyTypeApi, onDismiss: () -> Unit) {
}
}
LaunchedEffect(Unit) { focusRequester.requestFocus() }
LaunchedEffect(isVisible) { if (isVisible) focusRequester.requestFocus() }
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.