Skip to content

Conversation

@angelofallars
Copy link
Contributor

The most visible change in this PR is that I changed several function / variable names to improve clarity. I've also added some blank lines in between some lines of code.

Examples:

  • check_config_xdg() -> fetch_xdg_config_path()
  • check_keyboard() -> check_device_is_keyboard()
  • paused -> execution_is_paused

permission_check is now check_user_permissions, and it now returns a Result<T, E> as opposed to exiting the program within the function. I made it so that all calls to exit() are in fn main() so that contributors can follow the logic of the program better.

The send_command function was defined in main. I moved it outside as function definitions shouldn't go in main.

There was also improper indentation, which resulted in some unclean closing braces in main:

                    }
                }
            }
        }
        }
    }
}

Peculiarly, the second line below is inside the Some((i, Ok(event))) block yet they're of the same indentation.

            Some((i, Ok(event))) = keyboard_stream_map.next() => {
            let keyboard_state = &mut keyboard_states[i];

I found that a large part of the code was under an if let block, if let InputEventKind::Key(key) = event.kind(). I turned the if let into a simple guard clause to fix the indentation.

@angelofallars angelofallars requested review from EdenQwQ, Shinyzenith and vainiovano and removed request for vainiovano March 8, 2022 05:28
@angelofallars angelofallars changed the title refactor: improve daemon code refactor: improve daemon / server code Mar 8, 2022
refactor(daemon): take out fn send_command out of main fn

refactor(daemon): move sock_send & send_command to top

refactor(daemon): rename permission_check function

Rename permission_check to check_user_permissions for better clarity.

refactor: move exit() call out check_user_perms

Move the exit call in check_user_permissions
to the main function for more clarity, using an `if let` structure.

refactor: rename check_keyboard

check_keyboard -> check_device_is_keyboard

refactor: name set_flags to set_command_line_args

style: add one more blank line

refactor: rename check_config_xdg

check_config_xdg -> fetch_xdg_config_path

refactor(daemon): remove unneeded comment

refactor: rename paused to execution_is_paused

style: add comments to explain event 1 / 0 keys

refactor(daemon): merge two if statements into one

refactor: make event.kind() if let, a guard clause

There was improper indentation to try and make the program
not as indented, but it made the code look a little less clean.

style: add blank lines in load_config closure

style: capitalize first word in comment

refactor(server): move sys command fn out of main

refactor(server): remove unneeded type annotation

refactor(server): rename pidfile & sockfile vars

pidfile -> pid_file_path
sockfile -> sock_file_path

refactor(server): rename addr var to address
@Shinyzenith
Copy link
Member

Squashed commits into 1 to keep tree clean.

@Shinyzenith Shinyzenith merged commit b26da39 into main Mar 8, 2022
@Shinyzenith Shinyzenith deleted the daemon-refactor branch March 8, 2022 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants