Skip to content

Commit a313ce6

Browse files
committed
chore: code cleanup
1 parent 6586bf6 commit a313ce6

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "hyprland-autoname-workspaces"
33
authors = ["Cyril Levis", "Maxim Baz"]
4-
version = "0.2.9"
4+
version = "0.2.10"
55
edition = "2021"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/main.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ impl Config {
3535
if !cfg_path.exists() {
3636
let mut config_file = File::create(&cfg_path).expect("Can't create config dir");
3737
let default_icons = r#"# Add your icons mapping
38-
# Take care to lowercase app name
39-
# and use double quote the key and the value
38+
# use double quote the key and the value
39+
# take class name from 'hyprctl clients'
4040
"DEFAULT" = ""
4141
"kitty" = "term"
4242
"firefox" = "browser"
@@ -51,26 +51,31 @@ impl Config {
5151
}
5252
}
5353

54-
fn main() -> Result<(), Box<dyn Error>> {
54+
fn main() {
5555
let cfg = Config::new();
5656
// Init
5757
let renamer = Arc::new(Renamer::new(cfg, Args::parse()));
58-
_ = renamer.renameworkspace();
58+
renamer
59+
.renameworkspace()
60+
.expect("App can't rename workspaces on start");
5961

6062
// Handle unix signals
61-
let mut signals = Signals::new([SIGINT, SIGTERM])?;
63+
let mut signals = Signals::new([SIGINT, SIGTERM]).expect("Can't listen on SIGINT or SIGTERM");
6264
let final_renamer = renamer.clone();
6365
thread::spawn(move || {
6466
for _ in signals.forever() {
65-
_ = final_renamer.reset_workspaces();
67+
match final_renamer.reset_workspaces() {
68+
Err(_) => println!("Workspaces name can't be cleared"),
69+
Ok(_) => println!("Workspaces name cleared, bye"),
70+
};
6671
process::exit(0);
6772
}
6873
});
6974

7075
// Run on window events
71-
renamer.start_listeners()?;
72-
73-
Ok(())
76+
renamer
77+
.start_listeners()
78+
.expect("Can't listen Hyprland events, sorry");
7479
}
7580

7681
struct Renamer {
@@ -109,14 +114,14 @@ impl Renamer {
109114
.collect::<HashMap<_, _>>();
110115

111116
for client in clients {
112-
let class = client.clone().class.to_lowercase();
117+
let class = client.class;
113118
let fullscreen = client.fullscreen;
114119
let icon = self.class_to_icon(&class);
115-
let workspace_id = client.clone().workspace.id;
116-
let is_dup = !deduper.insert(format!("{}-{}", workspace_id.clone(), icon));
120+
let workspace_id = client.workspace.id;
121+
let is_dup = !deduper.insert(format!("{workspace_id}-{icon}"));
117122
let should_dedup = self.args.dedup && is_dup;
118123

119-
self.workspaces.lock()?.insert(client.clone().workspace.id);
124+
self.workspaces.lock()?.insert(client.workspace.id);
120125

121126
let workspace = workspaces.entry(workspace_id).or_insert("".to_string());
122127

@@ -130,9 +135,8 @@ impl Renamer {
130135
}
131136

132137
workspaces
133-
.clone()
134138
.iter()
135-
.try_for_each(|(&id, apps)| rename_cmd(id, &apps.clone()))?;
139+
.try_for_each(|(&id, apps)| rename_cmd(id, &apps))?;
136140

137141
Ok(())
138142
}
@@ -183,7 +187,7 @@ impl Renamer {
183187
}
184188

185189
fn rename_cmd(id: i32, apps: &str) -> Result<(), Box<dyn Error>> {
186-
let text = format!("{}:{}", id.clone(), apps);
190+
let text = format!("{id}:{apps}");
187191
let content = (!apps.is_empty()).then_some(text.as_str());
188192
hyprland::dispatch!(RenameWorkspace, id, content)?;
189193

0 commit comments

Comments
 (0)