Allow for browser program to contain arguments

This specifically fixes opening firefox in a flatpak, where previously
fenen would error if the browser option was set to something like:

	flatpak run org.mozilla.firefox

This fix also makes the "program not found" error more user friendly and
allows fenen to keep running even if the browser program was not found.
This commit is contained in:
Jake Bauer 2023-11-02 14:29:12 +01:00
parent e1c34dc059
commit bbda9b9ed9
1 changed files with 16 additions and 13 deletions

View File

@ -225,21 +225,24 @@ def get_url(index):
def open_in_browser(indices=None):
if not indices:
subprocess.Popen(
[conf.get_value("browser"), ui.data["post_url"]], stdout=subprocess.DEVNULL
browser = conf.get_value("browser").split(" ")
try:
if not indices:
subprocess.Popen(browser + [ui.data["post_url"]], stdout=subprocess.DEVNULL)
return
indices = interpret_range(indices)
for i in indices:
url = get_url(i)
if url:
subprocess.Popen(browser + [url], stdout=subprocess.DEVNULL)
sleep(0.1) # Wait a bit so the browser opens URLs in the correct order
else:
print(f"Entry {i + 1} has no associated URL.")
except FileNotFoundError:
print(
f"Error opening browser: could not find the program '{' '.join(browser)}'."
)
return
indices = interpret_range(indices)
for i in indices:
url = get_url(i)
if url:
subprocess.Popen(
[conf.get_value("browser"), url], stdout=subprocess.DEVNULL
)
sleep(0.1) # Wait a bit so the browser opens URLs in the correct order
else:
print(f"Entry {i + 1} has no associated URL.")
def download_entry(indices=None):