Hi everyone, can someone know how I can make an wi...
# compose-desktop
u
Hi everyone, can someone know how I can make an window invisible for the dock on macOS? thank you
s
🙏 1
u
it's not work even with a jdialog
i've succed with jna ! it's for my new api TrayApp 🙂
```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()
}
}
}```
🎉 1
c
love it!
need to see how this lines up with some investigation i did into this a few months ago when i was working on tray based apps. i remember the hardest thing for me to get was to prevent my app from showing in the app switcher (super + tab) https://dev.to/coltonidle/compose-for-desktop-window-tricks-55mf
s
Fwiw calling
System.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)
No need to bring in JNA
u
@seb Yes I tried this solution but it does not suit me, because I want to be able to display a window that displays an icon in the dock but the window of my tray does not display one, I had to manage this dynamically, so I was forced to do this with jna
👍 1
you can check my work in the dev branch of compose native tray https://github.com/kdroidFilter/ComposeNativeTray/tree/dev
s
Thanks for sharing :)
👍 1
u
@seb Thank you for Jewel🤩
c
"I want to be able to display a window that displays an icon in the dock but the window of my tray does not display one" Can you rephrase that? i dont think i understand.
u
@Colton Idle If you pay attention in the video, there are 2 windows, the main app and the companion app. I don't want to display the icon in the dock when only the companion app window is visible.
c
ohhhhhh okay. thanks for the explainer
👍 1
u
it's work too on windows and linux