Skip to content

Commit c579181

Browse files
committed
Format code and add GTK dependencies
CI now installs GTK development dependencies on Linux. Rust code simplified to use let-else chains and range patterns where applicable.
1 parent a720d10 commit c579181

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ jobs:
4141
- name: cargo test (core)
4242
run: cargo test -p something_bg_core
4343

44+
- name: Install GTK deps (Linux)
45+
if: runner.os == 'Linux'
46+
run: |
47+
sudo apt-get update
48+
sudo apt-get install -y pkg-config libgtk-3-dev libayatana-appindicator3-dev
49+
4450
- name: cargo check (mac app)
4551
if: runner.os == 'macOS'
4652
run: cargo check -p something_bg

core/src/config.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,25 @@ impl Config {
146146

147147
let mut tunnels = Vec::new();
148148

149-
if let Some(tunnels_value) = table.get("tunnels") {
150-
if let Some(tunnels_table) = tunnels_value.as_table() {
151-
// With preserve_order feature, this iteration maintains order
152-
for (key, value) in tunnels_table {
153-
let tunnel_config: TunnelConfig = value.clone().try_into()?;
154-
tunnels.push((key.clone(), tunnel_config));
155-
}
149+
if let Some(tunnels_value) = table.get("tunnels")
150+
&& let Some(tunnels_table) = tunnels_value.as_table()
151+
{
152+
// With preserve_order feature, this iteration maintains order
153+
for (key, value) in tunnels_table {
154+
let tunnel_config: TunnelConfig = value.clone().try_into()?;
155+
tunnels.push((key.clone(), tunnel_config));
156156
}
157157
}
158158

159159
let mut schedules = Vec::new();
160160

161-
if let Some(tasks_value) = table.get("schedules") {
162-
if let Some(tasks_table) = tasks_value.as_table() {
163-
// With preserve_order feature, this iteration maintains order
164-
for (key, value) in tasks_table {
165-
let task_config: ScheduledTaskConfig = value.clone().try_into()?;
166-
schedules.push((key.clone(), task_config));
167-
}
161+
if let Some(tasks_value) = table.get("schedules")
162+
&& let Some(tasks_table) = tasks_value.as_table()
163+
{
164+
// With preserve_order feature, this iteration maintains order
165+
for (key, value) in tasks_table {
166+
let task_config: ScheduledTaskConfig = value.clone().try_into()?;
167+
schedules.push((key.clone(), task_config));
168168
}
169169
}
170170

core/src/scheduler.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn load_task_states(path: &PathBuf) -> HashMap<String, TaskState> {
3232
return HashMap::new();
3333
}
3434

35-
match fs::read_to_string(&path) {
35+
match fs::read_to_string(path) {
3636
Ok(contents) => match toml::from_str(&contents) {
3737
Ok(states) => {
3838
info!("Loaded task states from {}", path.display());
@@ -53,16 +53,16 @@ fn load_task_states(path: &PathBuf) -> HashMap<String, TaskState> {
5353
/// Save task states to disk
5454
fn save_task_states(path: &PathBuf, states: &HashMap<String, TaskState>) {
5555
// Ensure the directory exists
56-
if let Some(parent) = path.parent() {
57-
if let Err(e) = fs::create_dir_all(parent) {
58-
error!("Failed to create state directory: {}", e);
59-
return;
60-
}
56+
if let Some(parent) = path.parent()
57+
&& let Err(e) = fs::create_dir_all(parent)
58+
{
59+
error!("Failed to create state directory: {}", e);
60+
return;
6161
}
6262

6363
match toml::to_string_pretty(&states) {
6464
Ok(toml_content) => {
65-
if let Err(e) = fs::write(&path, toml_content) {
65+
if let Err(e) = fs::write(path, toml_content) {
6666
error!("Failed to write task state file: {}", e);
6767
} else {
6868
debug!("Saved task states to {}", path.display());
@@ -547,7 +547,7 @@ fn format_relative_datetime(dt: &DateTime<Local>) -> String {
547547
/// Return ordinal suffix for a day (1st, 2nd, 3rd, 4th, ...).
548548
fn ordinal(day: u32) -> String {
549549
let suffix = match day % 100 {
550-
11 | 12 | 13 => "th",
550+
11..=13 => "th",
551551
_ => match day % 10 {
552552
1 => "st",
553553
2 => "nd",

core/src/tunnel.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ impl TunnelManager {
7474
let new_path = cmd
7575
.get_envs()
7676
.find(|(key, _)| key == &OsStr::new("PATH"))
77-
.map(|(_, value)| {
77+
.and_then(|(_, value)| {
7878
value.map(|path| format!("{}:{}", config_path, path.to_string_lossy()))
7979
})
80-
.flatten()
8180
.unwrap_or_else(|| config_path.clone());
8281

8382
debug!("Update PATH to: {new_path}");

0 commit comments

Comments
 (0)