Skip to content

Commit a5554b5

Browse files
committed
fix all warnings
1 parent 6c66450 commit a5554b5

File tree

10 files changed

+62
-78
lines changed

10 files changed

+62
-78
lines changed

src/app_state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub struct AppState {
1515
pub config: Arc<Mutex<Config>>,
1616
pub slave_servers: Arc<Mutex<Vec<ServerInfo>>>,
1717
pub slave_connections: Arc<Mutex<Vec<SlaveConnection>>>,
18+
#[allow(dead_code)]
1819
pub global_crash_prevention: Arc<AtomicBool>,
1920
pub specialization_registry: Arc<SpecializationRegistry>,
2021
}

src/controlled_program.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl Drop for ControlledProgramInstance {
125125
// Attempt to kill the process if it's still running
126126
if let Some(id) = self.process.id() {
127127
// Try to kill the process gracefully
128-
let _ = self.process.kill();
128+
std::mem::drop(self.process.kill());
129129
tracing::info!(
130130
"Terminated server process '{}' (PID {}) on drop.",
131131
self.name,
@@ -143,7 +143,7 @@ impl ControlledProgramInstance {
143143
// Ensure the working directory exists, create if it doesn't
144144
let working_dir_path = Path::new(&working_dir);
145145
if !working_dir_path.exists() {
146-
if let Err(e) = fs::create_dir_all(&working_dir_path) {
146+
if let Err(e) = fs::create_dir_all(working_dir_path) {
147147
panic!(
148148
"Failed to create working directory {:?}: {}",
149149
working_dir_path, e
@@ -232,7 +232,7 @@ impl ControlledProgramInstance {
232232
if inp < 150 {
233233
inp = 0;
234234
} else {
235-
inp = inp - 150;
235+
inp -= 150;
236236
}
237237
self.curr_output_in_progress = lines[std::cmp::max(0, inp)..lines.len()].join("\n");
238238
if out.is_empty() {

src/main.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::{
2929
#[tokio::main]
3030
async fn main() -> Result<(), String> {
3131
let config = load_json("config.json");
32-
let slave: bool = config.slave.clone();
32+
let slave: bool = config.slave;
3333
tracing_subscriber::FmtSubscriber::builder()
3434
.pretty()
3535
.with_line_number(false)
@@ -42,17 +42,16 @@ async fn main() -> Result<(), String> {
4242
let (tx, _rx) = broadcast::channel(100);
4343
let specialization_registry = specializations::init_builtin_registry();
4444
let mut app_state = app_state::AppState::new(tx, config, specialization_registry);
45-
let handles: Vec<tokio::task::JoinHandle<()>>;
46-
if slave {
47-
handles = spawn_tasks!(app_state.clone(), start_servers, start_slave)
45+
let handles: Vec<tokio::task::JoinHandle<()>> = if slave {
46+
spawn_tasks!(app_state.clone(), start_servers, start_slave)
4847
} else {
49-
handles = spawn_tasks!(
48+
spawn_tasks!(
5049
app_state.clone(),
5150
start_web_server,
5251
start_servers,
5352
create_slave_connections
54-
);
55-
}
53+
)
54+
};
5655
{
5756
info!("Starting {} tasks", handles.len());
5857
}
@@ -72,7 +71,9 @@ async fn main() -> Result<(), String> {
7271
};
7372

7473
// Ctrl+C handler
74+
#[allow(unused_variables)]
7575
let app_state_clone_ctrlc = app_state.clone();
76+
let _app_state_clone_ctrlc = app_state.clone();
7677
tokio::spawn({
7778
let shutdown = shutdown.clone();
7879
async move {
@@ -83,7 +84,9 @@ async fn main() -> Result<(), String> {
8384
});
8485

8586
// T key handler
87+
#[allow(unused_variables)]
8688
let app_state_clone_t = app_state.clone();
89+
let _app_state_clone_t = app_state.clone();
8790
tokio::spawn({
8891
let shutdown = shutdown.clone();
8992
async move {
@@ -226,8 +229,10 @@ Theme files are JSON files that define colors for the UI. Each theme should have
226229
}
227230

228231
// Create custom theme example (purple-based theme)
229-
let mut custom_theme = Theme::default();
230-
custom_theme.name = "Purple Dream".to_string();
232+
let mut custom_theme = Theme {
233+
name: "Purple Dream".to_string(),
234+
..Theme::default()
235+
};
231236

232237
// Use public oklch function to create colors
233238
custom_theme.primary = oklch(0.7, 0.25, 290.0); // Vibrant purple

src/master.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ impl SlaveConnection {
6565
// Handle the message, e.g., if it's a text message
6666
if let Message::Text(text) = msg {
6767
let js: Result<Value, _> = serde_json::from_str(&text);
68-
let js2: Value;
69-
if js.is_ok() {
70-
js2 = js.unwrap();
68+
if let Ok(js2) = js {
7169
match js2["type"].as_str().unwrap() {
7270
"ServerInfo" => {
7371
let serde_res = serde_json::from_str(&text);
@@ -78,7 +76,8 @@ impl SlaveConnection {
7876
let s_message =
7977
serde_json::to_string(&_sinfo).unwrap();
8078
let s_def = serde_json::to_string(&def).unwrap();
81-
if s_message != s_def && _sinfo.servers.len() != 0 {
79+
if s_message != s_def && !_sinfo.servers.is_empty()
80+
{
8281
for server_info in _sinfo.servers.iter() {
8382
let new_info = ServerInfo {
8483
name: server_info.name.clone(),
@@ -138,6 +137,8 @@ impl SlaveConnection {
138137
Err("No active connection".into())
139138
}
140139
}
140+
141+
#[allow(dead_code)]
141142
pub async fn write_stdin(
142143
&mut self,
143144
server_name: String,
@@ -164,6 +165,7 @@ impl SlaveConnection {
164165
Ok(())
165166
}
166167
}
168+
167169
pub async fn create_slave_connections(state: AppState) {
168170
let mut slaves: Vec<SlaveConnection> = vec![];
169171
let conf = state.config.lock().await;

src/servers.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,22 @@ pub async fn process_stdout(state: AppState) {
115115
}
116116
//all of our process are valid at this point, no need to even be careful about it
117117
for server in servers.iter_mut() {
118-
let str = match tokio::time::timeout(
118+
let str = tokio::time::timeout(
119119
tokio::time::Duration::from_secs_f64(1. / 10.),
120120
server.read_output(),
121121
)
122122
.await
123-
{
124-
Ok(val) => val,
125-
_ => None,
126-
};
127-
match str {
128-
Some(val) => {
129-
if !val.is_empty() {
130-
let out = ConsoleOutput {
131-
r#type: "ServerOutput".to_owned(),
132-
output: val,
133-
server_name: server.name.clone(),
134-
server_type: server.specialized_server_type.clone(),
135-
};
136-
let _ = state.tx.send(serde_json::to_string(&out).unwrap());
137-
}
123+
.unwrap_or_default();
124+
if let Some(val) = str {
125+
if !val.is_empty() {
126+
let out = ConsoleOutput {
127+
r#type: "ServerOutput".to_owned(),
128+
output: val,
129+
server_name: server.name.clone(),
130+
server_type: server.specialized_server_type.clone(),
131+
};
132+
let _ = state.tx.send(serde_json::to_string(&out).unwrap());
138133
}
139-
140-
_ => {}
141134
}
142135
}
143136
drop(servers);

src/specializations/minecraft.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use serde_json::{json, Value};
77
use std::path::Path;
88

99
/// Minecraft specialization struct.
10-
/// Holds any state needed for Minecraft-specific logic.
10+
1111
#[derive(Default)]
12+
1213
pub struct MinecraftSpecialization {
1314
// No internal state needed; all info is stored in ControlledProgramInstance
1415
}
@@ -57,6 +58,7 @@ impl ServerSpecialization for MinecraftSpecialization {
5758
// Ready regex
5859
let ready_pattern = Regex::new(r#"Done \(\d+\.\d+s\)! For help, type "help""#).unwrap();
5960

61+
#[allow(clippy::type_complexity)]
6062
let mut update_info =
6163
|f: &mut dyn FnMut(&mut usize, usize, &mut bool, &mut Vec<String>)| {
6264
if let Some(Value::Object(ref mut obj)) = instance.specialized_server_info {

src/specializations/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,14 @@ use std::sync::Arc;
99

1010
pub trait ServerSpecialization: Send + Sync {
1111
/// Called when the specialization is first attached to a server instance.
12-
1312
fn init(&mut self, instance: &mut ControlledProgramInstance);
14-
1513
/// Called for each output line from the server process.
16-
1714
/// Takes ownership of the log line. Return Some(String) to transform the line, None to omit it.
18-
1915
fn parse_output(
2016
&mut self,
21-
2217
line: String,
23-
2418
instance: &mut ControlledProgramInstance,
2519
) -> Option<String>;
26-
2720
/// Called when the server process exits.
2821
/// Allows the specialization to handle exit-specific logic (e.g., EULA patching, auto-restart).
2922
/// Default implementation does nothing.
@@ -35,11 +28,8 @@ pub trait ServerSpecialization: Send + Sync {
3528
) {
3629
// Default: do nothing
3730
}
38-
3931
/// Returns the current status/info for this specialization.
40-
4132
#[allow(unused)]
42-
4333
fn get_status(&self) -> serde_json::Value;
4434
}
4535

@@ -93,7 +83,3 @@ pub fn init_builtin_registry() -> Arc<SpecializationRegistry> {
9383
registry.register("Terraria", terraria::factory);
9484
registry
9585
}
96-
97-
// pub mod minecraft;
98-
// pub mod terraria;
99-
// (Uncomment and implement these modules as you migrate logic.)

src/theme.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use std::io::{self, Write};
99
use std::path::{Path, PathBuf};
1010

1111
/// Represents the available color spaces that can be used for themes
12-
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
12+
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Default)]
1313
pub enum ThemeColorSpace {
14+
#[default]
1415
Oklch,
1516
Oklab,
1617
Lch,
@@ -26,12 +27,6 @@ pub enum ThemeColorSpace {
2627
Xyz,
2728
}
2829

29-
impl Default for ThemeColorSpace {
30-
fn default() -> Self {
31-
ThemeColorSpace::Oklch // Default to Oklch as it's perceptually uniform and uses polar coordinates
32-
}
33-
}
34-
3530
/// A struct representing a complete theme for the application
3631
/// Contains all CSS variables needed to style the UI
3732
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -103,9 +98,10 @@ fn oklab_to_color(l: f64, a: f64, b: f64, alpha: f64) -> Color {
10398
impl Theme {
10499
/// Creates a new theme with the specified name
105100
pub fn new(name: &str) -> Self {
106-
let mut theme = Self::default();
107-
theme.name = name.to_string();
108-
theme
101+
Self {
102+
name: name.to_string(),
103+
..Self::default()
104+
}
109105
}
110106

111107
/// Create a light theme variant
@@ -309,7 +305,7 @@ impl Theme {
309305
let path = entry.path();
310306

311307
// Only check JSON files
312-
if path.extension().map_or(false, |ext| ext == "json") {
308+
if path.extension().is_some_and(|ext| ext == "json") {
313309
if let Ok(json) = fs::read_to_string(&path) {
314310
if let Ok(theme) = serde_json::from_str::<Theme>(&json) {
315311
if theme.name == theme_name {
@@ -506,7 +502,7 @@ impl ThemeCollection {
506502
let path = entry.path();
507503

508504
// Only process JSON files
509-
if path.extension().map_or(false, |ext| ext == "json") {
505+
if path.extension().is_some_and(|ext| ext == "json") {
510506
match Theme::load_from_file(&path) {
511507
Ok(theme) => {
512508
collection.add_theme(theme);

src/webserver.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ async fn get_router(_state: AppState) -> Router<AppState> {
2929
}
3030
async fn handle_icon(State(_state): State<AppState>) -> impl IntoResponse {
3131
let ico_bytes: &'static [u8] = include_bytes!("html_src/icon.ico");
32-
let response = Response::builder()
32+
Response::builder()
3333
.status(StatusCode::OK)
3434
.header("Content-Type", "image/x-icon")
3535
.body(Body::from(ico_bytes))
36-
.unwrap();
37-
38-
response
36+
.unwrap()
3937
}
4038
#[no_mangle]
4139
pub async fn start_web_server(_state: AppState) {

src/websocket.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ fn utf8bytes_to_string(bytes: Utf8Bytes) -> String {
2121
bytes.to_string()
2222
}
2323

24+
#[allow(unused_imports)]
25+
use crate::master::SlaveConnection;
26+
#[allow(unused_imports)]
27+
use crate::servers::send_termination_message;
2428
use crate::{
2529
app_state::AppState, configuration::Config, controlled_program::ControlledProgramDescriptor,
26-
master::SlaveConnection, messages::*, servers::send_termination_message,
27-
theme::ThemeCollection,
30+
messages::*, theme::ThemeCollection,
2831
};
2932
#[no_mangle]
3033
pub async fn handle_ws_upgrade(ws: WebSocketUpgrade, State(state): State<AppState>) -> Response {
@@ -127,10 +130,8 @@ async fn process_message(text: String, state: AppState) {
127130
.unwrap_or_else(|| "themes".to_string());
128131
drop(config);
129132

130-
let theme_collection = match ThemeCollection::load_from_directory(&themes_folder) {
131-
Ok(collection) => collection,
132-
Err(_) => ThemeCollection::default(),
133-
};
133+
let theme_collection =
134+
ThemeCollection::load_from_directory(&themes_folder).unwrap_or_default();
134135

135136
let theme_names: Vec<String> = theme_collection
136137
.themes
@@ -148,6 +149,7 @@ async fn process_message(text: String, state: AppState) {
148149
}
149150
"getThemeCSS" => {
150151
#[derive(Deserialize)]
152+
#[allow(dead_code)]
151153
struct GetThemeCSSWeb {
152154
r#type: String,
153155
theme_name: String,
@@ -169,10 +171,8 @@ async fn process_message(text: String, state: AppState) {
169171
.unwrap_or_else(|| "themes".to_string());
170172
drop(config);
171173

172-
let theme_collection = match ThemeCollection::load_from_directory(&themes_folder) {
173-
Ok(collection) => collection,
174-
Err(_) => ThemeCollection::default(),
175-
};
174+
let theme_collection =
175+
ThemeCollection::load_from_directory(&themes_folder).unwrap_or_default();
176176

177177
let css = if let Some(theme) = theme_collection
178178
.themes
@@ -227,14 +227,14 @@ async fn process_message(text: String, state: AppState) {
227227
specialized_info: server.specialized_server_info.clone(),
228228
host: None,
229229
};
230-
if val.arguments.get(0).copied().unwrap_or(false) {
230+
if val.arguments.first().copied().unwrap_or(false) {
231231
let cl: String = server.curr_output_in_progress.clone();
232232
let split: Vec<&str> = cl.split("\n").collect();
233233
let mut inp = split.len();
234234
if inp < 150 {
235235
inp = 0;
236236
} else {
237-
inp = inp - 150;
237+
inp -= 150;
238238
}
239239
s_info.output = split[inp..split.len()].join("\n");
240240
}
@@ -283,7 +283,7 @@ async fn process_message(text: String, state: AppState) {
283283
drop(servers);
284284
let config = state.config.lock().await;
285285
#[allow(unused)]
286-
let slave = config.slave.clone();
286+
let slave = config.slave;
287287
drop(config);
288288
// If not active, and value is "start", start the server
289289
if !is_active_server && value.value == "start" {
@@ -311,6 +311,7 @@ async fn process_message(text: String, state: AppState) {
311311
}
312312
"configChange" => {
313313
#[derive(Deserialize)]
314+
#[allow(dead_code)]
314315
struct ConfigChangeMessage {
315316
r#type: String,
316317
#[serde(alias = "updatedConfig", alias = "updated_config")]

0 commit comments

Comments
 (0)