port cli handling and uniqueness to gtk #722
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This is the long-term handling discussed in #680.
Before this PR, command line handling was done using argparse, uniqueness detection was done using psutil, and forwarding the command line to the running instance was done using the RPC server if it was configured.
This had some downsides: the RPC server was not available in all environments (e.g. if SafeEyes was not allowed to listen on the port), so it was made optional, and psutil detection was not perfect (any process with "safeeyes" in its cli would prevent SafeEyes from starting, and filtering it only to the current user was only implemented recently in #680). psutil also did not work correctly in flatpak, which is not allowed to read out all running processes.
However, GTK has native APIs for all of this.
Its command line parsing API is slightly less ergonomic than argparse, but the uniqueness detection (using DBus) is much more standardized and robust than the psutil approach - it also works inside of flatpak and without needing to listen on a port, and supports multi-user environments by default.
The command forwarding is also something GTK natively supports.
It should also be somewhat easier now to add more arguments (eg. adding
short
/long
options to--take-break
).Downsides of this:
logging
can only be used after startup, as we don't know whether--debug
was passed. Since we do less before startup now, this is just a small downside.do_handle_local_options
vsdo_command_line
- the former always runs, the latter only when it is the primary instance).This should also be a one-time cost - now that it is up and running, we shouldn't need to touch it much more.