Skip to content

Commit 211a87d

Browse files
committed
fix(macos): respect primaryActionLabel for first menu item instead of hardcoded "Open"
Previously on macOS, the primary action menu item always displayed "Open" regardless of the user-specified label. This commit ensures that primaryActionLabel is correctly used as the label for the first menu item on macOS, matching the behavior on Linux.
1 parent bba375d commit 211a87d

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/commonMain/kotlin/com/kdroid/composetray/tray/api/NativeTray.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ internal class NativeTray {
115115
if (AwtTrayInitializer.isSupported()) {
116116
try {
117117
Log.d("NativeTray", "Initializing AWT tray with icon path: $iconPath")
118-
AwtTrayInitializer.initialize(iconPath, tooltip, primaryAction, menuContent)
118+
AwtTrayInitializer.initialize(iconPath, tooltip, primaryAction, primaryActionLabel, menuContent)
119119
awtTrayUsed.set(true)
120120
} catch (th: Throwable) {
121121
Log.e("NativeTray", "Error initializing AWT tray:", th)

src/commonMain/kotlin/com/kdroid/composetray/tray/impl/AwtTrayInitializer.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ object AwtTrayInitializer {
2323
* @param iconPath Path to the tray icon.
2424
* @param tooltip Tooltip text for the icon.
2525
* @param onLeftClick Action to execute on left-click on the icon.
26+
* @param primaryActionLabel Label for the primary action menu item (used on macOS).
2627
* @param menuContent Content of the tray menu.
2728
* @throws IllegalStateException If the system does not support the tray.
2829
*/
2930
fun initialize(
3031
iconPath: String,
3132
tooltip: String,
3233
onLeftClick: (() -> Unit)?,
34+
primaryActionLabel: String = "Open",
3335
menuContent: (TrayMenuBuilder.() -> Unit)?
3436
) {
3537
if (!isSupported()) {
@@ -78,7 +80,7 @@ object AwtTrayInitializer {
7880
// For macOS, prepend the primary action to the menu if it exists
7981
if (getOperatingSystem() == OperatingSystem.MACOS && onLeftClick != null) {
8082
val menuBuilder = AwtTrayMenuBuilderImpl(popupMenu, newTrayIcon)
81-
menuBuilder.Item("Open", true) { onLeftClick.invoke() }
83+
menuBuilder.Item(primaryActionLabel, true) { onLeftClick.invoke() }
8284
menuBuilder.Divider()
8385
menuBuilder.apply(it)
8486
} else {
@@ -102,4 +104,4 @@ object AwtTrayInitializer {
102104
trayIcon = null
103105
}
104106
}
105-
}
107+
}

0 commit comments

Comments
 (0)