אליהו הדס
08/20/2025, 10:38 AMseb
08/20/2025, 3:12 PMאליהו הדס
08/20/2025, 6:54 PMאליהו הדס
08/20/2025, 7:41 PM```fun main() {
application {
var isWindowVisible by remember { mutableStateOf(true) }
var shouldRestoreWindow by remember { mutableStateOf(false) }
TrayApp(
icon = Icons.Default.Book,
tooltip = "TrayAppDemo",
windowSize = DpSize(300.dp, 500.dp),
transparent = true,
visibleOnStart = false,
content = {
MaterialTheme {
Box(
modifier = Modifier
.clip(RoundedCornerShape(16.dp))
.fillMaxSize()
.background(MaterialTheme.colorScheme.background),
contentAlignment = Center,
) {
Text("Hello World !")
}
}
},
menu = {
Item("Open the app", onClick = {
if (!isWindowVisible) {
isWindowVisible = true
} else {
shouldRestoreWindow = true
}
})
Item("Exit", onClick = { exitApplication() })
}
)
if (isWindowVisible) {
MacOSWindowManager().showInDock()
val state = rememberWindowState()
Window(
state = state,
onCloseRequest = {
isWindowVisible = false
}) {
LaunchedEffect(shouldRestoreWindow) {
if (shouldRestoreWindow) {
state.isMinimized = false
window.toFront()
window.requestFocusInWindow()
window.requestFocus()
shouldRestoreWindow = false
}
}
Text("Compose Native Tray Demo")
}
} else {
MacOSWindowManager().setAsAccessoryApp()
}
}
}```
Colton Idle
08/22/2025, 10:10 PMColton Idle
08/22/2025, 10:11 PMseb
08/22/2025, 10:26 PMSystem.setProperty("apple.awt.UIElement", "true")
works perfectly fine for my command line program. The important thing is to call it before anything related to UI at all is ever run (i.e., before any AWT calls under the hood)seb
08/22/2025, 10:26 PMאליהו הדס
08/23/2025, 7:06 PMאליהו הדס
08/23/2025, 7:10 PMאליהו הדס
08/23/2025, 7:10 PMseb
08/23/2025, 7:11 PMאליהו הדס
08/23/2025, 7:31 PMColton Idle
08/24/2025, 1:34 PMאליהו הדס
08/24/2025, 2:48 PMColton Idle
08/24/2025, 4:57 PMאליהו הדס
08/24/2025, 4:58 PM