Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linux): Correctly open files linked from help page #9601

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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