fix: resolve clippy warnings
This commit is contained in:
1 parent
0ec95e51e4
commit
4f597d04b2
12 files changed
+48
-42
No files matched your search
+1
-1
@@ -87,7 +87,7 @@ async fn create_instance(matches: &ArgMatches) -> CliResult {
|
|||||||
let name = required_arg(matches, "name")?;
|
let name = required_arg(matches, "name")?;
|
||||||
let version = required_arg(matches, "version")?;
|
let version = required_arg(matches, "version")?;
|
||||||
let loader = parse_loader(required_arg(matches, "loader")?)
|
let loader = parse_loader(required_arg(matches, "loader")?)
|
||||||
.map_err(|message| io::Error::other(message))?;
|
.map_err(io::Error::other)?;
|
||||||
let loader_version = matches.get_one::<String>("loader-version").map(String::as_str);
|
let loader_version = matches.get_one::<String>("loader-version").map(String::as_str);
|
||||||
let manager = manager();
|
let manager = manager();
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ use std::sync::{Arc, Mutex};
|
|||||||
|
|
||||||
const MAX_LINES: usize = 2000;
|
const MAX_LINES: usize = 2000;
|
||||||
|
|
||||||
pub static LOGS: Lazy<Arc<Mutex<HashMap<String, VecDeque<String>>>>> =
|
type LogsMap = Arc<Mutex<HashMap<String, VecDeque<String>>>>;
|
||||||
Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));
|
pub static LOGS: Lazy<LogsMap> = Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));
|
||||||
|
|
||||||
pub fn push(name: &str, line: impl Into<String>) {
|
pub fn push(name: &str, line: impl Into<String>) {
|
||||||
if let Ok(mut logs) = LOGS.lock() {
|
if let Ok(mut logs) = LOGS.lock() {
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ pub struct HttpClient {
|
|||||||
inner: Client,
|
inner: Client,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for HttpClient {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl HttpClient {
|
impl HttpClient {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
match Client::builder()
|
match Client::builder()
|
||||||
|
|||||||
+8
-11
@@ -116,19 +116,16 @@ pub async fn fetch_neoforge_game_versions(
|
|||||||
for version in &maven.versions {
|
for version in &maven.versions {
|
||||||
let parts: Vec<&str> = version.split('.').collect();
|
let parts: Vec<&str> = version.split('.').collect();
|
||||||
if parts.len() >= 2 {
|
if parts.len() >= 2 {
|
||||||
match (parts[0].parse::<u32>(), parts[1].parse::<u32>()) {
|
if let (Ok(major), Ok(minor)) = (parts[0].parse::<u32>(), parts[1].parse::<u32>()) {
|
||||||
(Ok(major), Ok(minor)) => {
|
let mc_version = if minor == 0 {
|
||||||
let mc_version = if minor == 0 {
|
format!("1.{}", major)
|
||||||
format!("1.{}", major)
|
} else {
|
||||||
} else {
|
format!("1.{}.{}", major, minor)
|
||||||
format!("1.{}.{}", major, minor)
|
};
|
||||||
};
|
|
||||||
|
|
||||||
if !game_versions.contains(&mc_version) {
|
if !game_versions.contains(&mc_version) {
|
||||||
game_versions.push(mc_version);
|
game_versions.push(mc_version);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -14,11 +14,12 @@ pub enum RunState {
|
|||||||
pub static RUNNING: Lazy<Arc<Mutex<HashMap<String, RunState>>>> =
|
pub static RUNNING: Lazy<Arc<Mutex<HashMap<String, RunState>>>> =
|
||||||
Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));
|
Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));
|
||||||
|
|
||||||
pub static PENDING_LAST_PLAYED: Lazy<Arc<Mutex<Vec<(String, DateTime<Utc>)>>>> =
|
type PendingLastPlayed = Arc<Mutex<Vec<(String, DateTime<Utc>)>>>;
|
||||||
|
pub static PENDING_LAST_PLAYED: Lazy<PendingLastPlayed> =
|
||||||
Lazy::new(|| Arc::new(Mutex::new(Vec::new())));
|
Lazy::new(|| Arc::new(Mutex::new(Vec::new())));
|
||||||
|
|
||||||
pub static KILL_SENDERS: Lazy<Arc<Mutex<HashMap<String, tokio::sync::oneshot::Sender<()>>>>> =
|
type KillSenders = Arc<Mutex<HashMap<String, tokio::sync::oneshot::Sender<()>>>>;
|
||||||
Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));
|
pub static KILL_SENDERS: Lazy<KillSenders> = Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));
|
||||||
|
|
||||||
pub fn set_state(name: &str, state: RunState) {
|
pub fn set_state(name: &str, state: RunState) {
|
||||||
if let Ok(mut map) = RUNNING.lock() {
|
if let Ok(mut map) = RUNNING.lock() {
|
||||||
|
|||||||
+7
-11
@@ -147,7 +147,7 @@ impl App {
|
|||||||
self.screenshots_state.request_visible_loads();
|
self.screenshots_state.request_visible_loads();
|
||||||
self.create_screenshot_protocols();
|
self.create_screenshot_protocols();
|
||||||
self.throbber_tick = self.throbber_tick.wrapping_add(1);
|
self.throbber_tick = self.throbber_tick.wrapping_add(1);
|
||||||
if self.throbber_tick % 8 == 0 {
|
if self.throbber_tick.is_multiple_of(8) {
|
||||||
self.throbber_state.calc_next();
|
self.throbber_state.calc_next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,13 +241,10 @@ impl App {
|
|||||||
let mut next_y: u16 = 1;
|
let mut next_y: u16 = 1;
|
||||||
for event in all_errors {
|
for event in all_errors {
|
||||||
let elapsed_ms = event.pushed_at.elapsed().as_millis();
|
let elapsed_ms = event.pushed_at.elapsed().as_millis();
|
||||||
match popup_area(frame.area(), &event.message, next_y, elapsed_ms) {
|
if let Some(area) = popup_area(frame.area(), &event.message, next_y, elapsed_ms) {
|
||||||
Some(area) => {
|
next_y = next_y.saturating_add(area.height + 1);
|
||||||
next_y = next_y.saturating_add(area.height + 1);
|
frame.render_widget(ErrorPopup::new(event.clone()), area);
|
||||||
frame.render_widget(ErrorPopup::new(event.clone()), area);
|
self.render_error_effect(frame, area, &event, elapsed_ms);
|
||||||
self.render_error_effect(frame, area, &event, elapsed_ms);
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,11 +392,10 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.focused == FocusedArea::Account {
|
if self.focused == FocusedArea::Account
|
||||||
if widgets::account::handle_key(&key_event, &mut self.account_state) {
|
&& widgets::account::handle_key(&key_event, &mut self.account_state) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if self.focused == FocusedArea::Settings {
|
if self.focused == FocusedArea::Settings {
|
||||||
match widgets::details::handle_key(
|
match widgets::details::handle_key(
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ impl ContentTab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn render(
|
pub fn render(
|
||||||
frame: &mut Frame,
|
frame: &mut Frame,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ use crate::instance::mods::ModEntry;
|
|||||||
use crate::tui::theme::THEME;
|
use crate::tui::theme::THEME;
|
||||||
|
|
||||||
type IconCell = (u8, u8, u8, u8, u8, u8);
|
type IconCell = (u8, u8, u8, u8, u8, u8);
|
||||||
|
type PendingContent = Arc<Mutex<Option<(String, Vec<ModEntry>)>>>;
|
||||||
|
type SnapshotRow = (String, String, bool, Option<Vec<Vec<IconCell>>>);
|
||||||
|
|
||||||
struct CachedList {
|
struct CachedList {
|
||||||
entries: Vec<ModEntry>,
|
entries: Vec<ModEntry>,
|
||||||
@@ -30,7 +32,7 @@ pub struct ContentListState {
|
|||||||
pub loading: bool,
|
pub loading: bool,
|
||||||
pub search: super::search::SearchState,
|
pub search: super::search::SearchState,
|
||||||
cache: HashMap<String, CachedList>,
|
cache: HashMap<String, CachedList>,
|
||||||
pending: Arc<Mutex<Option<(String, Vec<ModEntry>)>>>,
|
pending: PendingContent,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ContentListState {
|
impl Default for ContentListState {
|
||||||
@@ -338,7 +340,7 @@ pub fn render(
|
|||||||
|
|
||||||
let count = filtered.len();
|
let count = filtered.len();
|
||||||
|
|
||||||
let snapshot: Vec<(String, String, bool, Option<Vec<Vec<IconCell>>>)> = filtered
|
let snapshot: Vec<SnapshotRow> = filtered
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&i| {
|
.map(|&i| {
|
||||||
let entry = &state.entries[i];
|
let entry = &state.entries[i];
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
|
|||||||
use crate::instance::log_files::{read_log_file, scan_log_files, LogFileEntry};
|
use crate::instance::log_files::{read_log_file, scan_log_files, LogFileEntry};
|
||||||
use crate::tui::theme::THEME;
|
use crate::tui::theme::THEME;
|
||||||
|
|
||||||
|
type PendingLogs = Arc<Mutex<Option<(String, Vec<LogFileEntry>)>>>;
|
||||||
|
|
||||||
pub struct LogsState {
|
pub struct LogsState {
|
||||||
pub entries: Vec<LogFileEntry>,
|
pub entries: Vec<LogFileEntry>,
|
||||||
pub list_state: TuiListState,
|
pub list_state: TuiListState,
|
||||||
@@ -28,7 +30,7 @@ pub struct LogsState {
|
|||||||
pub search: super::search::SearchState,
|
pub search: super::search::SearchState,
|
||||||
pub viewer_search: super::search::SearchState,
|
pub viewer_search: super::search::SearchState,
|
||||||
selected_path: Option<std::path::PathBuf>,
|
selected_path: Option<std::path::PathBuf>,
|
||||||
pending: Arc<Mutex<Option<(String, Vec<LogFileEntry>)>>>,
|
pending: PendingLogs,
|
||||||
rescan_counter: u8,
|
rescan_counter: u8,
|
||||||
instances_dir_cache: Option<std::path::PathBuf>,
|
instances_dir_cache: Option<std::path::PathBuf>,
|
||||||
}
|
}
|
||||||
@@ -116,7 +118,7 @@ impl LogsState {
|
|||||||
|
|
||||||
pub fn try_rescan(&mut self) {
|
pub fn try_rescan(&mut self) {
|
||||||
self.rescan_counter = self.rescan_counter.wrapping_add(1);
|
self.rescan_counter = self.rescan_counter.wrapping_add(1);
|
||||||
if self.rescan_counter % 120 != 0 {
|
if !self.rescan_counter.is_multiple_of(120) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,13 +8,15 @@ use ratatui::{
|
|||||||
|
|
||||||
use crate::tui::theme::THEME;
|
use crate::tui::theme::THEME;
|
||||||
|
|
||||||
|
type ContentFn<'a> = Box<dyn Fn(Rect, &mut Buffer) + 'a>;
|
||||||
|
|
||||||
pub struct PopupFrame<'a> {
|
pub struct PopupFrame<'a> {
|
||||||
pub title: Line<'a>,
|
pub title: Line<'a>,
|
||||||
pub border_color: Color,
|
pub border_color: Color,
|
||||||
pub bg: Option<Color>,
|
pub bg: Option<Color>,
|
||||||
pub keybinds: Option<Line<'a>>,
|
pub keybinds: Option<Line<'a>>,
|
||||||
pub search_line: Option<Line<'a>>,
|
pub search_line: Option<Line<'a>>,
|
||||||
pub content: Box<dyn Fn(Rect, &mut Buffer) + 'a>,
|
pub content: ContentFn<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Widget for PopupFrame<'a> {
|
impl<'a> Widget for PopupFrame<'a> {
|
||||||
|
|||||||
@@ -42,18 +42,15 @@ pub enum WizardStep {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[derive(Default)]
|
||||||
pub enum LoadState<T> {
|
pub enum LoadState<T> {
|
||||||
|
#[default]
|
||||||
Idle,
|
Idle,
|
||||||
Loading,
|
Loading,
|
||||||
Loaded(T),
|
Loaded(T),
|
||||||
Error(String),
|
Error(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Default for LoadState<T> {
|
|
||||||
fn default() -> Self {
|
|
||||||
LoadState::Idle
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct WizardState {
|
pub struct WizardState {
|
||||||
@@ -255,7 +252,7 @@ fn handle_name_key(
|
|||||||
state.step = WizardStep::Loader;
|
state.step = WizardStep::Loader;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
state.name_state.handle_key_event(key_event.clone());
|
state.name_state.handle_key_event(*key_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -785,7 +782,7 @@ fn compare_semver(a: &str, b: &str) -> std::cmp::Ordering {
|
|||||||
a_parts.len().cmp(&b_parts.len())
|
a_parts.len().cmp(&b_parts.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sort_versions_semver(versions: &mut Vec<GameVersion>) {
|
fn sort_versions_semver(versions: &mut [GameVersion]) {
|
||||||
// Sort newest first (descending), so compare b vs a
|
// Sort newest first (descending), so compare b vs a
|
||||||
versions.sort_by(|a, b| compare_semver(&b.id, &a.id));
|
versions.sort_by(|a, b| compare_semver(&b.id, &a.id));
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,8 @@ const MAX_CELL_WIDTH: u16 = 52;
|
|||||||
const NAME_ROW_HEIGHT: u16 = 1;
|
const NAME_ROW_HEIGHT: u16 = 1;
|
||||||
const GAP: u16 = 1;
|
const GAP: u16 = 1;
|
||||||
|
|
||||||
|
type PendingScreenshots = Arc<Mutex<Option<(String, Vec<ScreenshotEntry>)>>>;
|
||||||
|
|
||||||
pub struct ScreenshotsState {
|
pub struct ScreenshotsState {
|
||||||
pub entries: Vec<ScreenshotEntry>,
|
pub entries: Vec<ScreenshotEntry>,
|
||||||
protocols: HashMap<usize, StatefulProtocol>,
|
protocols: HashMap<usize, StatefulProtocol>,
|
||||||
@@ -34,7 +36,7 @@ pub struct ScreenshotsState {
|
|||||||
pub scrollbar_state: ScrollbarState,
|
pub scrollbar_state: ScrollbarState,
|
||||||
pub search: super::search::SearchState,
|
pub search: super::search::SearchState,
|
||||||
pub font_size: (u16, u16),
|
pub font_size: (u16, u16),
|
||||||
pending_entries: Arc<Mutex<Option<(String, Vec<ScreenshotEntry>)>>>,
|
pending_entries: PendingScreenshots,
|
||||||
pending_images: Arc<Mutex<Vec<(usize, image::DynamicImage)>>>,
|
pending_images: Arc<Mutex<Vec<(usize, image::DynamicImage)>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +169,7 @@ impl ScreenshotsState {
|
|||||||
if self.cols == 0 {
|
if self.cols == 0 {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
(self.entries.len() + self.cols - 1) / self.cols
|
self.entries.len().div_ceil(self.cols)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user