Skip to content

Commit 4f6b0be

Browse files
authored
Merge pull request #44 from cappsyco/refactors
chores: cleanup and clippy
2 parents f83cf1f + beccc64 commit 4f6b0be

4 files changed

Lines changed: 38 additions & 48 deletions

File tree

applet/src/app.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct LogoMenu {
2222
core: Core,
2323
popup: Option<Id>,
2424
config: LogoMenuConfig,
25+
is_flatpak: bool,
2526
osd_cmd: String,
2627
}
2728

@@ -59,6 +60,9 @@ impl Application for LogoMenu {
5960
})
6061
.unwrap_or_default();
6162

63+
// set flatpag flag
64+
let is_flatpak = is_flatpak();
65+
6266
// get cosmic_osd command based on the distro
6367
let osd_cmd = match is_nixos() {
6468
true => String::from("/run/current-system/sw/bin/cosmic-osd"),
@@ -69,6 +73,7 @@ impl Application for LogoMenu {
6973
core,
7074
popup: None,
7175
config,
76+
is_flatpak,
7277
osd_cmd,
7378
};
7479
(app, Task::none())
@@ -80,7 +85,7 @@ impl Application for LogoMenu {
8085

8186
fn view(&self) -> Element<'_, Self::Message> {
8287
// If custom logo is active and there is a valid one set
83-
let logo_widget = if self.config.custom_logo_active == true
88+
let logo_widget = if self.config.custom_logo_active
8489
&& Path::new(&self.config.custom_logo_path).exists()
8590
{
8691
// Load custom logo
@@ -188,21 +193,18 @@ impl Application for LogoMenu {
188193
power::PowerAction::Shutdown => "shutdown",
189194
_ => return action.perform(),
190195
};
191-
let is_flatpak = is_flatpak();
192196

193-
if is_flatpak {
197+
if self.is_flatpak {
194198
if let Err(_err) = Command::new("flatpak-spawn")
195199
.arg("--host")
196200
.arg(&self.osd_cmd)
197-
.arg(&osd_arg)
201+
.arg(osd_arg)
198202
.spawn()
199203
{
200204
return action.perform();
201205
}
202-
} else {
203-
if let Err(_err) = Command::new("cosmic-osd").arg(osd_arg).spawn() {
204-
return action.perform();
205-
}
206+
} else if let Err(_err) = Command::new("cosmic-osd").arg(osd_arg).spawn() {
207+
return action.perform();
206208
}
207209

208210
return close_popup(self.popup);
@@ -218,7 +220,7 @@ impl Application for LogoMenu {
218220
}
219221
}
220222
Message::Run(action) => {
221-
if is_flatpak()
223+
if self.is_flatpak
222224
&& action != "cosmic-ext-logomenu-settings"
223225
&& action != "cosmic-logomenu-settings"
224226
{

liblog/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub struct MenuItem {
8585
}
8686
impl MenuItem {
8787
pub fn item_type(&self) -> MenuItemType {
88-
self.item_type.clone()
88+
self.item_type
8989
}
9090
pub fn label(&self) -> Option<String> {
9191
self.label.clone()

settings/src/app.rs

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,8 @@ impl cosmic::Application for AppModel {
118118
let menu_items = get_menu_items();
119119

120120
// get custom logo status and path
121-
let custom_logo_active = match load_config("custom_logo_active", CONFIG_VER) {
122-
Some(val) => val,
123-
None => false,
124-
};
125-
let custom_logo_path = match load_config("custom_logo_path", CONFIG_VER) {
126-
Some(val) => val,
127-
None => "".to_owned(),
128-
};
121+
let custom_logo_active = load_config("custom_logo_active", CONFIG_VER).unwrap_or_default();
122+
let custom_logo_path = load_config("custom_logo_path", CONFIG_VER).unwrap_or_default();
129123

130124
let menu_types = vec![MenuItemType::LaunchAction, MenuItemType::PowerAction];
131125
let menu_type_labels: Vec<String> =
@@ -222,17 +216,16 @@ impl cosmic::Application for AppModel {
222216
page_content = page_content.push(Space::with_height(padding));
223217

224218
// Set currently selected logo
225-
let logo_widget =
226-
if self.custom_logo_active == true && Path::new(&self.custom_logo_path).exists() {
227-
widget::svg(widget::svg::Handle::from_path(&self.custom_logo_path))
228-
.symbolic(false)
229-
.width(150)
230-
} else {
231-
let logo_bytes = IMAGES[&self.selected_logo_name];
232-
widget::svg(widget::svg::Handle::from_memory(logo_bytes.0))
233-
.symbolic(logo_bytes.1)
234-
.width(150)
235-
};
219+
let logo_widget = if self.custom_logo_active && Path::new(&self.custom_logo_path).exists() {
220+
widget::svg(widget::svg::Handle::from_path(&self.custom_logo_path))
221+
.symbolic(false)
222+
.width(150)
223+
} else {
224+
let logo_bytes = IMAGES[&self.selected_logo_name];
225+
widget::svg(widget::svg::Handle::from_memory(logo_bytes.0))
226+
.symbolic(logo_bytes.1)
227+
.width(150)
228+
};
236229

237230
// Display logo header
238231
page_content = page_content.push(
@@ -248,14 +241,12 @@ impl cosmic::Application for AppModel {
248241
// Menu settings
249242
let mut menu_settings = settings::section().add({
250243
Element::from(
251-
settings::item::builder(fl!("use-custom-logo")).control(
252-
toggler(self.custom_logo_active)
253-
.on_toggle(|value| Message::ToggleCustomLogo(value)),
254-
),
244+
settings::item::builder(fl!("use-custom-logo"))
245+
.control(toggler(self.custom_logo_active).on_toggle(Message::ToggleCustomLogo)),
255246
)
256247
});
257-
if self.custom_logo_active == true {
258-
let file_name = if &self.custom_logo_path != "" {
248+
if self.custom_logo_active {
249+
let file_name = if !&self.custom_logo_path.is_empty() {
259250
Path::new(&self.custom_logo_path)
260251
.file_name()
261252
.unwrap()
@@ -348,7 +339,7 @@ impl cosmic::Application for AppModel {
348339
let mut label_string = label;
349340
let command_string = menu_item.command().unwrap_or_default();
350341

351-
if command_string != "" {
342+
if !command_string.is_empty() {
352343
label_string.push_str(" :: ");
353344
label_string.push_str(&command_string);
354345
}
@@ -645,19 +636,16 @@ impl cosmic::Application for AppModel {
645636
.set_directory("~/")
646637
.pick_file();
647638

648-
match file {
649-
Some(path) => {
650-
let path_string = path.to_str().unwrap_or("");
651-
update_config(self.config.clone(), "custom_logo_path", &path_string);
652-
self.custom_logo_path = path_string.to_owned();
653-
}
654-
None => {}
639+
if let Some(path) = file {
640+
let path_string = path.to_str().unwrap_or("");
641+
update_config(self.config.clone(), "custom_logo_path", &path_string);
642+
self.custom_logo_path = path_string.to_owned();
655643
};
656644
}
657645

658646
Message::AddItem(item_type) => {
659647
let new_item = MenuItem {
660-
item_type: item_type.clone(),
648+
item_type,
661649
label: match &item_type {
662650
MenuItemType::LaunchAction => Some(fl!("new-launcher")),
663651
_ => None,

settings/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ fn is_running() -> bool {
3535
return false;
3636
}
3737

38-
if let Some(exe_path) = process.exe().and_then(|p| p.canonicalize().ok()) {
39-
if current_exe.as_ref() == Some(&exe_path) {
40-
return true;
41-
}
38+
if let Some(exe_path) = process.exe().and_then(|p| p.canonicalize().ok())
39+
&& current_exe.as_ref() == Some(&exe_path)
40+
{
41+
return true;
4242
}
4343

4444
false

0 commit comments

Comments
 (0)