From 4f349482d070b23ef5da17264d4c3b59245e7b3d Mon Sep 17 00:00:00 2001 From: YSoung99 <99796713+YSoung99@users.noreply.github.com> Date: Wed, 2 Dec 2026 18:10:03 +0900 Subject: [PATCH] fix(desktop): call disableTitleBar off the EDT to avoid macOS deadlock Skiko's native disableTitlebar does dispatch_sync to the main queue. When MacTitleBarEffect calls it on the EDT while the AppKit main thread is in LWCToolkit's nested run loop waiting for the EDT, both threads wait on each other and the UI freezes permanently. Run the call on Dispatchers.IO so only a background thread blocks. Refs #69 Co-Authored-By: Claude Opus 5.5 --- .../desktopMain/kotlin/dev/piko/desktop/WindowFrame.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/desktopApp/src/desktopMain/kotlin/dev/piko/desktop/WindowFrame.kt b/desktopApp/src/desktopMain/kotlin/dev/piko/desktop/WindowFrame.kt index 1a2b9608..16a7a16e 100644 --- a/desktopApp/src/desktopMain/kotlin/dev/piko/desktop/WindowFrame.kt +++ b/desktopApp/src/desktopMain/kotlin/dev/piko/desktop/WindowFrame.kt @@ -66,7 +66,9 @@ import androidx.compose.runtime.mutableIntStateOf import androidx.compose.ui.draw.clip import dev.nihildigit.windowstouch.ProvideTouchViewConfiguration import java.awt.Container +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay +import kotlinx.coroutines.withContext import org.jetbrains.skia.FontMgr import org.jetbrains.skia.FontStyle import org.jetbrains.skiko.SkiaLayer @@ -600,7 +602,11 @@ private fun FrameWindowScope.MacTitleBarEffect() { // 画布的原生层在窗口显示时才建好,之前调用什么也不做,所以先等窗口显示出来 LaunchedEffect(window) { while (!window.isShowing) delay(16) - findSkiaLayer(window)?.disableTitleBar(TitleBarHeight.value) + // Skiko 在原生侧 dispatch_sync 到主队列;若在 EDT 上调用,而主线程恰好在 + // LWCToolkit.invokeAndWait 的嵌套 run loop(javaRunLoopMode,不处理主队列)里等 EDT, + // 两边互等即死锁(#69)。放到后台线程调用,只阻塞该后台线程。 + val layer = findSkiaLayer(window) + if (layer != null) withContext(Dispatchers.IO) { layer.disableTitleBar(TitleBarHeight.value) } MacOs.patchTitleBarDoubleClick() } }