gemini handler added.

This commit is contained in:
Sam Hunter 2021-08-11 16:01:38 +02:00
parent ecbf2b66d2
commit e2a242c58e
2 changed files with 15 additions and 3 deletions

View File

@ -28,12 +28,13 @@ class DefaultUser:
settingsfile: Path = datadir / PATHS.settingsfile
lastlogin: str = "0.0"
browser: str = "lynx"
gemini: str = "amfora"
def save(self):
"""Saves config data to file"""
config = configparser.ConfigParser()
config["User Status"] = {"lastlogin": time()}
config["User Settings"] = {"browser": self.browser}
config["User Settings"] = {"browser": self.browser, "gemini": self.gemini}
with open(self.settingsfile, "w") as file:
config.write(file)
@ -44,6 +45,7 @@ class DefaultUser:
if len(ret) > 0:
self.lastlogin = config["User Status"]["lastlogin"]
self.browser = config["User Settings"]["browser"]
self.gemini = config["User Settings"]["gemini"]
USER = DefaultUser()

View File

@ -222,12 +222,21 @@ def view_link_in_browser(url):
+ " is not installed on your system. Ask your sysadmin to install it."
)
return
if which(config.USER.gemini) is None:
print(
"Sorry, "
+ config.USER.gemini
+ " is not installed on your system. Ask your sysadmin to install it."
)
return
url_scheme = urlparse(url).scheme
if url_scheme in ["gopher", "https", "http"]:
subprocess.call([config.USER.browser, url])
elif url_scheme in ["gemini"]:
subprocess.call([config.USER.gemini, url])
else:
print("Sorry, that url doesn't start with gopher://, http:// or https://")
print("Sorry, that url doesn't start with gopher://, http://, https:// or gemini://")
try_anyway = input(
"Do you want to try it in {} anyway? Y/[N]".format(config.USER.browser)
).lower()
@ -418,7 +427,8 @@ def menu_view_thread_details(post_id):
option_text = "Type {} to reply, {} to view in {}, {} to search, {} to post a new link, {} to go back, or {} to quit: ".format(
style_text("r", True, "underline"),
style_text("b", True, "underline"),
config.USER.browser,
# config.USER.browser,
"browser",
style_text("s", True, "underline"),
style_text("p", True, "underline"),
style_text("m", True, "underline"),