Rewrite CEF browser as child of Kivy window (v2)

v1 created a separate Win32 window — same problem as external Chrome.
v2 creates CEF as a CHILD WINDOW of Kivy's SDL_app window:
  - No separate taskbar entry
  - No z-order fighting (CEF is INSIDE Kivy)
  - No desktop flash
  - CEF message loop pumped via Kivy Clock (main thread)
  - Resize handler attached so CEF follows Kivy window changes
  - build.spec includes cef_browser in hidden imports
This commit is contained in:
ske087
2026-07-24 16:22:33 +03:00
parent 5a030671a2
commit 12f2880201
3 changed files with 154 additions and 183 deletions
+29 -3
View File
@@ -115,7 +115,12 @@ def _windows_screen_activity(self, dt):
_CEF_BROWSER = None
def _get_cef_browser():
"""Return the shared CefBrowser singleton, or None if unavailable."""
"""Return the shared CefBrowser singleton, or None if unavailable.
v2 embeds CEF as a CHILD WINDOW inside Kivy's SDL_app window.
This means: no separate taskbar entry, no z-order fighting,
no desktop flash, no taskkill needed.
"""
global _CEF_BROWSER
if _CEF_BROWSER is None:
try:
@@ -367,16 +372,37 @@ def _patch_main():
# ── Strategy 1: CEF embedded browser ────────────────────────
cef_browser = _get_cef_browser()
if cef_browser is not None:
Logger.info(f"SignagePlayer: Opening weblink via CEF embedded browser: {url}")
Logger.info(f"SignagePlayer: Opening weblink via CEF (embedded in Kivy): {url}")
try:
self.ids.content_area.opacity = 0
except Exception:
pass
# Attach resize handler so CEF follows Kivy window resizes
from kivy.core.window import Window as KivyWindow
_orig_on_resize = getattr(KivyWindow, '_on_resize', None)
def _cef_resize(*args):
try:
w, h = KivyWindow.size
cef_browser.resize(int(w), int(h))
except Exception:
pass
if _orig_on_resize:
try:
return _orig_on_resize(*args)
except Exception:
pass
KivyWindow._on_resize = _cef_resize
# Bind to size event as well
try:
KivyWindow.bind(size=_cef_resize)
except Exception:
pass
cef_browser.show(url)
Clock.unschedule(self.next_media)
self._start_inactivity_watchdog(duration)
self.preload_next_media()
Logger.info("SignagePlayer: CEF browser launched successfully")
Logger.info("SignagePlayer: CEF embedded browser visible (inside Kivy window)")
return True
# ── Strategy 2: Subprocess Chrome/Edge (fallback) ────────────