clan-app: Working webview from webview lib

This commit is contained in:
Qubasa
2025-01-04 00:44:52 +01:00
parent ea5a2a9447
commit 64f5801343
6 changed files with 25 additions and 36 deletions

View File

@@ -4,6 +4,7 @@ from pathlib import Path
module_path = Path(__file__).parent.parent.absolute()
sys.path.insert(0, str(module_path))
sys.path.insert(0, str(module_path.parent / "clan_cli"))

View File

@@ -1,18 +1,28 @@
import logging
import sys
# Remove working directory from sys.path
if "" in sys.path:
sys.path.remove("")
from clan_cli.profiler import profile
from clan_app.app import MainApplication
log = logging.getLogger(__name__)
from urllib.parse import quote
from clan_app.deps.webview.webview import Webview
@profile
def main(argv: list[str] = sys.argv) -> int:
html = """
<html>
<body>
<h1>Hello from Python Webview!</h1>
</body>
</html>
"""
webview = Webview()
webview.navigate(f"data:text/html,{quote(html)}")
webview.run()
app = MainApplication()
return app.run(argv)

View File

@@ -32,12 +32,6 @@ def _get_lib_names():
else: # linux
return ["libwebview.so"]
def _get_download_urls():
"""Get the appropriate download URLs based on the platform."""
version = _get_webview_version()
return [f"https://github.com/webview/webview_deno/releases/download/{version}/{lib_name}"
for lib_name in _get_lib_names()]
def _be_sure_libraries():
"""Ensure libraries exist and return paths."""
if getattr(sys, 'frozen', False):
@@ -47,38 +41,20 @@ def _be_sure_libraries():
base_dir = Path(sys.executable).parent / '_internal'
else:
base_dir = Path(__file__).parent
lib_dir = base_dir / "lib"
from ctypes.util import find_library
lib_dir = os.environ.get("WEBVIEW_LIB_DIR")
if not lib_dir:
raise RuntimeError("WEBVIEW_LIB_DIR environment variable is not set")
lib_dir = Path(lib_dir)
lib_names = _get_lib_names()
lib_paths = [lib_dir / lib_name for lib_name in lib_names]
# Check if any library is missing
missing_libs = [path for path in lib_paths if not path.exists()]
if not missing_libs:
return lib_paths
# Download missing libraries
download_urls = _get_download_urls()
system = platform.system().lower()
lib_dir.mkdir(parents=True, exist_ok=True)
for url, lib_path in zip(download_urls, lib_paths):
if lib_path.exists():
continue
print(f"Downloading library from {url}")
try:
req = urllib.request.Request(
url,
headers={'User-Agent': 'Mozilla/5.0'}
)
with urllib.request.urlopen(req) as response, open(lib_path, 'wb') as out_file:
out_file.write(response.read())
except Exception as e:
raise RuntimeError(f"Failed to download library: {e}")
return lib_paths
class _WebviewLibrary:
def __init__(self):

View File

@@ -9,7 +9,7 @@ description = "clan app"
dynamic = ["version"]
scripts = { clan-app = "clan_app:main" }
[project.urls]
[project.urls]
Homepage = "https://clan.lol/"
Documentation = "https://docs.clan.lol/"
Repository = "https://git.clan.lol/clan/clan-core"

View File

@@ -66,5 +66,7 @@ mkShell {
export XDG_DATA_DIRS=${gtk4}/share/gsettings-schemas/gtk4-4.14.4:$XDG_DATA_DIRS
export XDG_DATA_DIRS=${gsettings-desktop-schemas}/share/gsettings-schemas/gsettings-desktop-schemas-46.0:$XDG_DATA_DIRS
export WEBVIEW_LIB_DIR=${webview-wrapper}/lib
'';
}