fix: resolve clippy issues
This commit is contained in:
1 parent
eb91c908fc
commit
971375bf1f
18 files changed
+80
-116
No files matched your search
@@ -40,12 +40,11 @@ impl AccountStore {
|
||||
}
|
||||
|
||||
pub fn save(&self) {
|
||||
if let Some(parent) = self.path.parent() {
|
||||
if let Err(e) = std::fs::create_dir_all(parent) {
|
||||
if let Some(parent) = self.path.parent()
|
||||
&& let Err(e) = std::fs::create_dir_all(parent) {
|
||||
tracing::error!("Failed to create accounts directory: {}", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
match serde_json::to_string_pretty(&self.accounts) {
|
||||
Ok(json) => {
|
||||
if let Err(e) = std::fs::write(&self.path, json) {
|
||||
|
||||
+4
-6
@@ -73,19 +73,18 @@ async fn add_microsoft_account() -> CliResult {
|
||||
let result_arc = crate::auth::start_microsoft_auth();
|
||||
|
||||
loop {
|
||||
if let Ok(slot) = crate::auth::DEVICE_CODE_DISPLAY.lock() {
|
||||
if let Some(info) = slot.as_ref() {
|
||||
if let Ok(slot) = crate::auth::DEVICE_CODE_DISPLAY.lock()
|
||||
&& let Some(info) = slot.as_ref() {
|
||||
println!("Open: {}", info.verification_uri);
|
||||
println!("Code: {}", info.user_code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(200)).await;
|
||||
}
|
||||
|
||||
loop {
|
||||
if let Ok(slot) = result_arc.lock() {
|
||||
if let Some(result) = slot.as_ref() {
|
||||
if let Ok(slot) = result_arc.lock()
|
||||
&& let Some(result) = slot.as_ref() {
|
||||
return match result {
|
||||
AuthResult::Success(account) => {
|
||||
let mut store = AccountStore::load();
|
||||
@@ -96,7 +95,6 @@ async fn add_microsoft_account() -> CliResult {
|
||||
AuthResult::Error(message) => Err(io::Error::other(message.clone()).into()),
|
||||
};
|
||||
}
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,11 +48,10 @@ pub fn resolve_path(raw: &str) -> PathBuf {
|
||||
if let Some(home) = dirs_next::home_dir() {
|
||||
return home.join(stripped);
|
||||
}
|
||||
} else if raw == "~" {
|
||||
if let Some(home) = dirs_next::home_dir() {
|
||||
} else if raw == "~"
|
||||
&& let Some(home) = dirs_next::home_dir() {
|
||||
return home;
|
||||
}
|
||||
}
|
||||
PathBuf::from(raw)
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -141,15 +141,14 @@ fn load_base_theme(name: &str) -> Box<dyn Theme> {
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(path) = path {
|
||||
if let Ok(content) = std::fs::read_to_string(&path) {
|
||||
if let Some(path) = path
|
||||
&& let Ok(content) = std::fs::read_to_string(&path) {
|
||||
if let Ok(custom) = toml::from_str::<CustomTheme>(&content) {
|
||||
return Box::new(custom);
|
||||
} else {
|
||||
tracing::warn!("Failed to parse theme file: {}", path.display());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to built-in theme by name
|
||||
resolve_theme(name)
|
||||
|
||||
@@ -18,11 +18,7 @@ pub(crate) fn parse_enabled_stem(file_name: &str, ext: &str) -> Option<(bool, St
|
||||
let disabled_ext = format!("{ext}.disabled");
|
||||
if let Some(stem) = file_name.strip_suffix(&disabled_ext) {
|
||||
Some((false, stem.to_string()))
|
||||
} else if let Some(stem) = file_name.strip_suffix(ext) {
|
||||
Some((true, stem.to_string()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else { file_name.strip_suffix(ext).map(|stem| (true, stem.to_string())) }
|
||||
}
|
||||
|
||||
/// For directories: check if the name ends in `.disabled`.
|
||||
|
||||
@@ -71,17 +71,15 @@ fn world_description(world_dir: &Path) -> String {
|
||||
|
||||
let mut lines = Vec::new();
|
||||
|
||||
if let Some(secs) = created {
|
||||
if let Some(dt) = chrono::DateTime::from_timestamp(secs as i64, 0) {
|
||||
if let Some(secs) = created
|
||||
&& let Some(dt) = chrono::DateTime::from_timestamp(secs as i64, 0) {
|
||||
lines.push(format!("Created: {}", dt.format("%Y-%m-%d %H:%M")));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(secs) = modified {
|
||||
if let Some(dt) = chrono::DateTime::from_timestamp(secs as i64, 0) {
|
||||
if let Some(secs) = modified
|
||||
&& let Some(dt) = chrono::DateTime::from_timestamp(secs as i64, 0) {
|
||||
lines.push(format!("Played: {}", dt.format("%Y-%m-%d %H:%M")));
|
||||
}
|
||||
}
|
||||
|
||||
if dir_size > 0 {
|
||||
lines.push(format!("Size: {}", format_size(dir_size)));
|
||||
@@ -94,11 +92,10 @@ fn dir_size_approx(path: &Path) -> u64 {
|
||||
let mut total = 0u64;
|
||||
if let Ok(rd) = std::fs::read_dir(path) {
|
||||
for entry in rd.flatten() {
|
||||
if let Ok(meta) = entry.metadata() {
|
||||
if meta.is_file() {
|
||||
if let Ok(meta) = entry.metadata()
|
||||
&& meta.is_file() {
|
||||
total += meta.len();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check region folder too (main chunk data)
|
||||
|
||||
@@ -220,8 +220,8 @@ pub async fn launch(
|
||||
}
|
||||
crate::auth::AccountType::Offline => ("0".to_string(), None),
|
||||
};
|
||||
if let Some(new_rt) = new_refresh {
|
||||
if let Some(stored) = account_store
|
||||
if let Some(new_rt) = new_refresh
|
||||
&& let Some(stored) = account_store
|
||||
.accounts
|
||||
.iter_mut()
|
||||
.find(|a| a.uuid == acc.uuid)
|
||||
@@ -229,7 +229,6 @@ pub async fn launch(
|
||||
stored.refresh_token = Some(new_rt);
|
||||
account_store.save();
|
||||
}
|
||||
}
|
||||
let user_type = match acc.account_type {
|
||||
crate::auth::AccountType::Microsoft => "msa",
|
||||
crate::auth::AccountType::Offline => "legacy",
|
||||
@@ -321,11 +320,10 @@ pub async fn launch(
|
||||
while let Ok(Some(line)) = lines.next_line().await {
|
||||
tracing::info!(target: "mc_instance", "[{}] {}", n, line);
|
||||
crate::instance_logs::push(&n, &line);
|
||||
if let Ok(mut f) = w.lock() {
|
||||
if let Some(f) = f.as_mut() {
|
||||
if let Ok(mut f) = w.lock()
|
||||
&& let Some(f) = f.as_mut() {
|
||||
let _ = writeln!(f, "{}", line);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -338,11 +336,10 @@ pub async fn launch(
|
||||
while let Ok(Some(line)) = lines.next_line().await {
|
||||
tracing::warn!(target: "mc_instance", "[{}] {}", n, line);
|
||||
crate::instance_logs::push(&n, &line);
|
||||
if let Ok(mut f) = w.lock() {
|
||||
if let Some(f) = f.as_mut() {
|
||||
if let Ok(mut f) = w.lock()
|
||||
&& let Some(f) = f.as_mut() {
|
||||
let _ = writeln!(f, "[STDERR] {}", line);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -209,8 +209,8 @@ impl InstanceManager {
|
||||
std::fs::rename(&old_dir, &new_dir)?;
|
||||
|
||||
let config_path = new_dir.join("instance.json");
|
||||
if let Ok(data) = std::fs::read_to_string(&config_path) {
|
||||
if let Ok(mut config) = serde_json::from_str::<InstanceConfig>(&data) {
|
||||
if let Ok(data) = std::fs::read_to_string(&config_path)
|
||||
&& let Ok(mut config) = serde_json::from_str::<InstanceConfig>(&data) {
|
||||
config.name = new_name.to_string();
|
||||
if let Ok(json) = serde_json::to_string_pretty(&config) {
|
||||
let _ = std::fs::write(&config_path, json);
|
||||
@@ -219,7 +219,6 @@ impl InstanceManager {
|
||||
tracing::warn!("Failed to rename desktop shortcut: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -14,5 +14,6 @@ async fn main() {
|
||||
if let Err(e) = color_eyre::install() {
|
||||
eprintln!("Failed to install color-eyre: {}", e);
|
||||
}
|
||||
|
||||
cli::init().await
|
||||
}
|
||||
+2
-3
@@ -63,8 +63,8 @@ pub async fn fetch_neoforge_game_versions(
|
||||
let mut game_versions: Vec<String> = Vec::new();
|
||||
for version in &maven.versions {
|
||||
let parts: Vec<&str> = version.split('.').collect();
|
||||
if parts.len() >= 2 {
|
||||
if let (Ok(major), Ok(minor)) = (parts[0].parse::<u32>(), parts[1].parse::<u32>()) {
|
||||
if parts.len() >= 2
|
||||
&& let (Ok(major), Ok(minor)) = (parts[0].parse::<u32>(), parts[1].parse::<u32>()) {
|
||||
let mc_version = if minor == 0 {
|
||||
format!("1.{}", major)
|
||||
} else {
|
||||
@@ -75,7 +75,6 @@ pub async fn fetch_neoforge_game_versions(
|
||||
game_versions.push(mc_version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
game_versions.reverse();
|
||||
|
||||
|
||||
+2
-3
@@ -69,12 +69,11 @@ pub fn register_kill(name: &str, tx: tokio::sync::oneshot::Sender<()>) {
|
||||
}
|
||||
|
||||
pub fn send_kill(name: &str) -> bool {
|
||||
if let Ok(mut map) = KILL_SENDERS.lock() {
|
||||
if let Some(tx) = map.remove(name) {
|
||||
if let Ok(mut map) = KILL_SENDERS.lock()
|
||||
&& let Some(tx) = map.remove(name) {
|
||||
let _ = tx.send(());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -189,14 +189,13 @@ impl App {
|
||||
if let Err(e) = result {
|
||||
tracing::error!("Failed to open editor: {}", e);
|
||||
}
|
||||
} else if let Err(e) = std::process::Command::new(&editor)
|
||||
} else { if let Err(e) = std::process::Command::new(&editor)
|
||||
.arg(path)
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
.spawn()
|
||||
{
|
||||
.spawn() {
|
||||
tracing::error!("Failed to open editor: {}", e);
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
pub(super) fn spawn_launch(&self, instance: crate::instance::InstanceConfig) {
|
||||
|
||||
+2
-3
@@ -107,11 +107,10 @@ impl App {
|
||||
widgets::content::ContentTab::Shaders => Some(&mut self.shaders_state),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(state) = state {
|
||||
if widgets::content::list::handle_key(&key_event, state) {
|
||||
if let Some(state) = state
|
||||
&& widgets::content::list::handle_key(&key_event, state) {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,11 +53,11 @@ impl Default for AccountState {
|
||||
impl AccountState {
|
||||
pub fn drain_auth_result(&mut self) {
|
||||
if let AddMode::DeviceCodeWaiting { pending, .. } = &self.add_mode {
|
||||
let result = if let Ok(mut slot) = pending.lock() {
|
||||
let result = match pending.lock() { Ok(mut slot) => {
|
||||
slot.take()
|
||||
} else {
|
||||
} _ => {
|
||||
None
|
||||
};
|
||||
}};
|
||||
|
||||
if let Some(result) = result {
|
||||
match result {
|
||||
@@ -200,16 +200,13 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut AccountState) -> bool {
|
||||
}
|
||||
|
||||
pub fn drain_device_code(state: &mut AccountState) {
|
||||
if let AddMode::DeviceCodeWaiting { info, .. } = &mut state.add_mode {
|
||||
if info.user_code.is_empty() {
|
||||
if let Ok(mut slot) = auth::DEVICE_CODE_DISPLAY.lock() {
|
||||
if let Some(dc_info) = slot.take() {
|
||||
if let AddMode::DeviceCodeWaiting { info, .. } = &mut state.add_mode
|
||||
&& info.user_code.is_empty()
|
||||
&& let Ok(mut slot) = auth::DEVICE_CODE_DISPLAY.lock()
|
||||
&& let Some(dc_info) = slot.take() {
|
||||
info.user_code = dc_info.user_code;
|
||||
info.verification_uri = dc_info.verification_uri;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut AccountState) {
|
||||
|
||||
@@ -104,8 +104,8 @@ impl ContentListState {
|
||||
where
|
||||
F: FnOnce(&Path, &str) -> Vec<ContentEntry> + Send + 'static,
|
||||
{
|
||||
if let Some(prev) = self.loaded_for.take() {
|
||||
if !self.entries.is_empty() {
|
||||
if let Some(prev) = self.loaded_for.take()
|
||||
&& !self.entries.is_empty() {
|
||||
self.cache.insert(
|
||||
prev,
|
||||
CachedList {
|
||||
@@ -114,7 +114,6 @@ impl ContentListState {
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(cached) = self.cache.remove(instance_name) {
|
||||
self.entries = cached.entries;
|
||||
@@ -147,14 +146,14 @@ impl ContentListState {
|
||||
}
|
||||
|
||||
pub fn drain_pending(&mut self) {
|
||||
let taken = if let Ok(mut slot) = self.pending.lock() {
|
||||
let taken = match self.pending.lock() { Ok(mut slot) => {
|
||||
slot.take()
|
||||
} else {
|
||||
} _ => {
|
||||
None
|
||||
};
|
||||
}};
|
||||
|
||||
if let Some((instance_name, entries)) = taken {
|
||||
if self.loaded_for.as_deref() == Some(&instance_name) || instance_name.is_empty() {
|
||||
if let Some((instance_name, entries)) = taken
|
||||
&& (self.loaded_for.as_deref() == Some(&instance_name) || instance_name.is_empty()) {
|
||||
let selected_name = self
|
||||
.list_state
|
||||
.selected
|
||||
@@ -176,7 +175,6 @@ impl ContentListState {
|
||||
}
|
||||
self.update_scrollbar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_scrollbar(&mut self) {
|
||||
@@ -279,13 +277,11 @@ pub fn handle_key_no_toggle(key_event: &KeyEvent, state: &mut ContentListState)
|
||||
true
|
||||
}
|
||||
KeyCode::Enter if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
|
||||
if let Some(&real_idx) = state.list_state.selected.and_then(|i| filtered.get(i)) {
|
||||
if let Some(dir) = state.entries[real_idx].path.parent() {
|
||||
if let Err(e) = open::that(dir) {
|
||||
if let Some(&real_idx) = state.list_state.selected.and_then(|i| filtered.get(i))
|
||||
&& let Some(dir) = state.entries[real_idx].path.parent()
|
||||
&& let Err(e) = open::that(dir) {
|
||||
tracing::error!("Failed to open directory: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
@@ -316,13 +312,11 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ContentListState) -> bool {
|
||||
true
|
||||
}
|
||||
KeyCode::Enter if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
|
||||
if let Some(&real_idx) = state.list_state.selected.and_then(|i| filtered.get(i)) {
|
||||
if let Some(dir) = state.entries[real_idx].path.parent() {
|
||||
if let Err(e) = open::that(dir) {
|
||||
if let Some(&real_idx) = state.list_state.selected.and_then(|i| filtered.get(i))
|
||||
&& let Some(dir) = state.entries[real_idx].path.parent()
|
||||
&& let Err(e) = open::that(dir) {
|
||||
tracing::error!("Failed to open directory: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
@@ -565,8 +559,8 @@ fn parse_mc_text(text: &str, base_style: Style) -> Vec<Span<'static>> {
|
||||
let mut chars = text.chars().peekable();
|
||||
|
||||
while let Some(ch) = chars.next() {
|
||||
if ch == '\u{00A7}' {
|
||||
if let Some(&code) = chars.peek() {
|
||||
if ch == '\u{00A7}'
|
||||
&& let Some(&code) = chars.peek() {
|
||||
if !current_text.is_empty() {
|
||||
spans.push(Span::styled(current_text.clone(), current_style));
|
||||
current_text.clear();
|
||||
@@ -597,7 +591,6 @@ fn parse_mc_text(text: &str, base_style: Style) -> Vec<Span<'static>> {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
current_text.push(ch);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,14 +89,14 @@ impl LogsState {
|
||||
}
|
||||
|
||||
pub fn drain_pending(&mut self) {
|
||||
let taken = if let Ok(mut slot) = self.pending.lock() {
|
||||
let taken = match self.pending.lock() { Ok(mut slot) => {
|
||||
slot.take()
|
||||
} else {
|
||||
} _ => {
|
||||
None
|
||||
};
|
||||
}};
|
||||
|
||||
if let Some((instance_name, entries)) = taken {
|
||||
if self.loaded_for.as_deref() == Some(&instance_name) {
|
||||
if let Some((instance_name, entries)) = taken
|
||||
&& self.loaded_for.as_deref() == Some(&instance_name) {
|
||||
let prev_selected = self.list_state.selected;
|
||||
self.entries = entries;
|
||||
self.loading = false;
|
||||
@@ -106,14 +106,12 @@ impl LogsState {
|
||||
if display_count > 0 && prev_selected.is_none() {
|
||||
self.list_state.selected = Some(0);
|
||||
self.load_selected_content();
|
||||
} else if let Some(sel) = prev_selected {
|
||||
if sel >= display_count && display_count > 0 {
|
||||
} else if let Some(sel) = prev_selected
|
||||
&& sel >= display_count && display_count > 0 {
|
||||
self.list_state.selected = Some(display_count - 1);
|
||||
}
|
||||
}
|
||||
self.update_scrollbar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_rescan(&mut self) {
|
||||
|
||||
@@ -91,28 +91,27 @@ impl ScreenshotsState {
|
||||
}
|
||||
|
||||
pub fn drain_pending_entries(&mut self) {
|
||||
let taken = if let Ok(mut slot) = self.pending_entries.lock() {
|
||||
let taken = match self.pending_entries.lock() { Ok(mut slot) => {
|
||||
slot.take()
|
||||
} else {
|
||||
} _ => {
|
||||
None
|
||||
};
|
||||
}};
|
||||
|
||||
if let Some((instance_name, entries)) = taken {
|
||||
if self.loaded_for.as_deref() == Some(&instance_name) {
|
||||
if let Some((instance_name, entries)) = taken
|
||||
&& self.loaded_for.as_deref() == Some(&instance_name) {
|
||||
self.entries = entries;
|
||||
self.loading = false;
|
||||
self.selected = 0;
|
||||
self.scroll_row = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn take_pending_images(&mut self) -> Vec<(usize, image::DynamicImage)> {
|
||||
if let Ok(mut slot) = self.pending_images.lock() {
|
||||
match self.pending_images.lock() { Ok(mut slot) => {
|
||||
std::mem::take(&mut *slot)
|
||||
} else {
|
||||
} _ => {
|
||||
Vec::new()
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
pub fn set_protocol(&mut self, idx: usize, proto: StatefulProtocol) {
|
||||
@@ -138,11 +137,10 @@ impl ScreenshotsState {
|
||||
.await
|
||||
.unwrap_or(None);
|
||||
|
||||
if let Some(img) = img {
|
||||
if let Ok(mut slot) = pending.lock() {
|
||||
if let Some(img) = img
|
||||
&& let Ok(mut slot) = pending.lock() {
|
||||
slot.push((idx, img));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -217,21 +215,18 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ScreenshotsState) -> bool {
|
||||
true
|
||||
}
|
||||
KeyCode::Enter if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
|
||||
if let Some(entry) = state.entries.get(state.selected) {
|
||||
if let Some(dir) = entry.path.parent() {
|
||||
if let Err(e) = open::that(dir) {
|
||||
if let Some(entry) = state.entries.get(state.selected)
|
||||
&& let Some(dir) = entry.path.parent()
|
||||
&& let Err(e) = open::that(dir) {
|
||||
tracing::error!("Failed to open directory: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if let Some(entry) = state.entries.get(state.selected) {
|
||||
if let Err(e) = open::that(&entry.path) {
|
||||
if let Some(entry) = state.entries.get(state.selected)
|
||||
&& let Err(e) = open::that(&entry.path) {
|
||||
tracing::error!("Failed to open file: {}", e);
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
KeyCode::Char('L') | KeyCode::Right
|
||||
|
||||
Reference in new issue
Block a user