|
7 | 7 | from ctypes import c_int, c_char_p, c_void_p, CFUNCTYPE
|
8 | 8 | import ctypes.util
|
9 | 9 | import shutil
|
10 |
| - |
| 10 | +import logging |
11 | 11 | def _encode_c_string(s: str) -> bytes:
|
12 | 12 | return s.encode("utf-8")
|
13 | 13 |
|
@@ -70,33 +70,39 @@ def _get_download_urls():
|
70 | 70 | def _be_sure_libraries():
|
71 | 71 | """Ensure libraries exist and return paths."""
|
72 | 72 | if getattr(sys, 'frozen', False):
|
73 |
| - if hasattr(sys, '_MEIPASS'): |
74 |
| - base_dir = Path(sys._MEIPASS) |
75 |
| - else: |
76 |
| - base_dir = Path(sys.executable).parent / '_internal' |
| 73 | + # if hasattr(sys, '_MEIPASS'): |
| 74 | + # base_dir = Path(sys._MEIPASS) |
| 75 | + # else: |
| 76 | + # base_dir = Path(sys.executable).parent / '_internal'/'webview' |
| 77 | + base_dir = Path(sys.executable).parent / '_internal'/'webview' |
77 | 78 | else:
|
78 | 79 | base_dir = Path(__file__).parent
|
79 | 80 |
|
80 |
| - lib_dir = base_dir / "lib" |
| 81 | + #lib_dir = base_dir / "lib" |
| 82 | + lib_dir = base_dir |
| 83 | + logging.info(f"webview lib_dir: {lib_dir}") |
81 | 84 | lib_names = _get_lib_names()
|
| 85 | + logging.info(f"webview lib_names: {lib_names}") |
82 | 86 | lib_paths = [lib_dir / lib_name for lib_name in lib_names]
|
83 |
| - |
| 87 | + logging.info(f"webview lib_paths: {lib_paths}") |
84 | 88 | # Check if any library is missing
|
85 | 89 | missing_libs = [path for path in lib_paths if not path.exists()]
|
86 | 90 | if not missing_libs:
|
87 | 91 | return lib_paths
|
88 |
| - |
| 92 | + else: |
| 93 | + logging.warning(f"Missing libraries: {missing_libs}") |
89 | 94 | # Download or copy missing libraries
|
90 | 95 | download_urls = _get_download_urls()
|
91 |
| - system = platform.system().lower() |
92 | 96 |
|
93 | 97 | lib_dir.mkdir(parents=True, exist_ok=True)
|
94 | 98 |
|
95 | 99 | for url, lib_path in zip(download_urls, lib_paths):
|
96 | 100 | if lib_path.exists():
|
97 | 101 | continue
|
98 | 102 |
|
99 |
| - print(f"Getting library from {url}") |
| 103 | + print(f"Getting library from {url}, writing to {lib_path}") |
| 104 | + logging.warning(f"Getting library from {url}, writing to {lib_path}") |
| 105 | + |
100 | 106 | try:
|
101 | 107 | # Handle different URL types
|
102 | 108 | if url.startswith(("http://", "https://")):
|
@@ -130,7 +136,8 @@ def __init__(self):
|
130 | 136 | library_path = ctypes.util.find_library(lib_names[0])
|
131 | 137 | if not library_path:
|
132 | 138 | library_paths = _be_sure_libraries()
|
133 |
| - self.lib = ctypes.cdll.LoadLibrary(str(library_paths[0])) |
| 139 | + library_path = library_paths[0] |
| 140 | + self.lib = ctypes.cdll.LoadLibrary(str(library_path)) |
134 | 141 | except Exception as e:
|
135 | 142 | print(f"Failed to load webview library: {e}")
|
136 | 143 | raise
|
|
0 commit comments