Skip to content

Commit 9334579

Browse files
committed
Replacing unwrap calls with if-let and removing redundant key check
1 parent 88b2e82 commit 9334579

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,14 @@ impl Page {
251251
// if we're changing terminal, we want to update the COSMIC system actions shortcut
252252
// for terminal
253253
if category == Category::Terminal && self.shortcuts_config.is_some() {
254-
let shortcuts = self.shortcuts_config.as_ref().unwrap();
255-
let system_actions = shortcuts.get::<SystemActions>("system_actions");
256-
match system_actions {
257-
Err(e) => {
258-
// we don't have system_actions set?
259-
println!("{}", e);
260-
}
261-
Ok(mut actions) => {
262-
// get the current terminal option, which should default to cosmic-term
263-
let current_terminal = actions.get(&System::Terminal);
264-
if current_terminal.is_some() {
254+
if let Some(shortcuts) = self.shortcuts_config.as_ref() {
255+
let system_actions = shortcuts.get::<SystemActions>("system_actions");
256+
match system_actions {
257+
Err(e) => {
258+
// we don't have system_actions set?
259+
println!("{}", e);
260+
}
261+
Ok(mut actions) => {
265262
let default_paths = default_paths();
266263
let mut resolved_path = None;
267264

@@ -275,16 +272,17 @@ impl Page {
275272
}
276273

277274
// if we find a valid .desktop file, we can grab its exec
278-
if resolved_path.is_some() {
279-
let desktop_entry = DesktopEntry::from_path(resolved_path.unwrap(), Some(&get_languages_from_env()));
280-
if desktop_entry.is_ok() {
281-
// grab the exec, add it to system_actions and commit
282-
let exec = String::from(desktop_entry.unwrap().exec().unwrap());
283-
actions.insert(System::Terminal, exec);
284-
285-
if let Err(e) = shortcuts.set("system_actions", actions) {
286-
println!("{}", e);
275+
if let Some(resolved_path) = resolved_path {
276+
let desktop_entry = DesktopEntry::from_path(resolved_path, Some(&get_languages_from_env()));
277+
if let Ok(desktop_entry) = desktop_entry {
278+
if let Some(exec) = desktop_entry.exec() {
279+
actions.insert(System::Terminal, String::from(exec));
280+
281+
if let Err(e) = shortcuts.set("system_actions", actions) {
282+
println!("{}", e);
283+
}
287284
}
285+
288286
}
289287
}
290288
}

0 commit comments

Comments
 (0)