clan-app: Working webview from webview lib
This commit is contained in:
@@ -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"))
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,8 +41,12 @@ def _be_sure_libraries():
|
||||
base_dir = Path(sys.executable).parent / '_internal'
|
||||
else:
|
||||
base_dir = Path(__file__).parent
|
||||
from ctypes.util import find_library
|
||||
|
||||
lib_dir = base_dir / "lib"
|
||||
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]
|
||||
|
||||
@@ -57,28 +55,6 @@ def _be_sure_libraries():
|
||||
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):
|
||||
|
||||
@@ -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
|
||||
'';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user