diff --git a/blasta.py b/blasta.py index b216511..97b5db4 100644 --- a/blasta.py +++ b/blasta.py @@ -38,6 +38,7 @@ import tomli_w from typing import Optional import urllib.parse import uvicorn +import webbrowser import xml.etree.ElementTree as ET @@ -266,6 +267,7 @@ class HttpInstance: self.app.mount('/data', StaticFiles(directory='data'), name='data') self.app.mount('/export', StaticFiles(directory='export'), name='export') self.app.mount('/graphic', StaticFiles(directory='graphic'), name='graphic') + self.app.mount('/script', StaticFiles(directory='script'), name='script') self.app.mount('/stylesheet', StaticFiles(directory='stylesheet'), name='stylesheet') filename_configuration = 'configuration.toml' @@ -5318,7 +5320,11 @@ def main(): return http_instance.app app = main() +webbrowser.open('http://localhost:8000/help/about') +# TODO Check first time +webbrowser.open_new_tab('http://localhost:8000') # FIXME if __name__ == '__main__': - uvicorn.run(app, host='127.0.0.1', port=8000, reload=True) + uvicorn.run(app, host='localhost', port=8000, reload=True) + diff --git a/blasta_client.py b/blasta_client.py new file mode 100644 index 0000000..b840341 --- /dev/null +++ b/blasta_client.py @@ -0,0 +1,39 @@ +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: {} '.format(sys.argv[0])) + sys.exit(1) + + url_instance = sys.argv[1] + html_view = HtmlView(url_instance) + html_view.setup() diff --git a/blasta_client.sh b/blasta_client.sh new file mode 100755 index 0000000..6b6c36a --- /dev/null +++ b/blasta_client.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +unset http_proxy +WEBKIT_DISABLE_DMABUF_RENDERER=1 python blasta_client.py http://localhost:8000 diff --git a/script/regulator.js b/script/regulator.js new file mode 100644 index 0000000..0eb521c --- /dev/null +++ b/script/regulator.js @@ -0,0 +1,20 @@ +document.addEventListener('DOMContentLoaded', () => { + window.addEventListener('pywebviewready', () => { + // Attach event listeners to all anchor elements + document.querySelectorAll('a').forEach(element => { + element.addEventListener('click', regulator); + }); + }); +}); + +// This function will be called when an anchor is clicked +function regulator(event) { + event.preventDefault(); // Prevent the default link behavior + const url = this.href; // Get the URL from the clicked link + + // Call the exposed Python function + window.pywebview.api.regulator(url) + .catch(error => { + console.error("Error calling regulator:", error); + }); +} diff --git a/stylesheet/stylesheet.xsl b/stylesheet/stylesheet.xsl index daa3256..d2d2ccf 100644 --- a/stylesheet/stylesheet.xsl +++ b/stylesheet/stylesheet.xsl @@ -58,8 +58,9 @@ xmlns:atom='http://www.w3.org/2005/Atom'> <xsl:value-of select='atom:title'/> - + +