Skip to content

Commit 1d8613c

Browse files
committed
Add overloads for Tray and TrayApp to support platform-specific DrawableResource and ImageVector icons.
1 parent 34749f5 commit 1d8613c

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,38 @@ fun ApplicationScope.Tray(
462462
menuContent = menuContent
463463
)
464464
}
465+
466+
@Composable
467+
fun ApplicationScope.Tray(
468+
windowsIcon: DrawableResource,
469+
macLinuxIcon: ImageVector,
470+
tint: Color? = null,
471+
iconRenderProperties: IconRenderProperties = IconRenderProperties.forCurrentOperatingSystem(),
472+
tooltip: String,
473+
primaryAction: (() -> Unit)? = null,
474+
menuContent: (TrayMenuBuilder.() -> Unit)? = null,
475+
) {
476+
val os = getOperatingSystem()
477+
478+
if (os == WINDOWS) {
479+
// Convert DrawableResource to Painter for Windows and delegate
480+
val painter = painterResource(windowsIcon)
481+
Tray(
482+
icon = painter,
483+
iconRenderProperties = iconRenderProperties,
484+
tooltip = tooltip,
485+
primaryAction = primaryAction,
486+
menuContent = menuContent
487+
)
488+
} else {
489+
// Use ImageVector for macOS and Linux
490+
Tray(
491+
icon = macLinuxIcon,
492+
tint = tint,
493+
iconRenderProperties = iconRenderProperties,
494+
tooltip = tooltip,
495+
primaryAction = primaryAction,
496+
menuContent = menuContent
497+
)
498+
}
499+
}

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,51 @@ fun ApplicationScope.TrayApp(
218218
)
219219
}
220220

221+
@ExperimentalTrayAppApi
222+
@Composable
223+
fun ApplicationScope.TrayApp(
224+
windowsIcon: DrawableResource,
225+
macLinuxIcon: ImageVector,
226+
tint: Color? = null,
227+
iconRenderProperties: IconRenderProperties = IconRenderProperties.forCurrentOperatingSystem(),
228+
tooltip: String,
229+
windowSize: DpSize = DpSize(300.dp, 200.dp),
230+
visibleOnStart: Boolean = false,
231+
fadeDurationMs: Int = 200,
232+
animationSpec: AnimationSpec<Float> = tween(durationMillis = fadeDurationMs, easing = EaseInOut),
233+
menu: (TrayMenuBuilder.() -> Unit)? = null,
234+
content: @Composable () -> Unit,
235+
) {
236+
val os = getOperatingSystem()
237+
if (os == WINDOWS) {
238+
val painter = painterResource(windowsIcon)
239+
TrayApp(
240+
icon = painter,
241+
iconRenderProperties = iconRenderProperties,
242+
tooltip = tooltip,
243+
windowSize = windowSize,
244+
visibleOnStart = visibleOnStart,
245+
fadeDurationMs = fadeDurationMs,
246+
animationSpec = animationSpec,
247+
menu = menu,
248+
content = content,
249+
)
250+
} else {
251+
TrayApp(
252+
icon = macLinuxIcon,
253+
tint = tint,
254+
iconRenderProperties = iconRenderProperties,
255+
tooltip = tooltip,
256+
windowSize = windowSize,
257+
visibleOnStart = visibleOnStart,
258+
fadeDurationMs = fadeDurationMs,
259+
animationSpec = animationSpec,
260+
menu = menu,
261+
content = content,
262+
)
263+
}
264+
}
265+
221266
/**
222267
* TrayApp overload: accepts a composable iconContent with fade in/out animation.
223268
*/

0 commit comments

Comments
 (0)