Skip to content

Commit 0086eab

Browse files
committed
cargo clippy --fix (again)
1 parent 7a81073 commit 0086eab

File tree

6 files changed

+266
-283
lines changed

6 files changed

+266
-283
lines changed

src/app.rs

Lines changed: 58 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,20 @@ impl ToolkitTabViewer<'_> {
277277
let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
278278
if let Ok(contents) = ctx.get_contents() {
279279
let token: Result<Token, _> = contents.parse();
280-
if let Ok(token) = token {
281-
if let Some(tx) = self.tab_state.twitch_update_sender.as_ref() {
282-
self.tab_state.settings.twitch_token = Some(token.clone());
283-
let _ = tx.blocking_send(crate::twitch::TwitchUpdate::Token(token));
284-
}
280+
if let Ok(token) = token
281+
&& let Some(tx) = self.tab_state.twitch_update_sender.as_ref()
282+
{
283+
self.tab_state.settings.twitch_token = Some(token.clone());
284+
let _ = tx.blocking_send(crate::twitch::TwitchUpdate::Token(token));
285285
}
286286
}
287287
}
288288
ui.label("Monitored Channel (Default to Self)");
289289
let response = ui.text_edit_singleline(&mut self.tab_state.settings.twitch_monitored_channel);
290-
if response.lost_focus() {
291-
if let Some(tx) = self.tab_state.twitch_update_sender.as_ref() {
292-
let _ = tx.blocking_send(crate::twitch::TwitchUpdate::User(self.tab_state.settings.twitch_monitored_channel.clone()));
293-
}
290+
if response.lost_focus()
291+
&& let Some(tx) = self.tab_state.twitch_update_sender.as_ref()
292+
{
293+
let _ = tx.blocking_send(crate::twitch::TwitchUpdate::User(self.tab_state.settings.twitch_monitored_channel.clone()));
294294
}
295295
});
296296
});
@@ -624,20 +624,20 @@ impl TabState {
624624
replay_files.insert(new_file.clone(), Arc::clone(&replay));
625625
}
626626

