@@ -27,9 +27,19 @@ private final class DashboardLinkMessageHandler: NSObject, WKScriptMessageHandle
2727 }
2828}
2929
30+ @ MainActor
31+ private final class DashboardWindowDragMessageHandler : NSObject , WKScriptMessageHandler {
32+ weak var owner : DashboardWindowController ?
33+
34+ func userContentController ( _ : WKUserContentController , didReceive message : WKScriptMessage ) {
35+ self . owner ? . receiveWindowDragMessage ( message )
36+ }
37+ }
38+
3039@ MainActor
3140final class DashboardWindowController : NSWindowController , WKNavigationDelegate , WKUIDelegate , NSWindowDelegate {
3241 private static let linkMessageHandlerName = " openclawLink "
42+ private static let windowDragMessageHandlerName = " openclawWindowDrag "
3343
3444 private let webView : WKWebView
3545 private let linkBrowser : DashboardLinkBrowserView
@@ -55,6 +65,8 @@ final class DashboardWindowController: NSWindowController, WKNavigationDelegate,
5565 config . userContentController = WKUserContentController ( )
5666 let linkMessageHandler = DashboardLinkMessageHandler ( )
5767 config . userContentController . add ( linkMessageHandler , name : Self . linkMessageHandlerName )
68+ let windowDragMessageHandler = DashboardWindowDragMessageHandler ( )
69+ config . userContentController . add ( windowDragMessageHandler , name : Self . windowDragMessageHandlerName )
5870 Self . installNativeChromeScript ( into : config . userContentController )
5971 Self . installNativeAuthScript ( into : config . userContentController , url : url , auth : auth )
6072
@@ -104,6 +116,7 @@ final class DashboardWindowController: NSWindowController, WKNavigationDelegate,
104116 // optional browser collapsed until a link explicitly opens it.
105117 self . linkBrowserItem . isCollapsed = true
106118 linkMessageHandler . owner = self
119+ windowDragMessageHandler . owner = self
107120 self . webView . navigationDelegate = self
108121 self . webView . uiDelegate = self
109122 self . linkBrowser . webViewNavigationDelegate = self
@@ -229,7 +242,7 @@ final class DashboardWindowController: NSWindowController, WKNavigationDelegate,
229242 self . refreshNativeAuthScript ( url : self . currentURL , auth : self . auth )
230243 self . webView . stopLoading ( )
231244 self . webView . loadHTMLString (
232- Self . failureHTML ( title : title , message : message , detail : detail , url : nil ) ,
245+ DashboardFailurePage . html ( title : title , message : message , detail : detail , url : nil ) ,
233246 baseURL : nil )
234247 self . show ( )
235248 }
@@ -278,6 +291,36 @@ final class DashboardWindowController: NSWindowController, WKNavigationDelegate,
278291 }
279292 }
280293
294+ /// The Control UI posts this from mousedown on passive pane-header chrome
295+ /// (split-view session titles). WKWebView swallows titlebar-style drags, so
296+ /// the web side asks the window to take over the in-flight mouse gesture.
297+ fileprivate func receiveWindowDragMessage ( _ message : WKScriptMessage ) {
298+ guard message . name == Self . windowDragMessageHandlerName ,
299+ message . webView === self . webView ,
300+ message . frameInfo . isMainFrame ,
301+ Self . isTrustedLinkSource ( message . frameInfo . request . url , dashboardURL : self . currentURL ) ,
302+ Self . isWindowDragRequest ( message . body ) ,
303+ let window
304+ else {
305+ return
306+ }
307+ // The script message arrives async; during a press the app's current
308+ // event is still the initiating left-mouse-down (or a later drag). A
309+ // finished click leaves left-mouse-up here and starts no drag.
310+ guard let event = NSApp . currentEvent ,
311+ event . type == . leftMouseDown || event . type == . leftMouseDragged ,
312+ event . window === window
313+ else {
314+ return
315+ }
316+ window . performDrag ( with : event )
317+ }
318+
319+ static func isWindowDragRequest ( _ body : Any ) -> Bool {
320+ guard let payload = body as? [ String : Any ] else { return false }
321+ return payload [ " type " ] as? String == " window-drag "
322+ }
323+
281324 static func linkRequest ( from body : Any ) -> DashboardLinkRequest ? {
282325 guard let payload = body as? [ String : Any ] ,
283326 payload [ " type " ] as? String == " open-link " ,
@@ -803,121 +846,13 @@ final class DashboardWindowController: NSWindowController, WKNavigationDelegate,
803846 dashboard load failed url= \( dashboardLogString ( for : self . currentURL ) , privacy : . public ) \
804847 error= \( error . localizedDescription , privacy : . public )
805848 """ )
806- let html = Self . failureHTML (
849+ let html = DashboardFailurePage . html (
807850 title : " Dashboard unavailable " ,
808851 message : error . localizedDescription ,
809852 detail : " The dashboard window is open, but the web UI could not load from this endpoint. " ,
810853 url : self . currentURL )
811854 self . webView . loadHTMLString ( html , baseURL : nil )
812855 }
813-
814- private static func failureHTML ( title : String , message : String , detail : String ? , url : URL ? ) -> String {
815- let detailHTML = detail . map { " <p class= \" detail \" > \( self . htmlEscape ( $0 ) ) </p> " } ?? " "
816- let urlHTML = url . map { " <code> \( self . htmlEscape ( $0 . absoluteString ) ) </code> " } ?? " "
817- return """
818- <!doctype html>
819- <html>
820- <head>
821- <meta charset= " utf-8 " >
822- <style>
823- :root { color-scheme: light dark; }
824- * { box-sizing: border-box; }
825- body {
826- margin: 0;
827- min-height: 100vh;
828- display: grid;
829- place-items: center;
830- background: #101114;
831- color: rgba(255,255,255,.92);
832- font: 15px -apple-system, BlinkMacSystemFont, " SF Pro Text " , system-ui, sans-serif;
833- }
834- main {
835- width: min(540px, calc(100vw - 72px));
836- padding: 34px;
837- border: 1px solid rgba(255,255,255,.12);
838- border-radius: 22px;
839- background: rgba(255,255,255,.035);
840- box-shadow: 0 28px 90px rgba(0,0,0,.36);
841- line-height: 1.45;
842- }
843- .badge {
844- width: 44px;
845- height: 44px;
846- display: grid;
847- place-items: center;
848- margin-bottom: 20px;
849- border-radius: 14px;
850- background: rgba(255,255,255,.07);
851- color: #ff746b;
852- font-size: 24px;
853- }
854- h1 {
855- margin: 0 0 12px;
856- font-size: 24px;
857- line-height: 1.16;
858- font-weight: 700;
859- letter-spacing: 0;
860- }
861- p {
862- margin: 0;
863- color: rgba(255,255,255,.76);
864- font-size: 16px;
865- }
866- .detail {
867- margin-top: 14px;
868- color: rgba(255,255,255,.56);
869- font-size: 13px;
870- }
871- code {
872- display: block;
873- margin-top: 18px;
874- padding: 12px;
875- border: 1px solid rgba(255,255,255,.08);
876- border-radius: 10px;
877- background: rgba(0,0,0,.26);
878- color: rgba(255,255,255,.76);
879- overflow-wrap: anywhere;
880- font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
881- }
882- @media (prefers-color-scheme: light) {
883- body { background: #f5f6f8; color: rgba(0,0,0,.86); }
884- main {
885- background: rgba(255,255,255,.84);
886- border-color: rgba(0,0,0,.1);
887- box-shadow: 0 28px 90px rgba(0,0,0,.12);
888- }
889- .badge { background: rgba(0,0,0,.06); }
890- p { color: rgba(0,0,0,.68); }
891- .detail { color: rgba(0,0,0,.54); }
892- code {
893- background: rgba(0,0,0,.05);
894- border-color: rgba(0,0,0,.08);
895- color: rgba(0,0,0,.68);
896- }
897- }
898- </style>
899- </head>
900- <body>
901- <main>
902- <div class= " badge " >!</div>
903- <h1> \( self . htmlEscape ( title ) ) </h1>
904- <p> \( self . htmlEscape ( message ) ) </p>
905- \( detailHTML )
906- \( urlHTML )
907- </main>
908- </body>
909- </html>
910- """
911- }
912-
913- private static func htmlEscape ( _ value : String ) -> String {
914- value
915- . replacingOccurrences ( of : " & " , with : " & " )
916- . replacingOccurrences ( of : " < " , with : " < " )
917- . replacingOccurrences ( of : " > " , with : " > " )
918- . replacingOccurrences ( of : " \" " , with : " " " )
919- . replacingOccurrences ( of : " ' " , with : " ' " )
920- }
921856}
922857
923858#if DEBUG
0 commit comments