Skip to content

Commit

Permalink
fix(linux): Correctly open files linked from help page
Browse files Browse the repository at this point in the history
This works around the issue where browsers installed as snap package
can't access files under `$HOME/.local`. Instead we now only open
external links with the browser. Local non-html files we open with
the default app, and links to local html file we open in webview
(like we did previously with `welcome.htm` files).

Fixes #9600.
  • Loading branch information
ermshiperete committed Sep 20, 2023
1 parent e6017e8 commit b764a1c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions linux/keyman-config/keyman_config/welcome.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python3

import logging
import os
import webbrowser

import gi
Expand Down Expand Up @@ -55,17 +56,25 @@ def __init__(self, parent, welcomeurl, keyboardname, newlyInstalled=False):
def doc_policy(self, web_view, decision, decision_type):
logging.info("Checking policy")
logging.debug("received policy decision request of type: {0}".format(decision_type.value_name))
if decision_type == WebKit2.PolicyDecisionType.NAVIGATION_ACTION or \
decision_type == WebKit2.PolicyDecisionType.NEW_WINDOW_ACTION:
if decision_type in [
WebKit2.PolicyDecisionType.NAVIGATION_ACTION,
WebKit2.PolicyDecisionType.NEW_WINDOW_ACTION,
]:
nav_action = decision.get_navigation_action()
request = nav_action.get_request()
uri = request.get_uri()
logging.debug("nav request is for uri %s", uri)
if "welcome.htm" not in uri:
logging.debug("opening uri %s in webbrowser")
if not uri.startswith("file://"):
logging.debug("opening external uri %s in webbrowser", uri)
webbrowser.open(uri)
decision.ignore()
return True
elif ".htm" not in uri:
cmd = f'xdg-open {uri}'
logging.debug('opening uri in default app: %s', cmd)
os.system(cmd)
decision.ignore()
return True
return False

def on_openweb_clicked(self, button):
Expand Down

0 comments on commit b764a1c

Please sign in to comment.