cleanup
This commit is contained in:
+4
-2
@@ -65,7 +65,7 @@ async fn process_messages(
|
|||||||
let mut ping_interval =
|
let mut ping_interval =
|
||||||
tokio::time::interval_at(Instant::now() + config.ping_interval, config.ping_interval);
|
tokio::time::interval_at(Instant::now() + config.ping_interval, config.ping_interval);
|
||||||
|
|
||||||
let pong_timer = tokio::time::sleep(Duration::from_secs(0));
|
let pong_timer = tokio::time::sleep(std::time::Duration::ZERO);
|
||||||
tokio::pin!(pong_timer);
|
tokio::pin!(pong_timer);
|
||||||
let mut awaiting_pong = false;
|
let mut awaiting_pong = false;
|
||||||
|
|
||||||
@@ -88,7 +88,9 @@ async fn process_messages(
|
|||||||
return Err("Server did not respond to ping".into());
|
return Err("Server did not respond to ping".into());
|
||||||
}
|
}
|
||||||
next_message = stream.next() => {
|
next_message = stream.next() => {
|
||||||
if handle_stream_message(next_message, &outgoing_tx, config.max_output_bytes).await? {
|
if handle_stream_message(next_message, &outgoing_tx, config.max_output_bytes)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
awaiting_pong = false;
|
awaiting_pong = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -5,10 +5,10 @@ use tokio::{
|
|||||||
process::Command,
|
process::Command,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn execute(command: &str, max_output_bytes: u64) -> (i32, String, String) {
|
pub async fn execute(command_line: &str, max_output_bytes: u64) -> (i32, String, String) {
|
||||||
let mut child = match Command::new("sh")
|
let mut child = match Command::new("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg(command)
|
.arg(command_line)
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
|
|||||||
@@ -21,11 +21,9 @@ impl Config {
|
|||||||
pub fn from_env() -> Result<Self, String> {
|
pub fn from_env() -> Result<Self, String> {
|
||||||
let token = std::env::var("TOKEN")
|
let token = std::env::var("TOKEN")
|
||||||
.map_err(|_| "TOKEN environment variable is required".to_string())?;
|
.map_err(|_| "TOKEN environment variable is required".to_string())?;
|
||||||
|
|
||||||
let device_id =
|
let device_id =
|
||||||
std::env::var("DEVICE_ID").unwrap_or_else(|_| Self::DEFAULT_DEVICE_ID.to_string());
|
std::env::var("DEVICE_ID").unwrap_or_else(|_| Self::DEFAULT_DEVICE_ID.to_string());
|
||||||
validate_device_id(&device_id).map_err(|e| format!("Invalid DEVICE_ID: {e}"))?;
|
validate_device_id(&device_id).map_err(|e| format!("Invalid DEVICE_ID: {e}"))?;
|
||||||
|
|
||||||
let base_url =
|
let base_url =
|
||||||
std::env::var("BASE_URL").unwrap_or_else(|_| Self::DEFAULT_BASE_URL.to_string());
|
std::env::var("BASE_URL").unwrap_or_else(|_| Self::DEFAULT_BASE_URL.to_string());
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use crate::app::{config::Config, protocol::ClientMsg};
|
|||||||
pub type Socket =
|
pub type Socket =
|
||||||
tokio_tungstenite::WebSocketStream<tokio_tungstenite::MaybeTlsStream<tokio::net::TcpStream>>;
|
tokio_tungstenite::WebSocketStream<tokio_tungstenite::MaybeTlsStream<tokio::net::TcpStream>>;
|
||||||
pub type SocketReader = SplitStream<Socket>;
|
pub type SocketReader = SplitStream<Socket>;
|
||||||
type SocketWriter = SplitSink<Socket, Message>;
|
pub type SocketWriter = SplitSink<Socket, Message>;
|
||||||
|
|
||||||
pub enum OutgoingMessage {
|
pub enum OutgoingMessage {
|
||||||
Application(ClientMsg),
|
Application(ClientMsg),
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
pub mod client;
|
|
||||||
pub mod command;
|
|
||||||
pub mod config;
|
|
||||||
pub mod connection;
|
|
||||||
pub mod protocol;
|
|
||||||
+7
-1
@@ -1,4 +1,10 @@
|
|||||||
mod app;
|
mod app {
|
||||||
|
pub mod client;
|
||||||
|
pub mod command;
|
||||||
|
pub mod config;
|
||||||
|
pub mod connection;
|
||||||
|
pub mod protocol;
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user