mylinuxforwork / dotfiles-settings

GTK4 App to manage settings of the ML4W Dotfiles for Hyprland
5 stars 2 forks source link

Allow launching default applications containing spaces #1

Closed beaver700nh closed 3 weeks ago

beaver700nh commented 1 month ago

Hello,

I have just installed ML4W and must commend you on the wonderful work you have done on this project -- it improves Hyprland's accessibility and QOL so much.

Just one small suggestion I'd like to make: currently when I set my default text editor to kitty nvim, I cannot use "edit file" options such as "Edit Current Variation" in ml4w-settings because it tries to execute a program called kitty nvim which does not exist. The following is the error printed to the console:

Traceback (most recent call last):
  File "/tmp/.mount_ML4W_D2XXX3h/usr/bin/ml4w-dotfiles-settings.py", line 543, in on_edit_monitors
    self.on_open(widget, self.default_editor.get_text(), "hypr/conf/monitors/" + f)
  File "/tmp/.mount_ML4W_D2XXX3h/usr/bin/ml4w-dotfiles-settings.py", line 590, in on_open
    subprocess.Popen([a, self.dotfiles + u])
  File "/usr/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'kitty nvim'

I propose roughly the following changes to ml4w-dotfiles-settings.py:

+       1 import shlex
  ... ... ...
  589 590     def on_open(self, widget, a, u):
- 590 591         subprocess.Popen([a, self.dotfiles + u])
+ 590 591         a = shlex.split(a, posix=False)
+ 591 592         subprocess.Popen([*a, self.dotfiles + u])

This splits the executable parameter of on_open on spaces (respecting quoted strings) and passes them as individual arguments to subprocess.Popen. This causes the requested program to be executed correctly; i.e. first token is a program name, subsequent tokens are arguments to said program. That should hopefully fix my issue, and also allow people to specify command-line arguments to their default applications as well.

A possible workaround in the meantime is to create a program like so:

kitty --you-get-a-flag --you-get-a-flag --everybody-gets-a-flag --more-arguments foo bar baz "$@"

When this program is placed in $PATH, ml4w-settings should be able to execute it and call my desired application and pass additional arguments (such as which file to edit) as it pleases. However, I find this solution kind of janky as not only would I have to remember to maintain such a program but it would also defeat the purpose of having a graphical way to configure default applications.

Cheers, beaver700nh

mylinuxforwork commented 1 month ago

Thank you so much for your feedback and detailed explanation. I will check and implement accordingly.

mylinuxforwork commented 1 month ago

@beaver700nh Just pushed an update on the main branch. Can you test again? Thanks for your support.

beaver700nh commented 1 month ago

Hello, just updated to 2.9.5RL - Seems the updater throws a non-fatal error:

 ____           _                   ____       _   _   _                 
|  _ \ ___  ___| |_ ___  _ __ ___  / ___|  ___| |_| |_(_)_ __   __ _ ___ 
| |_) / _ \/ __| __/ _ \| '__/ _ \ \___ \ / _ \ __| __| | '_ \ / _` / __|
|  _ <  __/\__ \ || (_) | | |  __/  ___) |  __/ |_| |_| | | | | (_| \__ \
|_| \_\___||___/\__\___/|_|  \___| |____/ \___|\__|\__|_|_| |_|\__, |___/
                                                               |___/     

Traceback (most recent call last):
  File "/home/bun6502/Downloads/dotfiles/install/restore.py", line 187, in <module>
    ml4wrestore = ML4WRestore()
                  ^^^^^^^^^^^^^
  File "/home/bun6502/Downloads/dotfiles/install/restore.py", line 64, in __init__
    self.replaceInFileCheckpoint("waybar/modules.json", "persistent-workspaces",'"*"', text)
  File "/home/bun6502/Downloads/dotfiles/install/restore.py", line 159, in replaceInFileCheckpoint
    file = open(self.dotfiles + f, 'r')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/bun6502/dotfiles/waybar/modules.json'

I don't think I've modified the stock waybar config at all, so it shouldn't be because I removed that file, but I digress. It looks like the "Edit" button now throws a different error:

Traceback (most recent call last):
  File "/tmp/.mount_ML4W_DNJDHTq/usr/bin/ml4w-dotfiles-settings.py", line 532, in on_edit_environments
    self.on_open(widget, self.default_editor.get_text(), "hypr/conf/environments/" + f)
  File "/tmp/.mount_ML4W_DNJDHTq/usr/bin/ml4w-dotfiles-settings.py", line 590, in on_open
    a = shlex.split(a, posix=False)
        ^^^^^
NameError: name 'shlex' is not defined. Did you forget to import 'shlex'?

Thanks, beaver700nh

mylinuxforwork commented 1 month ago

Can you try again with the latest RL?

beaver700nh commented 3 weeks ago

Hi, sorry for the delay; I was away. I just tried with 2.9.6RL and it seems to work great! Thanks!