627-
if self.auto_load_latest_replay {
628-
if let Some(wows_data) = self.world_of_warships_data.as_ref() {
629-
update_background_task!(
630-
self.background_tasks,
631-
load_replay(
632-
Arc::clone(&self.game_constants),
633-
Arc::clone(wows_data),
634-
replay,
635-
Arc::clone(&self.replay_sort),
636-
self.background_task_sender.clone(),
637-
self.settings.debug_mode,
638-
)
639-
);
640-
}
627+
if self.auto_load_latest_replay
628+
&& let Some(wows_data) = self.world_of_warships_data.as_ref()
629+
{
630+
update_background_task!(
631+
self.background_tasks,
632+
load_replay(
633+
Arc::clone(&self.game_constants),
634+
Arc::clone(wows_data),
635+
replay,
636+
Arc::clone(&self.replay_sort),
637+
self.background_task_sender.clone(),
638+
self.settings.debug_mode,
639+
)
640+
);
641641
}
642642

643643
break;
@@ -737,11 +737,11 @@ impl TabState {
737737
}
738738
EventKind::Modify(ModifyKind::Data(_)) => {
739739
for path in event.paths {
740-
if let Some(filename) = path.file_name() {
741-
if filename == "preferences.xml" {
742-
debug!("Sending preferences changed event");
743-
tx.send(NotifyFileEvent::PreferencesChanged).expect("failed to send file creation event");
744-
}
740+
if let Some(filename) = path.file_name()
741+
&& filename == "preferences.xml"
742+
{
743+
debug!("Sending preferences changed event");
744+
tx.send(NotifyFileEvent::PreferencesChanged).expect("failed to send file creation event");
745745
}
746746
if path.extension().map(|ext| ext == "wowsreplay").unwrap_or(false) {
747747
let _ = background_tx.send(task::ReplayBackgroundParserThreadMessage::ModifiedReplay(path));
@@ -1186,15 +1186,15 @@ impl WowsToolkitApp {
11861186
}
11871187
});
11881188

1189-
if let Ok(latest_release) = app_updates {
1190-
if let Ok(version) = semver::Version::parse(&latest_release.tag_name[1..]) {
1191-
let app_version = semver::Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
1192-
if app_version < version {
1193-
self.update_window_open = true;
1194-
self.latest_release = Some(latest_release);
1195-
} else {
1196-
*self.tab_state.timed_message.write() = Some(TimedMessage::new(format!("{} Application up-to-date", icons::CHECK_CIRCLE)));
1197-
}
1189+
if let Ok(latest_release) = app_updates
1190+
&& let Ok(version) = semver::Version::parse(&latest_release.tag_name[1..])
1191+
{
1192+
let app_version = semver::Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
1193+
if app_version < version {
1194+
self.update_window_open = true;
1195+
self.latest_release = Some(latest_release);
1196+
} else {
1197+
*self.tab_state.timed_message.write() = Some(TimedMessage::new(format!("{} Application up-to-date", icons::CHECK_CIRCLE)));
11981198
}
11991199
}
12001200

@@ -1228,12 +1228,11 @@ impl WowsToolkitApp {
12281228
return Some("Only one file at a time, please.".to_owned());
12291229
}
12301230

1231-
if let Some(file) = i.raw.hovered_files.first() {
1232-
if let Some(path) = &file.path {
1233-
if path.is_file() {
1234-
return Some(format!("Drop to load\n{}", path.file_name()?.to_str()?));
1235-
}
1236-
}
1231+
if let Some(file) = i.raw.hovered_files.first()
1232+
&& let Some(path) = &file.path
1233+
&& path.is_file()
1234+
{
1235+
return Some(format!("Drop to load\n{}", path.file_name()?.to_str()?));
12371236
}
12381237

12391238
None
@@ -1258,23 +1257,22 @@ impl WowsToolkitApp {
12581257
});
12591258

12601259
// Only perform operations if we have one file
1261-
if dropped_files.len() == 1 {
1262-
if let Some(path) = &dropped_files[0].path {
1263-
if let Some(wows_data) = self.tab_state.world_of_warships_data.as_ref() {
1264-
self.tab_state.settings.current_replay_path = path.clone();
1265-
update_background_task!(
1266-
self.tab_state.background_tasks,
1267-
parse_replay(
1268-
Arc::clone(&self.tab_state.game_constants),
1269-
Arc::clone(wows_data),
1270-
self.tab_state.settings.current_replay_path.clone(),
1271-
Arc::clone(&self.tab_state.replay_sort),
1272-
self.tab_state.background_task_sender.clone(),
1273-
self.tab_state.settings.debug_mode
1274-
)
1275-
);
1276-
}
1277-
}
1260+
if dropped_files.len() == 1
1261+
&& let Some(path) = &dropped_files[0].path
1262+
&& let Some(wows_data) = self.tab_state.world_of_warships_data.as_ref()
1263+
{
1264+
self.tab_state.settings.current_replay_path = path.clone();
1265+
update_background_task!(
1266+
self.tab_state.background_tasks,
1267+
parse_replay(
1268+
Arc::clone(&self.tab_state.game_constants),
1269+
Arc::clone(wows_data),
1270+
self.tab_state.settings.current_replay_path.clone(),
1271+
Arc::clone(&self.tab_state.replay_sort),
1272+
self.tab_state.background_task_sender.clone(),
1273+
self.tab_state.settings.debug_mode
1274+
)
1275+
);
12781276
}
12791277
}
12801278

src/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ fn main() -> eframe::Result<()> {
6262
let current_path = Path::new(args[0].as_str());
6363
let old_path = Path::new(args[1].as_str());
6464
// Sanity check -- ensure that these files are in the same directory
65-
if current_path.parent() == old_path.parent() {
66-
if let Some(name) = old_path.file_name().and_then(|name| name.to_str()) {
67-
if name.contains(".exe") && old_path.exists() {
68-
let _ = std::fs::remove_file(old_path);
69-
70-
// Rename the update to the old path. This is useful
71-
// if people have desktop shortcuts / taskbar pins
72-
let _ = std::fs::rename(current_path, old_path);
73-
}
74-
}
65+
if current_path.parent() == old_path.parent()
66+
&& let Some(name) = old_path.file_name().and_then(|name| name.to_str())
67+
&& name.contains(".exe")
68+
&& old_path.exists()
69+
{
70+
let _ = std::fs::remove_file(old_path);
71+
72+
// Rename the update to the old path. This is useful
73+
// if people have desktop shortcuts / taskbar pins
74+
let _ = std::fs::rename(current_path, old_path);
7575
}
7676
}
7777

src/task.rs

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ fn replay_filepaths(replays_dir: &Path) -> Option<Vec<PathBuf>> {
245245

246246
let file_path = file.path();
247247

248-
if let Some("wowsreplay") = file_path.extension().map(|s| s.to_str().expect("failed to convert extension to str")) {
249-
if file.file_name() != "temp.wowsreplay" {
250-
files.push(file_path);
251-
}
248+
if let Some("wowsreplay") = file_path.extension().map(|s| s.to_str().expect("failed to convert extension to str"))
249+
&& file.file_name() != "temp.wowsreplay"
250+
{
251+
files.push(file_path);
252252
}
253253
}
254254
}
@@ -309,23 +309,23 @@ pub fn load_wows_files(wows_directory: PathBuf, locale: &str) -> Result<Backgrou
309309
let prefs_file = wows_directory.join("preferences.xml");
310310
if prefs_file.exists() {
311311
// Try getting the version string from the preferences file
312-
if let Some(version_str) = current_build_from_preferences(&prefs_file) {
313-
if version_str.contains(',') {
314-
let full_build_info = wowsunpack::data::Version::from_client_exe(&version_str);
315-
latest_build = Some(full_build_info.build as usize);
316-
317-
// We want to build the version string without the patch component to get the replays dir
318-
// that the replay manager mod uses
319-
let friendly_build = format!("{}.{}.{}.0", full_build_info.major, full_build_info.minor, full_build_info.patch);
320-
321-
full_version = Some(full_build_info);
322-
323-
for temp_replays_dir in [replays_dir.join(&friendly_build), replays_dir.join(friendly_build)] {
324-
debug!("Looking for build-specific replays dir at {:?}", temp_replays_dir);
325-
if temp_replays_dir.exists() {
326-
replays_dir = temp_replays_dir;
327-
break;
328-
}
312+
if let Some(version_str) = current_build_from_preferences(&prefs_file)
313+
&& version_str.contains(',')
314+
{
315+
let full_build_info = wowsunpack::data::Version::from_client_exe(&version_str);
316+
latest_build = Some(full_build_info.build as usize);
317+
318+
// We want to build the version string without the patch component to get the replays dir
319+
// that the replay manager mod uses
320+
let friendly_build = format!("{}.{}.{}.0", full_build_info.major, full_build_info.minor, full_build_info.patch);
321+
322+
full_version = Some(full_build_info);
323+
324+
for temp_replays_dir in [replays_dir.join(&friendly_build), replays_dir.join(friendly_build)] {
325+
debug!("Looking for build-specific replays dir at {:?}", temp_replays_dir);
326+
if temp_replays_dir.exists() {
327+
replays_dir = temp_replays_dir;
328+
break;
329329
}
330330
}
331331
}
@@ -343,10 +343,10 @@ pub fn load_wows_files(wows_directory: PathBuf, locale: &str) -> Result<Backgrou
343343
continue;
344344
}
345345

346-
if let Some(build_num) = file.file_name().to_str().and_then(|name| name.parse::<usize>().ok()) {
347-
if latest_build.is_none() || latest_build.map(|number| number < build_num).unwrap_or(false) {
348-
latest_build = Some(build_num)
349-
}
346+
if let Some(build_num) = file.file_name().to_str().and_then(|name| name.parse::<usize>().ok())
347+
&& (latest_build.is_none() || latest_build.map(|number| number < build_num).unwrap_or(false))
348+
{
349+
latest_build = Some(build_num)
350350
}
351351
}
352352
}
@@ -517,12 +517,11 @@ pub fn start_twitch_task(
517517
(state.client().clone(), state.token.clone())
518518
};
519519
let mut monitored_user_id = token.as_ref().map(|token| token.user_id.clone());
520-
if !monitored_channel.is_empty() {
521-
if let Some(token) = token {
522-
if let Ok(Some(user)) = client.get_user_from_login(&monitored_channel, &token).await {
523-
monitored_user_id = Some(user.id)
524-
}
525-
}
520+
if !monitored_channel.is_empty()
521+
&& let Some(token) = token
522+
&& let Ok(Some(user)) = client.get_user_from_login(&monitored_channel, &token).await
523+
{
524+
monitored_user_id = Some(user.id)
526525
}
527526

528527
loop {
@@ -532,17 +531,15 @@ pub fn start_twitch_task(
532531
// Every 2 minutes we attempt to get the participants list
533532
_ = interval.tick() => {
534533
let (client, token) = { let state = twitch_state.read(); (state.client().clone(), state.token.clone()) };
535-
if let Some(token) = token {
536-
if let Some(monitored_user) = &monitored_user_id {
537-
if let Ok(chatters) = twitch::fetch_chatters(&client, monitored_user, &token).await {
534+
if let Some(token) = token
535+
&& let Some(monitored_user) = &monitored_user_id
536+
&& let Ok(chatters) = twitch::fetch_chatters(&client, monitored_user, &token).await {
538537
let now = Timestamp::now();
539538
let mut state = twitch_state.write();
540539
for chatter in chatters {
541540
state.participants.entry(chatter).or_default().insert(now);
542541
}
543542
}
544-
}
545-
}
546543
}
547544

548545
update = token_receive => {
@@ -553,37 +550,32 @@ pub fn start_twitch_task(
553550
update_twitch_token(&twitch_state, &token).await;
554551

555552
let (client, token) = { let state = twitch_state.read(); (state.client().clone(), state.token.clone()) };
556-
if let Some(token) = &token {
557-
if let Some(monitored_user) = &monitored_user_id {
558-
if let Ok(chatters) = twitch::fetch_chatters(&client, monitored_user, token).await {
553+
if let Some(token) = &token
554+
&& let Some(monitored_user) = &monitored_user_id
555+
&& let Ok(chatters) = twitch::fetch_chatters(&client, monitored_user, token).await {
559556
let now = Timestamp::now();
560557
let mut state = twitch_state.write();
561558
for chatter in chatters {
562559
state.participants.entry(chatter).or_default().insert(now);
563560
}
564561
}
565-
}
566-
}
567562

568563
if !had_previous_token {
569564
// If we didn't have a previous token, but we did have a username to watch, update the username
570565
monitored_user_id = token.as_ref().map(|token| token.user_id.clone());
571-
if !monitored_channel.is_empty() {
572-
if let Some(token) = token {
573-
if let Ok(Some(user)) = client.get_user_from_login(&monitored_channel, &token).await {
566+
if !monitored_channel.is_empty()
567+
&& let Some(token) = token
568+
&& let Ok(Some(user)) = client.get_user_from_login(&monitored_channel, &token).await {
574569
monitored_user_id = Some(user.id)
575570
}
576-
}
577-
}
578571
}
579572
},
580573
TwitchUpdate::User(user_name) => {
581574
let (client, token) = { let state = twitch_state.read(); (state.client().clone(), state.token.clone()) };
582-
if let Some(token) = token {
583-
if let Ok(Some(user)) = client.get_user_from_login(&user_name, &token).await {
575+
if let Some(token) = token
576+
&& let Ok(Some(user)) = client.get_user_from_login(&user_name, &token).await {
584577
monitored_user_id = Some(user.id);
585578
}
586-
}
587579
},
588580
}
589581
}

0 commit comments

Comments
 (0)