Blasta/blasta_client.py
Schimon Jehudah, Adv. 0ab40eedec Python : Utilize XEP-0004: Data Forms to store configurations;
Python : Fix error in blasta_client.py (Thank you. yvo.);
XMPP   : Replace node xmpp:blasta:settings:0 by xmpp:blasta:configuration:0;
2024-09-11 07:44:18 +03:00

42 lines
1.3 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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('Failed to open URL: {}. Error: {}'.format(uri, 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()