Skip to content

Commit de57f08

Browse files
committed
添加网速显示
1 parent 1006f80 commit de57f08

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

dsclient/src/client.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ fn draw(host: String, pwd: String) {
264264
}
265265
true
266266
});
267-
let fpsstring = Arc::new(RwLock::new(String::new()));
268-
let fpss = fpsstring.clone();
267+
let _tool_str = Arc::new(RwLock::new(String::new()));
268+
let _tool_strc = _tool_str.clone();
269269
frame.draw(move |frame|{
270270
if let Ok(_buf) = draw_work_buf.read() {
271271
unsafe {
@@ -275,8 +275,8 @@ fn draw(host: String, pwd: String) {
275275
image.scale(frame.width(), frame.height(), false, true);
276276
image.draw(frame.x(), frame.y(), frame.width(), frame.height());
277277
draw::set_color_rgb(0, 0, 0);
278-
if let Ok(a) = fpss.read() {
279-
draw::draw_text(&a, frame.x() + frame.width() - 60, 20);
278+
if let Ok(a) = _tool_strc.read() {
279+
draw::draw_text(&a, frame.x() + frame.width() - 180, 20);
280280
}
281281
}
282282
}
@@ -294,12 +294,16 @@ fn draw(host: String, pwd: String) {
294294
let mut last = std::time::Instant::now();
295295
let mut fps = 0u8;
296296
let mut fpscount = 0u8;
297+
// 流速
298+
let mut _length_all = 0usize;
299+
let mut _length_sum = 0usize;
297300
// 接收第一帧数据
298301
let mut header = [0u8; 3];
299302
if let Err(_) = conn.read_exact(&mut header) {
300303
return;
301304
}
302305
let recv_len = depack(&header);
306+
_length_sum += recv_len;
303307
unsafe {
304308
b.set_len(recv_len);
305309
}
@@ -319,6 +323,7 @@ fn draw(host: String, pwd: String) {
319323
return;
320324
}
321325
let recv_len = depack(&header);
326+
_length_sum += recv_len;
322327
unsafe {
323328
b.set_len(recv_len);
324329
}
@@ -335,11 +340,13 @@ fn draw(host: String, pwd: String) {
335340
fpscount += 1;
336341
if dur.as_millis() >= 1000 {
337342
last = cur;
338-
if let Ok(mut a) = fpsstring.write() {
339-
*a = format!("FPS: {}", fps);
343+
_length_all = _length_sum;
344+
if let Ok(mut a) = _tool_str.write() {
345+
*a = format!("FPS:{:2} | Rate:{:>6}kb/s", fps, _length_all * 8 / 1024);
340346
}
341347
fps = fpscount;
342348
fpscount = 0;
349+
_length_sum = 0;
343350
}
344351
}
345352
tx.send(Msg::Draw);

dsclient/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
1+
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
22
mod bitmap;
33
mod client;
44

0 commit comments

Comments
 (0)