Skip to content

Commit ee4d512

Browse files
committed
fix(macos): make OpenClaw settings pane responsive
1 parent 5e1a28b commit ee4d512

2 files changed

Lines changed: 121 additions & 15 deletions

File tree

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,30 @@ struct SystemAgentSettings: View {
1717
sessionPrefix: "mac-settings-openclaw")
1818

1919
var body: some View {
20-
VStack(alignment: .leading, spacing: 20) {
21-
SettingsPageHeader(
22-
title: "OpenClaw",
23-
subtitle: """
24-
Your AI-powered setup helper. It can check status, fix config, switch models, and connect channels.
25-
""")
20+
GeometryReader { geometry in
21+
ScrollView(.vertical) {
22+
VStack(alignment: .leading, spacing: 20) {
23+
SettingsPageHeader(
24+
title: "OpenClaw",
25+
subtitle: """
26+
Your AI-powered setup helper. It can check status, fix config, \
27+
switch models, and connect channels.
28+
""")
2629

27-
SettingsCardGroup("Chat") {
28-
SystemAgentOnboardingChatView(model: self.chat)
29-
.frame(maxWidth: .infinity, minHeight: 320, maxHeight: .infinity)
30-
}
31-
.frame(maxHeight: .infinity)
30+
SettingsCardGroup("Chat") {
31+
SystemAgentOnboardingChatView(model: self.chat)
32+
.frame(maxWidth: .infinity, minHeight: 320, maxHeight: .infinity)
33+
}
34+
.frame(maxHeight: .infinity)
3235

33-
Text("Tip: try “status”, “doctor”, “set default model …”, or “connect telegram”.")
34-
.font(.caption)
35-
.foregroundStyle(.secondary)
36+
Text("Tip: try “status”, “doctor”, “set default model …”, or “connect telegram”.")
37+
.font(.caption)
38+
.foregroundStyle(.secondary)
39+
}
40+
.settingsDetailContent()
41+
.frame(minHeight: geometry.size.height, alignment: .top)
42+
}
3643
}
37-
.settingsDetailContent()
3844
.task(id: self.isActive) {
3945
guard self.isActive else { return }
4046
Self.configureChatCallbacks(
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import AppKit
2+
import SwiftUI
3+
import XCTest
4+
@testable import OpenClaw
5+
6+
@MainActor
7+
final class SystemAgentSettingsLayoutTests: XCTestCase {
8+
private static var retainedWindows: [NSWindow] = []
9+
10+
func testPaneOwnsScrollableDetailContainer() async throws {
11+
let hosting = NSHostingView(rootView: SystemAgentSettings(
12+
isActive: false,
13+
onReplyReceived: {}))
14+
hosting.frame = NSRect(x: 0, y: 0, width: 800, height: 260)
15+
let window = Self.retainWindow(hosting)
16+
17+
try await Self.waitForLayout(hosting, stage: "system agent detail scroll") {
18+
Self.detailScrollView(in: hosting) != nil
19+
}
20+
let scroll = try XCTUnwrap(Self.detailScrollView(in: hosting))
21+
let maximumOffset = scroll.documentView.map {
22+
max(0, $0.bounds.height - scroll.contentView.bounds.height)
23+
} ?? 0
24+
XCTAssertGreaterThan(maximumOffset, 0)
25+
26+
window.orderOut(nil)
27+
}
28+
29+
func testChatUsesAvailableDetailHeight() async throws {
30+
let hosting = NSHostingView(rootView: SystemAgentSettings(
31+
isActive: false,
32+
onReplyReceived: {}))
33+
hosting.frame = NSRect(x: 0, y: 0, width: 800, height: 700)
34+
let window = Self.retainWindow(hosting)
35+
36+
try await Self.waitForLayout(hosting, stage: "system agent chat fills detail height") {
37+
Self.chatScrollView(in: hosting)?.frame.height ?? 0 > hosting.frame.height / 2
38+
}
39+
40+
window.orderOut(nil)
41+
}
42+
43+
private static func retainWindow(_ hosting: NSView) -> NSWindow {
44+
let window = NSWindow(
45+
contentRect: hosting.frame,
46+
styleMask: [.titled],
47+
backing: .buffered,
48+
defer: false)
49+
window.isReleasedWhenClosed = false
50+
window.contentView = hosting
51+
self.retainedWindows.append(window)
52+
return window
53+
}
54+
55+
private static func detailScrollView(in view: NSView) -> NSScrollView? {
56+
self.descendants(of: NSScrollView.self, in: view).first { scrollView in
57+
guard let documentView = scrollView.documentView else { return false }
58+
let containsChatScroll = !self.descendants(of: NSScrollView.self, in: documentView).isEmpty
59+
return containsChatScroll && documentView.bounds.height > scrollView.contentView.bounds.height + 1
60+
}
61+
}
62+
63+
private static func chatScrollView(in view: NSView) -> NSScrollView? {
64+
self.descendants(of: NSScrollView.self, in: view).first { scrollView in
65+
scrollView.frame.width > 500 && self.descendants(of: NSScrollView.self, in: scrollView).count == 1
66+
}
67+
}
68+
69+
private static func descendants<T: NSView>(of type: T.Type, in view: NSView) -> [T] {
70+
var matches: [T] = []
71+
if let match = view as? T { matches.append(match) }
72+
for child in view.subviews {
73+
matches.append(contentsOf: self.descendants(of: type, in: child))
74+
}
75+
return matches
76+
}
77+
78+
private static func waitForLayout(
79+
_ hosting: NSView,
80+
stage: String,
81+
timeout: Duration = .seconds(3),
82+
until condition: @MainActor () -> Bool) async throws
83+
{
84+
let clock = ContinuousClock()
85+
let deadline = clock.now.advanced(by: timeout)
86+
while clock.now < deadline {
87+
hosting.layoutSubtreeIfNeeded()
88+
if condition() { return }
89+
try await Task.sleep(for: .milliseconds(20))
90+
}
91+
throw SettingsLayoutTimeout(stage: stage)
92+
}
93+
94+
private struct SettingsLayoutTimeout: Error, CustomStringConvertible {
95+
let stage: String
96+
var description: String {
97+
"Settings layout timed out during \(self.stage)"
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)