fix window activation
This commit is contained in:
1 parent
cf500a75d1
commit
aee88b8272
4 files changed
+26
-3
No files matched your search
@@ -37,6 +37,7 @@ Always stage newly created files that permanently belong to the project with `gi
|
|||||||
- One class per file — file name matches the class name.
|
- One class per file — file name matches the class name.
|
||||||
- No wildcard imports (`import foo.*`).
|
- No wildcard imports (`import foo.*`).
|
||||||
- Code, comments, and documentation in English.
|
- Code, comments, and documentation in English.
|
||||||
|
- Exceptions: always handle or at least log them (with full stacktrace).
|
||||||
|
|
||||||
## macOS Notes
|
## macOS Notes
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ compose.desktop {
|
|||||||
application {
|
application {
|
||||||
mainClass = "ch.ergon.anytask.MainKt"
|
mainClass = "ch.ergon.anytask.MainKt"
|
||||||
|
|
||||||
|
// Allow access to AWT Classes to control the window
|
||||||
|
jvmArgs("--add-opens", "java.desktop/com.apple.eawt=ALL-UNNAMED")
|
||||||
|
|
||||||
nativeDistributions {
|
nativeDistributions {
|
||||||
targetFormats(TargetFormat.Dmg)
|
targetFormats(TargetFormat.Dmg)
|
||||||
packageName = "AnyTask"
|
packageName = "AnyTask"
|
||||||
|
|||||||
@@ -61,14 +61,33 @@ fun main() {
|
|||||||
alwaysOnTop = true,
|
alwaysOnTop = true,
|
||||||
undecorated = false,
|
undecorated = false,
|
||||||
) {
|
) {
|
||||||
|
LaunchedEffect(isVisible) {
|
||||||
|
if (isVisible) {
|
||||||
|
activateMacOsApp()
|
||||||
|
window.toFront()
|
||||||
|
window.requestFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
TaskWindow(
|
TaskWindow(
|
||||||
client = client,
|
client = client,
|
||||||
|
isVisible = isVisible,
|
||||||
onDismiss = { isVisible = false }
|
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) {
|
private fun setupSystemTray(onShow: () -> Unit, onExit: () -> Unit) {
|
||||||
if (!SystemTray.isSupported()) return
|
if (!SystemTray.isSupported()) return
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import ch.ergon.anytask.api.AnyTypeApi
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TaskWindow(client: AnyTypeApi, onDismiss: () -> Unit) {
|
fun TaskWindow(client: AnyTypeApi, isVisible: Boolean, onDismiss: () -> Unit) {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
var title by remember { mutableStateOf("") }
|
var title by remember { mutableStateOf("") }
|
||||||
var details by remember { mutableStateOf("") }
|
var details by remember { mutableStateOf("") }
|
||||||
@@ -43,7 +43,7 @@ fun TaskWindow(client: AnyTypeApi, onDismiss: () -> Unit) {
|
|||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(24.dp)
|
.padding(24.dp)
|
||||||
.onKeyEvent { event ->
|
.onPreviewKeyEvent { event ->
|
||||||
when {
|
when {
|
||||||
event.type == KeyEventType.KeyDown && event.key == Key.Escape -> {
|
event.type == KeyEventType.KeyDown && event.key == Key.Escape -> {
|
||||||
onDismiss(); true
|
onDismiss(); true
|
||||||
@@ -96,5 +96,5 @@ fun TaskWindow(client: AnyTypeApi, onDismiss: () -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(Unit) { focusRequester.requestFocus() }
|
LaunchedEffect(isVisible) { if (isVisible) focusRequester.requestFocus() }
|
||||||
}
|
}
|
||||||