Skip to content

Commit 66d9491

Browse files
CopilotGZTimeWalker
andcommitted
Add interactivity to views: network logs, settings display, and vertical scrolling
Co-authored-by: GZTimeWalker <[email protected]>
1 parent 7cb7ffc commit 66d9491

File tree

3 files changed

+81
-21
lines changed

3 files changed

+81
-21
lines changed

crates/wsrx-desktop-gpui/src/views/network_logs.rs

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,45 @@ pub struct NetworkLogsView {
1414

1515
impl NetworkLogsView {
1616
pub fn new(_window: &mut Window, _cx: &mut Context<Self>) -> Self {
17-
Self {
18-
logs: VecDeque::new(),
19-
}
17+
// Add some sample logs for demonstration
18+
let mut logs = VecDeque::new();
19+
20+
logs.push_back(LogEntry {
21+
timestamp: "2025-11-10 15:00:01".to_string(),
22+
level: LogLevel::Info,
23+
target: "wsrx::daemon".to_string(),
24+
message: "Daemon started successfully".to_string(),
25+
});
26+
27+
logs.push_back(LogEntry {
28+
timestamp: "2025-11-10 15:00:05".to_string(),
29+
level: LogLevel::Debug,
30+
target: "wsrx::tunnel".to_string(),
31+
message: "Initializing WebSocket connection to ws://example.com".to_string(),
32+
});
33+
34+
logs.push_back(LogEntry {
35+
timestamp: "2025-11-10 15:00:10".to_string(),
36+
level: LogLevel::Info,
37+
target: "wsrx::tunnel".to_string(),
38+
message: "Connection established: 127.0.0.1:8080 → ws://example.com".to_string(),
39+
});
40+
41+
logs.push_back(LogEntry {
42+
timestamp: "2025-11-10 15:00:15".to_string(),
43+
level: LogLevel::Warn,
44+
target: "wsrx::proxy".to_string(),
45+
message: "High latency detected: 250ms".to_string(),
46+
});
47+
48+
logs.push_back(LogEntry {
49+
timestamp: "2025-11-10 15:00:20".to_string(),
50+
level: LogLevel::Error,
51+
target: "wsrx::tunnel".to_string(),
52+
message: "Connection failed: Connection refused".to_string(),
53+
});
54+
55+
Self { logs }
2056
}
2157

2258
fn log_level_color(&self, level: LogLevel) -> gpui::Rgba {
@@ -128,22 +164,45 @@ impl Render for NetworkLogsView {
128164
.child("Network Logs"),
129165
)
130166
.child(
131-
div().flex().gap_2().child(
132-
div()
133-
.id("clear-logs-button")
134-
.px_3()
135-
.py_1()
136-
.text_sm()
137-
.bg(gpui::rgba(0x444444FF))
138-
.rounded_md()
139-
.cursor_pointer()
140-
.hover(|div| div.bg(gpui::rgba(0x555555FF)))
141-
.on_click(cx.listener(|this, _event, _window, cx| {
142-
this.logs.clear();
143-
cx.notify();
144-
}))
145-
.child("Clear"),
146-
),
167+
div().flex().gap_2()
168+
.child(
169+
div()
170+
.id("add-sample-log-button")
171+
.px_3()
172+
.py_1()
173+
.text_sm()
174+
.bg(colors::accent())
175+
.rounded_md()
176+
.cursor_pointer()
177+
.hover(|div| div.bg(gpui::rgba(0x0088DDFF)))
178+
.on_click(cx.listener(|this, _event, _window, cx| {
179+
use chrono::Local;
180+
this.logs.push_back(LogEntry {
181+
timestamp: Local::now().format("%Y-%m-%d %H:%M:%S").to_string(),
182+
level: LogLevel::Info,
183+
target: "wsrx::test".to_string(),
184+
message: format!("Sample log entry #{}", this.logs.len() + 1),
185+
});
186+
cx.notify();
187+
}))
188+
.child("Add Sample"),
189+
)
190+
.child(
191+
div()
192+
.id("clear-logs-button")
193+
.px_3()
194+
.py_1()
195+
.text_sm()
196+
.bg(gpui::rgba(0x444444FF))
197+
.rounded_md()
198+
.cursor_pointer()
199+
.hover(|div| div.bg(gpui::rgba(0x555555FF)))
200+
.on_click(cx.listener(|this, _event, _window, cx| {
201+
this.logs.clear();
202+
cx.notify();
203+
}))
204+
.child("Clear"),
205+
),
147206
),
148207
)
149208
.child(if self.logs.is_empty() {

crates/wsrx-desktop-gpui/src/views/root.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ impl RootView {
101101

102102
fn render_page_content(&self) -> impl IntoElement {
103103
div()
104+
.id("page-content")
104105
.flex_1()
105-
.overflow_hidden() // Use basic overflow hidden
106+
.overflow_y_scroll() // Allow vertical scrolling when content overflows
106107
.child(match self.current_page {
107108
Page::GetStarted => div().h_full().child(self.get_started.clone()),
108109
Page::Connections => div().h_full().child(self.connections.clone()),

crates/wsrx-desktop-gpui/src/views/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl SettingsView {
4444
}
4545

4646
impl Render for SettingsView {
47-
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
47+
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
4848
div()
4949
.flex()
5050
.flex_col()

0 commit comments

Comments
 (0)