Scoop API

scoop:scoop.ui.component.tray:0.1.0

src/handle.scoop

Selected production source · src/handle.scoop

1package scoop.ui.component.tray
3import scoop.tray.*
4import scoop.ui.state
6/** Controls the current mount; the exposed icon is borrowed from that mount. */
7public class NativeTrayHandle public constructor() {
8 private val binding = state<NativeTrayAttachment?>(None)
9 public val icon: TrayIcon? get() = binding.value?.icon
10 public val availability: TrayAvailability? get() = binding.value?.availability
11 public val isMenuPending: Boolean get() = binding.value?.isMenuPending ?: false
12 public fun requestMenu(): Boolean = binding.value?.requestMenu() ?: false
13 public fun cancelMenu() {
14 binding.value?.cancelMenu()
15 }
16 internal fun bind(owner: NativeTrayAttachment) {
17 when (binding.value) {
18 case Some(val current) -> if (!(current === owner))
19 throw IllegalStateException(Some("tray handle already belongs to a mounted icon"))
20 case None -> {
21 binding.value = Some(owner)
22 }
23 }
24 }
25 internal fun unbind(owner: NativeTrayAttachment) {
26 when (binding.value) {
27 case Some(val current) -> if (current === owner)
28 binding.value = None
29 case None -> {}
30 }
31 }