Skip to content

Commit b2771ba

Browse files
committed
[test] re;ease 0.3.14.post40
1 parent 9727648 commit b2771ba

3 files changed

Lines changed: 48 additions & 9 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespaces = false
1313

1414
[project]
1515
name = "pytron-kit"
16-
version = "0.3.14.post39"
16+
version = "0.3.14.post40"
1717
description = "An Electron-like library for Python to build Cross Platform Apps"
1818
readme = "README.md"
1919
requires-python = ">=3.7"

pytron/engines/native/src/webview.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,20 @@ impl NativeWebview {
348348
});
349349

350350
let webview = builder.build()
351-
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(format!("Failed to build WebView: {}", e)))?;
351+
.map_err(|e| {
352+
#[cfg(target_os = "linux")]
353+
{
354+
use raw_window_handle::HasRawWindowHandle;
355+
let handle_kind = format!("{:?}", window.raw_window_handle());
356+
PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(format!(
357+
"Failed to build WebView: {}\nHandle: {}", e, handle_kind
358+
))
359+
}
360+
#[cfg(not(target_os = "linux"))]
361+
{
362+
PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(format!("Failed to build WebView: {}", e))
363+
}
364+
})?;
352365

353366
// Re-hide on Linux after successful build so it stays hidden until explicitly shown
354367
#[cfg(target_os = "linux")]

pytron/webview.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,29 @@ def _init_native_engine(self, config):
128128
f"Cause: {details}\n"
129129
)
130130

131+
orig_wayland = None
132+
orig_winit = None
133+
orig_gdk = None
134+
is_wayland = False
135+
131136
if sys.platform.startswith("linux"):
132137
self.logger.warning("Linux Native Engine is still experimental.")
133138
import os
134139

135140
session_type = os.environ.get("XDG_SESSION_TYPE", "").lower()
136141
if session_type == "wayland":
137-
if not os.environ.get("WINIT_UNIX_BACKEND"):
138-
self.logger.info(
139-
"Wayland session detected, forcing WINIT_UNIX_BACKEND=x11 for better native stability."
140-
)
141-
os.environ["WINIT_UNIX_BACKEND"] = "x11"
142-
if not os.environ.get("GDK_BACKEND"):
143-
os.environ["GDK_BACKEND"] = "x11"
142+
is_wayland = True
143+
self.logger.info(
144+
"Wayland session detected. Forcing X11 backend temporarily to initialize native webview."
145+
)
146+
orig_wayland = os.environ.get("WAYLAND_DISPLAY")
147+
orig_winit = os.environ.get("WINIT_UNIX_BACKEND")
148+
orig_gdk = os.environ.get("GDK_BACKEND")
149+
150+
if "WAYLAND_DISPLAY" in os.environ:
151+
del os.environ["WAYLAND_DISPLAY"]
152+
os.environ["WINIT_UNIX_BACKEND"] = "x11"
153+
os.environ["GDK_BACKEND"] = "x11"
144154

145155
raw_url = config.get("url", "")
146156
debug = config.get("debug", False)
@@ -196,6 +206,22 @@ def _init_native_engine(self, config):
196206
) from e
197207

198208
raise NativeEngineError(f"Failed to initialize Native WebView: {e}") from e
209+
finally:
210+
if is_wayland:
211+
import os
212+
213+
if orig_wayland is not None:
214+
os.environ["WAYLAND_DISPLAY"] = orig_wayland
215+
else:
216+
os.environ.pop("WAYLAND_DISPLAY", None)
217+
if orig_winit is not None:
218+
os.environ["WINIT_UNIX_BACKEND"] = orig_winit
219+
else:
220+
os.environ.pop("WINIT_UNIX_BACKEND", None)
221+
if orig_gdk is not None:
222+
os.environ["GDK_BACKEND"] = orig_gdk
223+
else:
224+
os.environ.pop("GDK_BACKEND", None)
199225

200226
def _setup_native_window(self, config):
201227
"""Applies window settings and platform helpers for native engine."""

0 commit comments

Comments
 (0)