Skip to content

Commit b66a541

Browse files
committed
refactor(macos): move the dashboard failure page out of the window controller
SwiftLint type_body_length: the drag-message handler pushed DashboardWindowController past 800 lines; the failure-page HTML is presentation-only and now lives in DashboardFailurePage.
1 parent a60339e commit b66a541

2 files changed

Lines changed: 116 additions & 110 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import Foundation
2+
3+
/// Renders the static error page the dashboard window shows when the Control
4+
/// UI cannot load. Presentation-only; kept out of `DashboardWindowController`
5+
/// so the controller stays focused on window/navigation behavior.
6+
enum DashboardFailurePage {
7+
static func html(title: String, message: String, detail: String?, url: URL?) -> String {
8+
let detailHTML = detail.map { "<p class=\"detail\">\(self.htmlEscape($0))</p>" } ?? ""
9+
let urlHTML = url.map { "<code>\(self.htmlEscape($0.absoluteString))</code>" } ?? ""
10+
return """
11+
<!doctype html>
12+
<html>
13+
<head>
14+
<meta charset="utf-8">
15+
<style>
16+
:root { color-scheme: light dark; }
17+
* { box-sizing: border-box; }
18+
body {
19+
margin: 0;
20+
min-height: 100vh;
21+
display: grid;
22+
place-items: center;
23+
background: #101114;
24+
color: rgba(255,255,255,.92);
25+
font: 15px -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
26+
}
27+
main {
28+
width: min(540px, calc(100vw - 72px));
29+
padding: 34px;
30+
border: 1px solid rgba(255,255,255,.12);
31+
border-radius: 22px;
32+
background: rgba(255,255,255,.035);
33+
box-shadow: 0 28px 90px rgba(0,0,0,.36);
34+
line-height: 1.45;
35+
}
36+
.badge {
37+
width: 44px;
38+
height: 44px;
39+
display: grid;
40+
place-items: center;
41+
margin-bottom: 20px;
42+
border-radius: 14px;
43+
background: rgba(255,255,255,.07);
44+
color: #ff746b;
45+
font-size: 24px;
46+
}
47+
h1 {
48+
margin: 0 0 12px;
49+
font-size: 24px;
50+
line-height: 1.16;
51+
font-weight: 700;
52+
letter-spacing: 0;
53+
}
54+
p {
55+
margin: 0;
56+
color: rgba(255,255,255,.76);
57+
font-size: 16px;
58+
}
59+
.detail {
60+
margin-top: 14px;
61+
color: rgba(255,255,255,.56);
62+
font-size: 13px;
63+
}
64+
code {
65+
display: block;
66+
margin-top: 18px;
67+
padding: 12px;
68+
border: 1px solid rgba(255,255,255,.08);
69+
border-radius: 10px;
70+
background: rgba(0,0,0,.26);
71+
color: rgba(255,255,255,.76);
72+
overflow-wrap: anywhere;
73+
font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
74+
}
75+
@media (prefers-color-scheme: light) {
76+
body { background: #f5f6f8; color: rgba(0,0,0,.86); }
77+
main {
78+
background: rgba(255,255,255,.84);
79+
border-color: rgba(0,0,0,.1);
80+
box-shadow: 0 28px 90px rgba(0,0,0,.12);
81+
}
82+
.badge { background: rgba(0,0,0,.06); }
83+
p { color: rgba(0,0,0,.68); }
84+
.detail { color: rgba(0,0,0,.54); }
85+
code {
86+
background: rgba(0,0,0,.05);
87+
border-color: rgba(0,0,0,.08);
88+
color: rgba(0,0,0,.68);
89+
}
90+
}
91+
</style>
92+
</head>
93+
<body>
94+
<main>
95+
<div class="badge">!</div>
96+
<h1>\(self.htmlEscape(title))</h1>
97+
<p>\(self.htmlEscape(message))</p>
98+
\(detailHTML)
99+
\(urlHTML)
100+
</main>
101+
</body>
102+
</html>
103+
"""
104+
}
105+
106+
private static func htmlEscape(_ value: String) -> String {
107+
value
108+
.replacingOccurrences(of: "&", with: "&amp;")
109+
.replacingOccurrences(of: "<", with: "&lt;")
110+
.replacingOccurrences(of: ">", with: "&gt;")
111+
.replacingOccurrences(of: "\"", with: "&quot;")
112+
.replacingOccurrences(of: "'", with: "&#39;")
113+
}
114+
}

