Skip to content

Commit eb42b42

Browse files
committed
Refactor visibility handling in TrayApp and improve delay logic
- Unified position calculation and visibility logic before showing tray window. - Adjusted delays for better cross-platform consistency. - Improved code readability by restructuring `try-catch` blocks.
1 parent e74b26b commit eb42b42

File tree

1 file changed

+8
-8
lines changed
  • src/commonMain/kotlin/com/kdroid/composetray/tray/api

1 file changed

+8
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,10 @@ fun ApplicationScope.TrayApp(
391391
}
392392

393393
// FIX: Consolidated visibility handling with position calculation BEFORE showing the window.
394-
// Added macOS-specific delay before polling, as per your feedback.
395394
LaunchedEffect(isVisible) {
396395
if (isVisible) {
397396
if (!shouldShowWindow) {
398-
// macOS-specific delay to allow tray icon to settle
399-
if (os == MACOS) {
400-
delay(300)
401-
}
397+
delay(150)
402398

403399
val widthPx = currentWindowSize.width.value.toInt()
404400
val heightPx = currentWindowSize.height.value.toInt()
@@ -408,7 +404,7 @@ fun ApplicationScope.TrayApp(
408404
position = getTrayWindowPositionForInstance(
409405
tray.instanceKey(), widthPx, heightPx
410406
)
411-
delay(50)
407+
delay(150)
412408
}
413409
// If still default after timeout, proceed anyway to avoid invisible window
414410
dialogState.position = position
@@ -481,7 +477,10 @@ fun ApplicationScope.TrayApp(
481477
}
482478

483479
// Mark this as the tray popup (macOS visibility monitor)
484-
try { window.name = WindowVisibilityMonitor.TRAY_DIALOG_NAME } catch (_: Throwable) {}
480+
try {
481+
window.name = WindowVisibilityMonitor.TRAY_DIALOG_NAME
482+
} catch (_: Throwable) {
483+
}
485484
runCatching { WindowVisibilityMonitor.recompute() }
486485

487486
// Bring to front on open
@@ -490,7 +489,8 @@ fun ApplicationScope.TrayApp(
490489
window.toFront()
491490
window.requestFocus()
492491
window.requestFocusInWindow()
493-
} catch (_: Throwable) {}
492+
} catch (_: Throwable) {
493+
}
494494
}
495495

496496
val focusListener = object : WindowFocusListener {

0 commit comments

Comments
 (0)