@@ -24,6 +24,9 @@ document.addEventListener("DOMContentLoaded", () => {
2424// This bridges the HTML5 Fullscreen API to Tauri's native window fullscreen
2525// Works for all video sites (YouTube, Vimeo, Bilibili, etc.)
2626( function ( ) {
27+ if ( window . __PAKE_FULLSCREEN_POLYFILL__ ) return ;
28+ window . __PAKE_FULLSCREEN_POLYFILL__ = true ;
29+
2730 function initFullscreenPolyfill ( ) {
2831 if ( ! window . __TAURI__ || ! document . head ) {
2932 setTimeout ( initFullscreenPolyfill , 100 ) ;
@@ -37,11 +40,13 @@ document.addEventListener("DOMContentLoaded", () => {
3740 let originalParent = null ;
3841 let originalNextSibling = null ;
3942 let wasInBody = false ;
43+ let monitorId = null ;
4044
4145 // Inject fullscreen styles
42- const styleEl = document . createElement ( "style" ) ;
43- styleEl . id = "pake-fullscreen-style" ;
44- styleEl . textContent = `
46+ if ( ! document . getElementById ( "pake-fullscreen-style" ) ) {
47+ const styleEl = document . createElement ( "style" ) ;
48+ styleEl . id = "pake-fullscreen-style" ;
49+ styleEl . textContent = `
4550 body.pake-fullscreen-active {
4651 overflow: hidden !important;
4752 }
@@ -65,7 +70,28 @@ document.addEventListener("DOMContentLoaded", () => {
6570 object-fit: contain !important;
6671 }
6772 ` ;
68- document . head . appendChild ( styleEl ) ;
73+ document . head . appendChild ( styleEl ) ;
74+ }
75+
76+ function startFullscreenMonitor ( ) {
77+ if ( monitorId ) return ;
78+ monitorId = setInterval ( ( ) => {
79+ appWindow
80+ . isFullscreen ( )
81+ . then ( ( isFullscreen ) => {
82+ if ( fullscreenElement && ! isFullscreen ) {
83+ exitFullscreen ( ) ;
84+ }
85+ } )
86+ . catch ( ( ) => { } ) ;
87+ } , 500 ) ;
88+ }
89+
90+ function stopFullscreenMonitor ( ) {
91+ if ( ! monitorId ) return ;
92+ clearInterval ( monitorId ) ;
93+ monitorId = null ;
94+ }
6995
7096 // Find the actual video element
7197 function findMediaElement ( ) {
@@ -136,6 +162,7 @@ document.addEventListener("DOMContentLoaded", () => {
136162
137163 // Fullscreen window
138164 appWindow . setFullscreen ( true ) . then ( ( ) => {
165+ startFullscreenMonitor ( ) ;
139166 const event = new Event ( "fullscreenchange" , { bubbles : true } ) ;
140167 document . dispatchEvent ( event ) ;
141168 element . dispatchEvent ( event ) ;
@@ -156,6 +183,8 @@ document.addEventListener("DOMContentLoaded", () => {
156183 return Promise . resolve ( ) ;
157184 }
158185
186+ stopFullscreenMonitor ( ) ;
187+
159188 const exitingElement = fullscreenElement ;
160189 const targetElement = actualFullscreenElement ;
161190
@@ -252,20 +281,6 @@ document.addEventListener("DOMContentLoaded", () => {
252281 } ,
253282 true ,
254283 ) ;
255-
256- // Monitor window fullscreen changes
257- let lastFullscreenState = false ;
258- setInterval ( ( ) => {
259- appWindow
260- . isFullscreen ( )
261- . then ( ( isFullscreen ) => {
262- if ( lastFullscreenState && ! isFullscreen && fullscreenElement ) {
263- exitFullscreen ( ) ;
264- }
265- lastFullscreenState = isFullscreen ;
266- } )
267- . catch ( ( ) => { } ) ;
268- } , 500 ) ;
269284 }
270285
271286 initFullscreenPolyfill ( ) ;
0 commit comments