‎apps/macos/Sources/OpenClaw/DashboardWindowController.swift‎

Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ final class DashboardWindowController: NSWindowController, WKNavigationDelegate,
242242
self.refreshNativeAuthScript(url: self.currentURL, auth: self.auth)
243243
self.webView.stopLoading()
244244
self.webView.loadHTMLString(
245-
Self.failureHTML(title: title, message: message, detail: detail, url: nil),
245+
DashboardFailurePage.html(title: title, message: message, detail: detail, url: nil),
246246
baseURL: nil)
247247
self.show()
248248
}
@@ -846,121 +846,13 @@ final class DashboardWindowController: NSWindowController, WKNavigationDelegate,
846846
dashboard load failed url=\(dashboardLogString(for: self.currentURL), privacy: .public) \
847847
error=\(error.localizedDescription, privacy: .public)
848848
""")
849-
let html = Self.failureHTML(
849+
let html = DashboardFailurePage.html(
850850
title: "Dashboard unavailable",
851851
message: error.localizedDescription,
852852
detail: "The dashboard window is open, but the web UI could not load from this endpoint.",
853853
url: self.currentURL)
854854
self.webView.loadHTMLString(html, baseURL: nil)
855855
}
856-
857-
private static func failureHTML(title: String, message: String, detail: String?, url: URL?) -> String {
858-
let detailHTML = detail.map { "<p class=\"detail\">\(self.htmlEscape($0))</p>" } ?? ""
859-
let urlHTML = url.map { "<code>\(self.htmlEscape($0.absoluteString))</code>" } ?? ""
860-
return """
861-
<!doctype html>
862-
<html>
863-
<head>
864-
<meta charset="utf-8">
865-
<style>
866-
:root { color-scheme: light dark; }
867-
* { box-sizing: border-box; }
868-
body {
869-
margin: 0;
870-
min-height: 100vh;
871-
display: grid;
872-
place-items: center;
873-
background: #101114;
874-
color: rgba(255,255,255,.92);
875-
font: 15px -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
876-
}
877-
main {
878-
width: min(540px, calc(100vw - 72px));
879-
padding: 34px;
880-
border: 1px solid rgba(255,255,255,.12);
881-
border-radius: 22px;
882-
background: rgba(255,255,255,.035);
883-
box-shadow: 0 28px 90px rgba(0,0,0,.36);
884-
line-height: 1.45;
885-
}
886-
.badge {
887-
width: 44px;
888-
height: 44px;
889-
display: grid;
890-
place-items: center;
891-
margin-bottom: 20px;
892-
border-radius: 14px;
893-
background: rgba(255,255,255,.07);
894-
color: #ff746b;
895-
font-size: 24px;
896-
}
897-
h1 {
898-
margin: 0 0 12px;
899-
font-size: 24px;
900-
line-height: 1.16;
901-
font-weight: 700;
902-
letter-spacing: 0;
903-
}
904-
p {
905-
margin: 0;
906-
color: rgba(255,255,255,.76);
907-
font-size: 16px;
908-
}
909-
.detail {
910-
margin-top: 14px;
911-
color: rgba(255,255,255,.56);
912-
font-size: 13px;
913-
}
914-
code {
915-
display: block;
916-
margin-top: 18px;
917-
padding: 12px;
918-
border: 1px solid rgba(255,255,255,.08);
919-
border-radius: 10px;
920-
background: rgba(0,0,0,.26);
921-
color: rgba(255,255,255,.76);
922-
overflow-wrap: anywhere;
923-
font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
924-
}
925-
@media (prefers-color-scheme: light) {
926-
body { background: #f5f6f8; color: rgba(0,0,0,.86); }
927-
main {
928-
background: rgba(255,255,255,.84);
929-
border-color: rgba(0,0,0,.1);
930-
box-shadow: 0 28px 90px rgba(0,0,0,.12);
931-
}
932-
.badge { background: rgba(0,0,0,.06); }
933-
p { color: rgba(0,0,0,.68); }
934-
.detail { color: rgba(0,0,0,.54); }
935-
code {
936-
background: rgba(0,0,0,.05);
937-
border-color: rgba(0,0,0,.08);
938-
color: rgba(0,0,0,.68);
939-
}
940-
}
941-
</style>
942-
</head>
943-
<body>
944-
<main>
945-
<div class="badge">!</div>
946-
<h1>\(self.htmlEscape(title))</h1>
947-
<p>\(self.htmlEscape(message))</p>
948-
\(detailHTML)
949-
\(urlHTML)
950-
</main>
951-
</body>
952-
</html>
953-
"""
954-
}
955-
956-
private static func htmlEscape(_ value: String) -> String {
957-
value
958-
.replacingOccurrences(of: "&", with: "&amp;")
959-
.replacingOccurrences(of: "<", with: "&lt;")
960-
.replacingOccurrences(of: ">", with: "&gt;")
961-
.replacingOccurrences(of: "\"", with: "&quot;")
962-
.replacingOccurrences(of: "'", with: "&#39;")
963-
}
964856
}
965857

966858
#if DEBUG

0 commit comments

Comments
 (0)