Blasta/blasta_client.py

40 lines
1.2 KiB
Python
Raw Permalink Normal View History

import webview
import subprocess
import sys
class HtmlView:
def __init__(self, url_instance):
self.url_instance = url_instance
def regulator(self, uri):
# Check if the URL is not from url_instance
if not uri.startswith(self.url_instance):
try:
# Open the link using xdg-open
subprocess.run(['xdg-open', uri], check=True)
except subprocess.CalledProcessError as e:
print(f"Failed to open URL: {uri}. Error: {e}")
else:
# If it is from url_instance, just load it in the webview
#webview.load_url(uri)
#webview.evaluate(f"window.location.href = '{uri}';")
webview.windows[0].load_url(uri)
def setup(self):
# Create a webview window
window = webview.create_window('Blasta', self.url_instance)
# Bind the link click event to the regulator function
window.expose(self.regulator)
# Start the webview application
webview.start()
if __name__ == '__main__':
if len(sys.argv) != 2:
print('Usage: {} <URL_OF_A_BLASTA_INSTANCE>'.format(sys.argv[0]))
sys.exit(1)
url_instance = sys.argv[1]
html_view = HtmlView(url_instance)
html_view.setup()