Migrate from ComposeNativeTray
Move an app from the ComposeNativeTray library to the Nucleus tray and tray-app modules. Swap the Maven coordinates and the imports, and review the few API and behavior changes.
Move an app from the ComposeNativeTray library (composenativetray and composenativetray-app)
to the Nucleus tray and tray-app modules. For most apps it is a dependency swap and a
search-and-replace of the imports: the Tray composables, the menu DSL and TrayApp keep their
signatures.
ComposeNativeTray is not dead
Its code moved into the Nucleus repository. Bug fixes and new tray features land in Nucleus, in
the tray and tray-app modules, under the Nucleus version.
Why the code moved
ComposeNativeTray already depended on Nucleus: composenativetray on core-runtime and
darkmode-detector, and TrayApp on nucleus-application and the window runtime. Each Nucleus
release meant a matching tray release, from a second repository with its own CI.
In the Nucleus repository, the tray, the windows, the packaging and the other modules are built, tested and released together:
- One version.
nucleus.trayandnucleus.tray-appalways match thenucleus-applicationand window runtime you use. - One CI pipeline. Each pull request runs the Linux tray torture suites (seeded menu fuzzing,
many trays at once, panel restarts, disposal races, leaked threads and bus names) and the
TrayAppend-to-end tests against a real Nucleus application under a headless X server. The same kind of suites cover Windows and macOS (./gradlew :tray:teston those systems), and a local suite checks the tray against GNOME's real AppIndicator host in a headless GNOME Shell. - The same rules as the rest of Nucleus: JNI only,
java.util.logging, GraalVM metadata in the JAR, and a public API checked for binary compatibility.
These suites found and fixed bugs in the old backends, listed in Behavior changes.
You don't need the whole framework
Nucleus is modular: each module is a separate artifact with its own small set of dependencies.
nucleus.tray brings only core-runtime and darkmode-detector, not the window runtime and not
nucleusApplication: a Compose Desktop app keeps its own application { } and its own windows and
adds a tray, nothing more. Only TrayApp asks for more, because its popup is a window: it runs in
a nucleusApplication.
Before you start
- Find your ComposeNativeTray version. This page covers 2.1.x, the last line. The import and
TrayApptables also list what changed from 2.0.x and 1.x. - Use Compose Multiplatform 1.13 or later and JDK 17 or later, as Nucleus 3.0 requires.
- If you use
TrayApp, your app moves to Nucleus 3.0 at the same time, sincetray-appbringsnucleus-application3.0. Read Migrate from Nucleus 2.x for the application and window changes. A JetBrains Compose Desktop app reads Migrate from JetBrains Compose Desktop.
Replace the dependency
| ComposeNativeTray | Nucleus |
|---|---|
dev.nucleusframework:composenativetray (2.x) | dev.nucleusframework:nucleus.tray |
dev.nucleusframework:composenativetray-app (2.1.x) | dev.nucleusframework:nucleus.tray-app |
io.github.kdroidfilter:composenativetray (1.x) | dev.nucleusframework:nucleus.tray, plus nucleus.tray-app for TrayApp |
dependencies {
- implementation("dev.nucleusframework:composenativetray:<tray-version>")
- implementation("dev.nucleusframework:composenativetray-app:<tray-version>")
+ implementation("dev.nucleusframework:nucleus.tray:3.0.0")
+ // Only if you use TrayApp
+ implementation("dev.nucleusframework:nucleus.tray-app:3.0.0")
}<version> is the Nucleus version, 3.0.0 or later. tray-app brings tray and
nucleus-application as API dependencies, so tray-app alone is enough for an app with a
TrayApp.
tray depends on neither nucleus-application nor the window runtime, so a daemon or an app
without Nucleus windows can use it. Inside a Nucleus app, call Tray from nucleusApplication { }:
Compose Desktop's AWT Window and Tray do not work there.
Replace the imports
The .api and .impl segments are gone, composenativetray becomes tray, and trayapp
becomes tray.app:
| ComposeNativeTray | Nucleus |
|---|---|
dev.nucleusframework.composenativetray.tray.api.Tray | dev.nucleusframework.tray.Tray |
dev.nucleusframework.composenativetray.menu.api.* (TrayMenuBuilder, ComposableTrayMenuScope, KeyShortcut, Key) | dev.nucleusframework.tray.menu.* |
dev.nucleusframework.composenativetray.utils.* (IconRenderProperties, isMenuBarInDarkMode) | dev.nucleusframework.tray.utils.* |
dev.nucleusframework.composenativetray.trayapp.* (TrayApp, TrayAppState, rememberTrayAppState, TrayWindowDismissMode, TrayPosition, getTrayPosition, getTrayWindowPosition) | dev.nucleusframework.tray.app.* |
2.0.x: …composenativetray.tray.api.TrayApp, TrayAppState, TrayWindowDismissMode | dev.nucleusframework.tray.app.* |
2.0.x: …composenativetray.utils.TrayPosition, getTrayPosition, getTrayWindowPosition | dev.nucleusframework.tray.app.* |
1.x: com.kdroid.composetray.tray.api.Tray | dev.nucleusframework.tray.Tray |
1.x: com.kdroid.composetray.tray.api.TrayApp, TrayAppState, TrayWindowDismissMode | dev.nucleusframework.tray.app.* |
1.x: com.kdroid.composetray.menu.api.* | dev.nucleusframework.tray.menu.* |
1.x: com.kdroid.composetray.utils.TrayPosition, getTrayPosition, getTrayWindowPosition | dev.nucleusframework.tray.app.* |
1.x: com.kdroid.composetray.utils.IconRenderProperties, isMenuBarInDarkMode | dev.nucleusframework.tray.utils.* |
-import dev.nucleusframework.composenativetray.tray.api.Tray
-import dev.nucleusframework.composenativetray.menu.api.KeyShortcut
-import dev.nucleusframework.composenativetray.utils.isMenuBarInDarkMode
-import dev.nucleusframework.composenativetray.trayapp.TrayApp
-import dev.nucleusframework.composenativetray.trayapp.rememberTrayAppState
+import dev.nucleusframework.tray.Tray
+import dev.nucleusframework.tray.menu.KeyShortcut
+import dev.nucleusframework.tray.utils.isMenuBarInDarkMode
+import dev.nucleusframework.tray.app.TrayApp
+import dev.nucleusframework.tray.app.rememberTrayAppStatePort the code
Coming from 2.1.x, the code itself does not change. Every Tray overload keeps its parameters:
icon as an ImageVector (with tint), a Painter or a DrawableResource, iconContent,
windowsIcon with macLinuxIcon, then iconRenderProperties, tooltip, primaryAction,
onMenuOpened and the menu. Item, CheckableItem, SubMenu, Divider and KeyShortcut
take the same arguments.
A tray with a menu
-import dev.nucleusframework.composenativetray.tray.api.Tray
+import dev.nucleusframework.tray.Tray
fun main() = nucleusApplication {
Tray(
icon = Icons.Default.Favorite,
tooltip = "My App",
primaryAction = { showWindow() },
) {
Item(label = "Settings") { openSettings() }
Divider()
Item(label = "Quit") { exitApplication() }
}
}Checkable items and submenus
The menu lambda is @Composable: it reads state, and the native menu follows each change.
var notifications by remember { mutableStateOf(true) }
var advanced by remember { mutableStateOf(false) }
Tray(icon = Icons.Default.Settings, tooltip = "Settings") {
CheckableItem(
label = "Notifications",
checked = notifications,
onCheckedChange = { notifications = it },
)
SubMenu(label = "Options") {
Item(label = "Option 1") { }
SubMenu(label = "Advanced") {
CheckableItem(label = "Verbose", checked = advanced, onCheckedChange = { advanced = it })
}
}
}Only the imports change. Two checkable items may now share a label: each one toggles alone.
Icon and tooltip updates
Pass state to icon and tooltip, as before. A change that keeps the same icon skips the icon
render, so a menu-only or tooltip-only change applies at once.
var unread by remember { mutableStateOf(0) }
Tray(
icon = if (unread > 0) Icons.Default.MarkEmailUnread else Icons.Default.Email,
tooltip = if (unread > 0) "$unread unread" else "No new mail",
) {
Item(label = "Mark all read") { unread = 0 }
}TrayApp
From 2.1.x, TrayApp, rememberTrayAppState and TrayAppState keep their signatures. Only
the imports change:
-import dev.nucleusframework.composenativetray.trayapp.TrayApp
-import dev.nucleusframework.composenativetray.trayapp.TrayWindowDismissMode
-import dev.nucleusframework.composenativetray.trayapp.rememberTrayAppState
+import dev.nucleusframework.tray.app.TrayApp
+import dev.nucleusframework.tray.app.TrayWindowDismissMode
+import dev.nucleusframework.tray.app.rememberTrayAppState
fun main() = nucleusApplication {
val state = rememberTrayAppState(
initialWindowSize = DpSize(300.dp, 420.dp),
initialDismissMode = TrayWindowDismissMode.AUTO,
)
TrayApp(
state = state,
icon = Icons.Default.Dashboard,
tooltip = "Quick settings",
menu = {
Item("Toggle popup") { state.toggle() }
Divider()
Item("Quit") { exitApplication() }
},
) {
Text("Quick settings")
}
}Coming from 1.x, also:
| 1.x | Nucleus |
|---|---|
ApplicationScope.TrayApp inside Compose Desktop's application { } | NucleusApplicationScope.TrayApp inside nucleusApplication { } |
@OptIn(ExperimentalTrayAppApi::class) | Remove it: TrayApp needs no opt-in |
content: @Composable DialogWindowScope.() -> Unit | content: @Composable () -> Unit: the popup is no DialogWindow, so code that used the window of that scope needs another way |
transparent = … | Removed: on Windows and macOS the popup is always a transparent native panel |
undecorated, resizable, windowsTitle and windowIcon only apply to the fallback window of a
Linux Wayland session without XWayland. See Tray apps.
Remove the icon
The icon stays while Tray or TrayApp is in the composition. Take it out with an if, or end
the app with exitApplication():
Tray(icon = Icons.Default.Favorite, tooltip = "My App") {
Item(label = "Exit") {
- dispose()
- exitProcess(0)
+ exitApplication()
}
}dispose() is still in the menu DSL, but it does nothing, as it already did in the composable
menu of 2.x. A Tray that leaves the composition is disposed for good; bringing it back creates a
new tray.
API mapping
| ComposeNativeTray | Nucleus |
|---|---|
Tray(…), every overload | Tray(…), same parameters (System tray) |
Tray(iconPath, windowsIconPath, …), deprecated | Still there and still deprecated. Use iconContent or a DrawableResource |
Item, CheckableItem, SubMenu, Divider | Same (Tray menu DSL) |
KeyShortcut, Key | Same, in dev.nucleusframework.tray.menu |
IconRenderProperties.forCurrentOperatingSystem, withoutScalingAndAliasing, forMenuItem | Same, in dev.nucleusframework.tray.utils |
isMenuBarInDarkMode() | Same, in dev.nucleusframework.tray.utils |
TrayApp(…), TrayAppState, rememberTrayAppState, TrayWindowDismissMode | Same, in dev.nucleusframework.tray.app (Tray apps) |
getTrayPosition(), TrayPosition | Same, in dev.nucleusframework.tray.app |
getTrayWindowPosition(windowWidth, windowHeight, …) | Same, in dev.nucleusframework.tray.app |
allowComposeNativeTrayLogging, composeNativeTrayLoggingLevel | allowNucleusRuntimeLogging, nucleusLoggingLevel from core-runtime (dev.nucleusframework.core.runtime.tools). Tray logs go to the dev.nucleusframework.tray JUL logger |
1.x SingleInstanceManager | Built into nucleusApplication. React to a second launch with SingleInstanceRestoreEffect (Single instance) |
MacOSWindowManager (Dock show / hide) | No direct equivalent. For a tray app, nucleusApplication(dockIconFollowsWindows = true) keeps the app out of the Dock (Tray apps) |
No public equivalent
These were public in ComposeNativeTray. In Nucleus they are internal: tray-app uses them, and
they can change in any release.
NativeTray, the non-composable tray engine. It is marked@InternalNucleusTrayApi, whose opt-in level is an error. Use theTraycomposables.ComposableIconUtils,MenuContentHash,TrayClickTracker,AppIdProvider,MacTrayInitializerandWindowsTrayInitializer, also marked@InternalNucleusTrayApi.LinuxTrayInitializerandMacOSMenuBarThemeDetector, nowinternal. For the menu bar theme, callisMenuBarInDarkMode(); it has no change listener. AnImageVectoricon withouttintalready follows the menu bar theme.getTrayWindowPositionForInstanceis still public, but it takes the instance key that onlyNativeTraygives. UsegetTrayWindowPositionorTrayApp.
Behavior changes
The calls are the same, but the backends were rewritten while the tray was being tested in Nucleus. These changes can show in an app:
- Labels are literal.
&on Windows and_on Linux are no longer read as mnemonics, and a-label is an item, not a separator. UseDivider()for separators. - Each tray is independent. Several trays live side by side on every OS. On Linux, the old backend let only one tray live at a time. On Linux and Windows, disposing one tray dropped the menu callbacks of the others.
- Callbacks see current state. A click,
primaryActionandonMenuOpenedrun the latest lambdas, and a new lambda on each recomposition no longer rebuilds the tray. - Changes are conflated. A burst of updates reaches the native tray in order and collapses to the newest state, and disposal is final: no late update can bring the icon back.
- Icons render to a capped cache. Identical renders share a file, and at most 64 files are
kept. Raise the cap with
-Dnucleus.tray.iconCacheSize=<n>. - GNOME. The AppIndicator extension opens the menu on a single click and calls
primaryActionon a double click, so aTrayApppopup opens on a double click. With no menu, a single click does nothing. The app never receives the single click. - Linux,
primaryAction. The old backend always marked the item as menu only, so hosts opened the menu and never called the primary action. With aprimaryAction, the item now asks the host to call it on a click (GNOME aside, see above). - TrayApp anchoring. Several
TrayApps each anchor their popup to their own icon. On macOS a visible popup follows its icon when other menu bar items come or go. - Wayland. In a Linux Wayland session, a click on the desktop, the top bar or a Wayland window
does not reach the popup, so
TrayWindowDismissMode.AUTOdoes not close it there. It closes from the icon, fromhide()or from your code.
Update the build rules
- ProGuard. The old README asked for keep rules on JNA and
dev.nucleusframework.composenativetray.**. That package no longer exists, and the tray uses JNI, not JNA. If you keep a rule for the tray, point it atdev.nucleusframework.tray.**. - GraalVM.
nucleus.trayships its reachability metadata in the JAR, so remove any metadata you copied for thecomposenativetrayclasses.
Checklist
composenativetray/composenativetray-appreplaced withnucleus.tray/nucleus.tray-appat the Nucleus version.- Every
dev.nucleusframework.composenativetray(orcom.kdroid.composetray) import replaced. TrayAppcalled insidenucleusApplication { }, and the rest of the app ported to Nucleus 3.0.- Menu labels checked: no
&or_mnemonics,Divider()instead of-. dispose()calls in menus replaced with aniforexitApplication().- No use of
NativeTrayor the other internal classes. - Logging switched to
allowNucleusRuntimeLogging/nucleusLoggingLevel. - ProGuard and GraalVM rules for
composenativetrayremoved or retargeted. - Clicks tested on each OS, including a double click under GNOME.
What's next
- System tray: icon sources, clicks, and platform behavior.
- Tray menu DSL: items, checkable items, submenus and shortcuts.
- Tray apps: the popup anchored to the icon.
- Migrate from Nucleus 2.x: the rest of the 3.0 changes.
Last updated on
Migrate from JetBrains Compose Desktop
Move a JetBrains Compose Desktop app to Nucleus. Apply the plugin, rename the DSL block, and replace the AWT windows, dialogs, and tray with their Nucleus equivalents.
Migrate from ComposeMediaPlayer
Move an app from ComposeMediaPlayer to the Nucleus media modules. Swap the coordinates and the package, run desktop video under nucleusApplication, and adapt the few APIs that were renamed or removed.