Skip to content

Commit ef6a615

Browse files
committed
Improve dialog positioning and visibility setup in TrayApp
- Added multi-step initialization process for macOS and Windows to stabilize icon position and dialog placement. - Refined dialog state updates to ensure accurate positioning before visibility toggle. - Enhanced inline comments for better code clarity.
1 parent e49dc02 commit ef6a615

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

  • src/commonMain/kotlin/com/kdroid/composetray/tray/api

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,10 @@ fun ApplicationScope.TrayApp(
432432
LaunchedEffect(Unit) {
433433
// Ne s'exécute qu'une seule fois.
434434
if (trayAppState.isVisible.value) { // Vérifie si l'état initial est visible.
435-
// Si oui, on exécute la logique de pré-affichage (attente, etc.)
435+
436+
// Étape 1 : Attendre que la position de l'icône soit stable et disponible.
436437
if (os == MACOS) {
437-
delay(100)
438+
delay(100) // Donne le temps à l'icône de s'installer dans la barre de menus.
438439
}
439440
if (os == WINDOWS) {
440441
val deadline = System.currentTimeMillis() + 2000
@@ -445,7 +446,17 @@ fun ApplicationScope.TrayApp(
445446
autoHideEnabledAt = System.currentTimeMillis() + 1000
446447
}
447448

448-
// Une fois l'attente terminée, on peut afficher la fenêtre en toute sécurité.
449+
// Étape 2 : Calculer la position finale AVANT de montrer la fenêtre.
450+
val widthPx = currentWindowSize.width.value.toInt()
451+
val heightPx = currentWindowSize.height.value.toInt()
452+
val initialPosition = getTrayWindowPositionForInstance(
453+
tray.instanceKey(), widthPx, heightPx
454+
)
455+
456+
// Étape 3 : Appliquer cette position à l'état du dialogue.
457+
dialogState.position = initialPosition
458+
459+
// Étape 4 : SEULEMENT MAINTENANT, rendre la fenêtre visible.
449460
shouldShowWindow = true
450461
lastShownAt = System.currentTimeMillis()
451462
}

0 commit comments

Comments
 (0)