@@ -2,12 +2,13 @@ use can_dbc::DBC;
2
2
use chrono:: Utc ;
3
3
#[ cfg( target_os = "windows" ) ]
4
4
use pcan_basic:: socket:: usb:: UsbCanSocket ;
5
- use slint:: { Model , ModelRc , SharedString , VecModel , Weak } ;
5
+ use slint:: { ComponentHandle , Model , ModelRc , SharedString , VecModel , Weak } ;
6
6
#[ cfg( target_os = "linux" ) ]
7
7
use socketcan:: { CanInterface , CanSocket , EmbeddedFrame , Frame , Socket } ;
8
8
use std:: {
9
9
collections:: HashMap ,
10
10
fmt:: Write ,
11
+ process:: exit,
11
12
rc:: Rc ,
12
13
sync:: { mpsc:: Receiver , Arc , Mutex } ,
13
14
thread:: sleep,
@@ -29,6 +30,13 @@ static mut NEW_DBC_CHECK: bool = false;
29
30
use super :: { EVEN_COLOR , ODD_COLOR } ;
30
31
31
32
impl < ' a > ViewHandler < ' a > {
33
+ pub fn check_to_kill_thread ( & self ) {
34
+ let _ = self . ui_handle . upgrade_in_event_loop ( move |ui| {
35
+ if !ui. window ( ) . is_visible ( ) {
36
+ exit ( 1 ) ;
37
+ }
38
+ } ) ;
39
+ }
32
40
pub fn process_can_messages ( & mut self ) {
33
41
if let Ok ( dbc) = self . mspc_rx . lock ( ) . unwrap ( ) . try_recv ( ) {
34
42
#[ cfg( target_os = "linux" ) ]
@@ -68,6 +76,7 @@ impl<'a> ViewHandler<'a> {
68
76
let mut start_bus_load = Instant :: now ( ) ;
69
77
let mut total_bits = 0 ;
70
78
loop {
79
+ self . check_to_kill_thread ( ) ;
71
80
let bus_state = match can_if. state ( ) . unwrap ( ) . unwrap ( ) {
72
81
socketcan:: nl:: CanState :: ErrorActive => "ERR_ACTIVE" ,
73
82
socketcan:: nl:: CanState :: ErrorWarning => "ERR_WARNING" ,
@@ -138,6 +147,7 @@ impl<'a> ViewHandler<'a> {
138
147
use pcan_basic:: { error:: PcanError , socket:: RecvCan } ;
139
148
let mut start_bus_load = Instant :: now ( ) ;
140
149
let mut total_bits = 0 ;
150
+ self . check_to_kill_thread ( ) ;
141
151
loop {
142
152
let bitrate = self . bitrate ( ) . unwrap ( ) ;
143
153
let busload = if start_bus_load. elapsed ( ) >= Duration :: from_millis ( 1000 ) {
0 commit comments