Skip to content

Commit b3be053

Browse files
git-f0xwash2
authored andcommitted
chore: clippy
1 parent a8d8e14 commit b3be053

File tree

27 files changed

+656
-708
lines changed

27 files changed

+656
-708
lines changed

cosmic-settings/src/pages/applications/default_apps.rs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ impl page::Page<crate::pages::Message> for Page {
121121

122122
let mut local_list = mime_apps::List::default();
123123

124-
if let Some(path) = mime_apps::local_list_path() {
125-
if let Ok(buffer) = std::fs::read_to_string(&path) {
126-
local_list.load_from(&buffer);
127-
}
124+
if let Some(path) = mime_apps::local_list_path()
125+
&& let Ok(buffer) = std::fs::read_to_string(&path)
126+
{
127+
local_list.load_from(&buffer);
128128
}
129129

130130
let assocs = mime_apps::associations::by_app();
@@ -245,10 +245,11 @@ impl Page {
245245
meta.selected = Some(id);
246246
let appid = &meta.app_ids[id];
247247

248-
if category == Category::Terminal && self.shortcuts_config.is_some() {
249-
if let Some(config) = self.shortcuts_config.as_ref() {
250-
assign_default_terminal(config, appid);
251-
}
248+
if category == Category::Terminal
249+
&& self.shortcuts_config.is_some()
250+
&& let Some(config) = self.shortcuts_config.as_ref()
251+
{
252+
assign_default_terminal(config, appid);
252253
}
253254

254255
for mime in mime_types {
@@ -450,13 +451,13 @@ fn assign_default_terminal(config: &cosmic_config::Config, appid: &str) {
450451
if let Some(resolved_path) = resolved_path {
451452
let desktop_entry = DesktopEntry::from_path(resolved_path, Some(&get_languages_from_env()));
452453

453-
if let Ok(desktop_entry) = desktop_entry {
454-
if let Some(exec) = desktop_entry.exec() {
455-
actions.insert(System::Terminal, String::from(exec));
454+
if let Ok(desktop_entry) = desktop_entry
455+
&& let Some(exec) = desktop_entry.exec()
456+
{
457+
actions.insert(System::Terminal, String::from(exec));
456458

457-
if let Err(why) = config.set("system_actions", actions) {
458-
tracing::error!(?why, "Unable to set system_actions shortcuts config");
459-
}
459+
if let Err(why) = config.set("system_actions", actions) {
460+
tracing::error!(?why, "Unable to set system_actions shortcuts config");
460461
}
461462
}
462463
}
@@ -500,10 +501,10 @@ async fn load_defaults(assocs: &BTreeMap<Arc<str>, Arc<App>>, for_mimes: &[&str]
500501
let mut icons = Vec::new();
501502

502503
for (id, (appid, app)) in unsorted.iter().enumerate() {
503-
if let Some(current_app) = current_app {
504-
if app.name.as_ref() == current_app.name.as_ref() {
505-
selected = Some(id);
506-
}
504+
if let Some(current_app) = current_app
505+
&& app.name.as_ref() == current_app.name.as_ref()
506+
{
507+
selected = Some(id);
507508
}
508509

509510
app_ids.push(appid.as_ref().into());
@@ -562,21 +563,21 @@ async fn load_terminal_apps(assocs: &BTreeMap<Arc<str>, Arc<App>>) -> AppMeta {
562563

563564
// Scan desktop entries for terminal applications
564565
for path in DesktopEntryIter::new(default_paths()) {
565-
if let Ok(bytes) = std::fs::read_to_string(&path) {
566-
if let Ok(entry) = DesktopEntry::from_str(&path, &bytes, None::<&[&str]>) {
567-
// Check if it's a terminal application
568-
if entry
569-
.categories()
570-
.map(|cats| cats.iter().any(|c| *c == "TerminalEmulator"))
571-
.unwrap_or(false)
572-
{
573-
let id = entry.id();
574-
if let Some(app) = assocs.get(id) {
575-
if current_appid.as_ref().map(|c| *c == id).unwrap_or(false) {
576-
current_app = Some(app.clone());
577-
}
578-
terminals.push((Arc::from(id), app.clone()));
566+
if let Ok(bytes) = std::fs::read_to_string(&path)
567+
&& let Ok(entry) = DesktopEntry::from_str(&path, &bytes, None::<&[&str]>)
568+
{
569+
// Check if it's a terminal application
570+
if entry
571+
.categories()
572+
.map(|cats| cats.contains(&"TerminalEmulator"))
573+
.unwrap_or(false)
574+
{
575+
let id = entry.id();
576+
if let Some(app) = assocs.get(id) {
577+
if current_appid.as_ref().map(|c| *c == id).unwrap_or(false) {
578+
current_app = Some(app.clone());
579579
}
580+
terminals.push((Arc::from(id), app.clone()));
580581
}
581582
}
582583
}
@@ -591,10 +592,10 @@ async fn load_terminal_apps(assocs: &BTreeMap<Arc<str>, Arc<App>>) -> AppMeta {
591592
let mut icons = Vec::new();
592593

593594
for (id, (appid, app)) in terminals.iter().enumerate() {
594-
if let Some(ref current_app) = current_app {
595-
if app.name.as_ref() == current_app.name.as_ref() {
596-
selected = Some(id);
597-
}
595+
if let Some(ref current_app) = current_app
596+
&& app.name.as_ref() == current_app.name.as_ref()
597+
{
598+
selected = Some(id);
598599
}
599600

600601
app_ids.push(appid.to_string());

cosmic-settings/src/pages/applications/legacy_applications.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ impl page::Page<crate::pages::Message> for Page {
138138
let (randr_task, randr_handle) =
139139
Task::stream(async_fn_stream::fn_stream(|emitter| async move {
140140
while let Ok(message) = rx.recv().await {
141-
if let cosmic_randr::Message::ManagerDone = message {
142-
if !refresh_pending.swap(true, Ordering::SeqCst) {
143-
_ = emitter.emit(on_enter().await).await;
144-
}
141+
if let cosmic_randr::Message::ManagerDone = message
142+
&& !refresh_pending.swap(true, Ordering::SeqCst)
143+
{
144+
_ = emitter.emit(on_enter().await).await;
145145
}
146146
}
147147
}))

cosmic-settings/src/pages/applications/startup_apps.rs

Lines changed: 101 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -157,36 +157,35 @@ impl page::Page<crate::pages::Message> for Page {
157157
}
158158

159159
fn dialog(&self) -> Option<crate::pages::Element<'_>> {
160-
if let Some(app_to_remove) = &self.app_to_remove {
161-
if let Some(cached_startup_apps) = &self.cached_startup_apps {
162-
if let Some(target_directory_type) = &self.target_directory_type {
163-
return Some(
164-
widget::dialog()
165-
.title(fl!(
166-
"startup-apps",
167-
"remove-dialog-title",
168-
name = app_to_remove.name(&cached_startup_apps.locales)
169-
))
170-
.icon(icon::from_name("dialog-warning").size(64))
171-
.body(fl!("startup-apps", "remove-dialog-description"))
172-
.primary_action(
173-
button::suggested(fl!("remove")).on_press(
174-
Message::RemoveStartupApplication(
175-
target_directory_type.clone(),
176-
app_to_remove.clone(),
177-
true,
178-
)
179-
.into(),
180-
),
160+
if let Some(app_to_remove) = &self.app_to_remove
161+
&& let Some(cached_startup_apps) = &self.cached_startup_apps
162+
&& let Some(target_directory_type) = &self.target_directory_type
163+
{
164+
return Some(
165+
widget::dialog()
166+
.title(fl!(
167+
"startup-apps",
168+
"remove-dialog-title",
169+
name = app_to_remove.name(&cached_startup_apps.locales)
170+
))
171+
.icon(icon::from_name("dialog-warning").size(64))
172+
.body(fl!("startup-apps", "remove-dialog-description"))
173+
.primary_action(
174+
button::suggested(fl!("remove")).on_press(
175+
Message::RemoveStartupApplication(
176+
target_directory_type.clone(),
177+
app_to_remove.clone(),
178+
true,
181179
)
182-
.secondary_action(
183-
button::standard(fl!("cancel"))
184-
.on_press(Message::CancelRemoveStartupApplication.into()),
185-
)
186-
.apply(Element::from),
187-
);
188-
}
189-
}
180+
.into(),
181+
),
182+
)
183+
.secondary_action(
184+
button::standard(fl!("cancel"))
185+
.on_press(Message::CancelRemoveStartupApplication.into()),
186+
)
187+
.apply(Element::from),
188+
);
190189
}
191190
None
192191
}
@@ -228,32 +227,31 @@ impl Page {
228227

229228
_ = std::fs::create_dir_all(directory_to_target.as_path());
230229

231-
if let Ok(exists) = std::fs::exists(directory_to_target.join(file_name.clone())) {
232-
if !exists {
233-
// when adding an application, we want to symlink to be more user-friendly
234-
// this ensures that, as an application gets updated / removed, so does the
235-
// symlink
236-
match std::os::unix::fs::symlink(
237-
app.clone().path,
238-
directory_to_target.join(file_name),
239-
) {
240-
Ok(_) => {
241-
if let Some(ref mut cached_startup_apps) = self.cached_startup_apps
242-
{
243-
let target_apps = cached_startup_apps.apps.get(&directory_type);
244-
if let Some(target_apps) = target_apps {
245-
let mut new_apps = target_apps.clone();
246-
new_apps.push(app.clone());
247-
248-
cached_startup_apps
249-
.apps
250-
.insert(directory_type.clone(), new_apps);
251-
}
230+
if let Ok(exists) = std::fs::exists(directory_to_target.join(file_name.clone()))
231+
&& !exists
232+
{
233+
// when adding an application, we want to symlink to be more user-friendly
234+
// this ensures that, as an application gets updated / removed, so does the
235+
// symlink
236+
match std::os::unix::fs::symlink(
237+
app.clone().path,
238+
directory_to_target.join(file_name),
239+
) {
240+
Ok(_) => {
241+
if let Some(ref mut cached_startup_apps) = self.cached_startup_apps {
242+
let target_apps = cached_startup_apps.apps.get(&directory_type);
243+
if let Some(target_apps) = target_apps {
244+
let mut new_apps = target_apps.clone();
245+
new_apps.push(app.clone());
246+
247+
cached_startup_apps
248+
.apps
249+
.insert(directory_type.clone(), new_apps);
252250
}
253251
}
254-
Err(e) => {
255-
error!(?e, "Failed to symlink");
256-
}
252+
}
253+
Err(e) => {
254+
error!(?e, "Failed to symlink");
257255
}
258256
}
259257
}
@@ -273,33 +271,30 @@ impl Page {
273271
let directory_to_target =
274272
directories.first().expect("Always at least one directory");
275273
if let Ok(exists) = std::fs::exists(directory_to_target.join(file_name.clone()))
274+
&& exists
276275
{
277-
if exists {
278-
// remove_file works for both regular files & symlinks
279-
match std::fs::remove_file(directory_to_target.join(file_name)) {
280-
Ok(_) => {
281-
if let Some(ref mut cached_startup_apps) =
282-
self.cached_startup_apps
283-
{
284-
let target_apps =
285-
cached_startup_apps.apps.get(&directory_type);
286-
if let Some(target_apps) = target_apps {
287-
let mut new_apps = Vec::new();
288-
for old_app in target_apps {
289-
if old_app != &app {
290-
new_apps.push(old_app.clone());
291-
}
276+
// remove_file works for both regular files & symlinks
277+
match std::fs::remove_file(directory_to_target.join(file_name)) {
278+
Ok(_) => {
279+
if let Some(ref mut cached_startup_apps) = self.cached_startup_apps
280+
{
281+
let target_apps = cached_startup_apps.apps.get(&directory_type);
282+
if let Some(target_apps) = target_apps {
283+
let mut new_apps = Vec::new();
284+
for old_app in target_apps {
285+
if old_app != &app {
286+
new_apps.push(old_app.clone());
292287
}
293-
294-
cached_startup_apps
295-
.apps
296-
.insert(directory_type.clone(), new_apps);
297288
}
289+
290+
cached_startup_apps
291+
.apps
292+
.insert(directory_type.clone(), new_apps);
298293
}
299294
}
300-
Err(e) => {
301-
error!(?e, "Failed to remove file");
302-
}
295+
}
296+
Err(e) => {
297+
error!(?e, "Failed to remove file");
303298
}
304299
}
305300
}
@@ -330,39 +325,30 @@ impl Page {
330325

331326
if let Some(startup_apps) = &self.cached_startup_apps {
332327
for app in &startup_apps.all_apps {
333-
if let Some(name) = app.name(&startup_apps.locales) {
334-
if let Some(exec) = app.exec() {
335-
if search_input.is_empty()
336-
|| exec.to_lowercase().contains(search_input)
337-
|| name.to_lowercase().contains(search_input)
338-
{
339-
let mut row = widget::row::with_capacity(3)
340-
.spacing(space_xs)
341-
.align_y(Alignment::Center);
342-
343-
row = row.push(
344-
icon::from_name(app.icon().unwrap_or("application-default"))
345-
.size(32),
346-
);
347-
348-
if let Some(name) = app.name(&startup_apps.locales) {
349-
row = row.push(text(name).width(Length::Fill));
350-
} else {
351-
row = row.push(text(&app.appid).width(Length::Fill));
352-
}
353-
row = row.push(
354-
widget::button::text(fl!("add")).on_press(
355-
Message::AddStartupApplication(
356-
directory_type.clone(),
357-
app.clone(),
358-
)
359-
.into(),
360-
),
361-
);
362-
363-
list = list.add(row)
364-
}
328+
if let Some(name) = app.name(&startup_apps.locales)
329+
&& let Some(exec) = app.exec()
330+
&& (search_input.is_empty()
331+
|| exec.to_lowercase().contains(search_input)
332+
|| name.to_lowercase().contains(search_input))
333+
{
334+
let mut row = widget::row::with_capacity(3)
335+
.spacing(space_xs)
336+
.align_y(Alignment::Center);
337+
338+
row = row.push(
339+
icon::from_name(app.icon().unwrap_or("application-default")).size(32),
340+
);
341+
342+
if let Some(name) = app.name(&startup_apps.locales) {
343+
row = row.push(text(name).width(Length::Fill));
344+
} else {
345+
row = row.push(text(&app.appid).width(Length::Fill));
365346
}
347+
row = row.push(widget::button::text(fl!("add")).on_press(
348+
Message::AddStartupApplication(directory_type.clone(), app.clone()).into(),
349+
));
350+
351+
list = list.add(row)
366352
}
367353
}
368354
}
@@ -467,16 +453,16 @@ fn get_all_apps(locales: Vec<String>) -> Vec<DesktopEntry> {
467453
}
468454

469455
// skip if we can't run this in COSMIC
470-
if let Some(only_show_in) = entry.only_show_in() {
471-
if !only_show_in.contains(&"COSMIC") {
472-
continue;
473-
}
456+
if let Some(only_show_in) = entry.only_show_in()
457+
&& !only_show_in.contains(&"COSMIC")
458+
{
459+
continue;
474460
}
475461

476-
if let Some(not_show_in) = entry.not_show_in() {
477-
if not_show_in.contains(&"COSMIC") {
478-
continue;
479-
}
462+
if let Some(not_show_in) = entry.not_show_in()
463+
&& not_show_in.contains(&"COSMIC")
464+
{
465+
continue;
480466
}
481467

482468
result.push(entry.clone());

0 commit comments

Comments
 (0)