Skip to content

Commit f186c45

Browse files
committed
chore: collapse nested if-let statements as it was stabilised in Rust 1.88.0
1 parent 0846f91 commit f186c45

File tree

7 files changed

+20
-30
lines changed

7 files changed

+20
-30
lines changed

plugins/com.amansprojects.starterpack.sdPlugin/src/run_command.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ async fn run_command(
6565
let mut output = String::new();
6666
reader.read_to_string(&mut output)?;
6767

68-
if let Some(path) = settings.get("file").map(|v| v.as_str().unwrap()) {
69-
if !path.is_empty() {
68+
if let Some(path) = settings.get("file").map(|v| v.as_str().unwrap())
69+
&& !path.is_empty() {
7070
tokio::fs::write(path, &output).await?;
7171
}
72-
}
7372

7473
if settings
7574
.get("show")

src-tauri/src/events/inbound/misc.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ pub struct LogMessageEvent {
2121
}
2222

2323
pub async fn log_message(uuid: Option<&str>, mut event: PayloadEvent<LogMessageEvent>) -> Result<(), anyhow::Error> {
24-
if let Some(uuid) = uuid {
25-
if let Ok(manifest) = crate::plugins::manifest::read_manifest(&crate::shared::config_dir().join("plugins").join(uuid)) {
24+
if let Some(uuid) = uuid
25+
&& let Ok(manifest) = crate::plugins::manifest::read_manifest(&crate::shared::config_dir().join("plugins").join(uuid)) {
2626
event.payload.message = format!("[{}] {}", manifest.name, event.payload.message);
2727
}
28-
}
2928
log::info!("{}", event.payload.message.trim());
3029
Ok(())
3130
}

src-tauri/src/events/inbound/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,10 @@ pub async fn process_incoming_message(data: Result<Message, Error>, uuid: &str,
133133
InboundEventType::SendToPlugin(_) => Ok(()),
134134
InboundEventType::SwitchProfile(event) => misc::switch_profile(event).await,
135135
InboundEventType::DeviceBrightness(event) => misc::device_brightness(event).await,
136-
} {
137-
if !error.to_string().contains("closed connection") {
136+
}
137+
&& !error.to_string().contains("closed connection") {
138138
warn!("Failed to process incoming event from plugin: {}", error);
139139
}
140-
}
141140
}
142141
}
143142

@@ -155,11 +154,10 @@ pub async fn process_incoming_message_pi(data: Result<Message, Error>, uuid: &st
155154
InboundEventType::GetGlobalSettings(event) => Some(event.context.clone()),
156155
InboundEventType::SendToPlugin(event) => Some(event.context.to_string()),
157156
_ => None,
158-
} {
159-
if context != uuid {
157+
}
158+
&& context != uuid {
160159
return;
161160
}
162-
}
163161

164162
if let Err(error) = match decoded {
165163
InboundEventType::SetSettings(event) => settings::set_settings(event, true).await,
@@ -170,10 +168,9 @@ pub async fn process_incoming_message_pi(data: Result<Message, Error>, uuid: &st
170168
InboundEventType::LogMessage(event) => misc::log_message(None, event).await,
171169
InboundEventType::SendToPlugin(event) => property_inspector::send_to_plugin(event).await,
172170
_ => Ok(()),
173-
} {
174-
if !error.to_string().contains("closed connection") {
171+
}
172+
&& !error.to_string().contains("closed connection") {
175173
warn!("Failed to process incoming event from property inspector: {}", error);
176174
}
177-
}
178175
}
179176
}

src-tauri/src/events/outbound/will_appear.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ pub async fn will_disappear(instance: &ActionInstance, clear_on_device: bool) ->
4242
)
4343
.await?;
4444

45-
if clear_on_device {
46-
if let Err(error) = crate::events::outbound::devices::update_image((&instance.context).into(), None).await {
45+
if clear_on_device
46+
&& let Err(error) = crate::events::outbound::devices::update_image((&instance.context).into(), None).await {
4747
log::warn!("Failed to clear device image: {}", error);
4848
}
49-
}
5049

5150
Ok(())
5251
}

src-tauri/src/plugins/manifest.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ pub fn read_manifest(base_path: &std::path::Path) -> Result<PluginManifest, anyh
7979
.context("failed to parse manifest")?;
8080

8181
let platform_overrides_path = base_path.join(format!("manifest.{}.json", std::env::consts::OS));
82-
if platform_overrides_path.exists() {
83-
if let Ok(Ok(platform_overrides)) = std::fs::read(platform_overrides_path).map(|v| serde_json::from_slice(&v)) {
82+
if platform_overrides_path.exists()
83+
&& let Ok(Ok(platform_overrides)) = std::fs::read(platform_overrides_path).map(|v| serde_json::from_slice(&v)) {
8484
json_patch::merge(&mut manifest, &platform_overrides);
8585
}
86-
}
8786

8887
serde_json::from_value(manifest).context("failed to parse manifest")
8988
}

src-tauri/src/plugins/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,11 @@ pub async fn initialise_plugin(path: &path::Path) -> anyhow::Result<()> {
176176
.visible(false)
177177
.build()?;
178178

179-
if let Ok(store) = get_settings() {
180-
if store.value.developer {
179+
if let Ok(store) = get_settings()
180+
&& store.value.developer {
181181
let _ = window.show();
182182
window.open_devtools();
183183
}
184-
}
185184

186185
let info = info_param::make_info(plugin_uuid.to_owned(), manifest.version, false).await;
187186
window.eval(format!(
@@ -319,11 +318,10 @@ pub async fn initialise_plugin(path: &path::Path) -> anyhow::Result<()> {
319318
}
320319
}
321320

322-
if let Some(applications) = manifest.applications_to_monitor {
323-
if let Some(applications) = applications.get(platform) {
321+
if let Some(applications) = manifest.applications_to_monitor
322+
&& let Some(applications) = applications.get(platform) {
324323
crate::application_watcher::start_monitoring(plugin_uuid, applications).await;
325324
}
326-
}
327325

328326
Ok(())
329327
}

src-tauri/src/zip_extract.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,10 @@ pub fn extract<S: Read + Seek>(source: S, target_dir: &Path) -> Result<(), ZipEx
8888
if name.ends_with('/') {
8989
fs::create_dir_all(&outpath)?;
9090
} else {
91-
if let Some(p) = outpath.parent() {
92-
if !p.exists() {
91+
if let Some(p) = outpath.parent()
92+
&& !p.exists() {
9393
fs::create_dir_all(p)?;
9494
}
95-
}
9695
let mut outfile = fs::File::create(&outpath)?;
9796
io::copy(&mut file, &mut outfile)?;
9897
}

0 commit comments

Comments
 (0)