Toggle the Comet when pressing F12
This commit is contained in:
parent
fc53a97831
commit
b7c65c877d
9 changed files with 125 additions and 35 deletions
|
|
@ -35,6 +35,12 @@ pub enum Event {
|
|||
duration: Duration,
|
||||
span: Span,
|
||||
},
|
||||
QuitRequested {
|
||||
at: SystemTime,
|
||||
},
|
||||
AlreadyRunning {
|
||||
at: SystemTime,
|
||||
},
|
||||
}
|
||||
|
||||
impl Event {
|
||||
|
|
@ -43,19 +49,36 @@ impl Event {
|
|||
Self::Connected { at, .. }
|
||||
| Self::Disconnected { at, .. }
|
||||
| Self::ThemeChanged { at, .. }
|
||||
| Self::SpanFinished { at, .. } => *at,
|
||||
| Self::SpanFinished { at, .. }
|
||||
| Self::QuitRequested { at }
|
||||
| Self::AlreadyRunning { at } => *at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_running() -> bool {
|
||||
std::net::TcpListener::bind(client::SERVER_ADDRESS).is_err()
|
||||
}
|
||||
|
||||
pub fn run() -> impl Stream<Item = Event> {
|
||||
stream::channel(|mut output| async move {
|
||||
let mut buffer = Vec::new();
|
||||
|
||||
loop {
|
||||
let Ok(mut stream) = connect().await else {
|
||||
delay().await;
|
||||
continue;
|
||||
let mut stream = match connect().await {
|
||||
Ok(stream) => stream,
|
||||
Err(error) => {
|
||||
if error.kind() == io::ErrorKind::AddrInUse {
|
||||
let _ = output
|
||||
.send(Event::AlreadyRunning {
|
||||
at: SystemTime::now(),
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
delay().await;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
loop {
|
||||
|
|
@ -124,6 +147,11 @@ pub fn run() -> impl Stream<Item = Event> {
|
|||
}
|
||||
}
|
||||
}
|
||||
client::Message::Quit { at } => {
|
||||
let _ = output
|
||||
.send(Event::QuitRequested { at })
|
||||
.await;
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(Error::IOFailed(_)) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue