1- import CSSHandler from "@main/lib/css/handler" ;
21import { AfterInit , BaseProvider } from "@main/utils/baseProvider" ;
32import { IpcContext , IpcOn } from "@main/utils/onIpcEvent" ;
43import type { TrackData } from "@main/utils/trackData" ;
@@ -297,11 +296,11 @@ export default class TrackProvider extends BaseProvider implements AfterInit {
297296 this . logger . error ( "Failed to update media timeline:" , error ) ;
298297 }
299298 }
300- @IpcOn ( IPC_EVENT_NAMES . TRACK_PLAYSTATE_PROGRESS , { debounce : 1000 } )
299+ // Synchronize track state with the media timeline of Mini Player and other views
300+ @IpcOn ( IPC_EVENT_NAMES . TRACK_PLAYSTATE_PROGRESS , { debounce : 100 } )
301301 private async __onPlayStateProgress ( _ev : any , isPlaying : boolean , progressSeconds : number = 0 ) {
302302 if ( ! this . trackData ?. meta ) return ;
303303 const duration = Number ( this . trackData . meta . duration ) ;
304- await this . updateMediaTimeline ( duration , progressSeconds , isPlaying ) ;
305304 this . setTrackState ( ( state ) => {
306305 state . progress = progressSeconds ;
307306 state . uiProgress = progressSeconds ;
@@ -310,6 +309,13 @@ export default class TrackProvider extends BaseProvider implements AfterInit {
310309 state . eventType = "progress" ;
311310 } ) ;
312311 }
312+ // Synchronize the media timeline with services outside of the app with a longer debounce
313+ @IpcOn ( IPC_EVENT_NAMES . TRACK_PLAYSTATE_PROGRESS , { debounce : 1000 } )
314+ private async __onProgressHandler ( _ev : any , isPlaying : boolean , progressSeconds : number = 0 ) {
315+ if ( ! this . trackData ?. meta ) return ;
316+ const duration = Number ( this . trackData . meta . duration ) ;
317+ await this . updateMediaTimeline ( duration , progressSeconds , isPlaying ) ;
318+ }
313319
314320 private _currentPallete : { id : string ; color : string } | null = null ;
315321 async getTrackAccent ( track : TrackData = this . trackData ) {
@@ -353,20 +359,18 @@ export default class TrackProvider extends BaseProvider implements AfterInit {
353359 this . logger . error ( "youtubeView not found" ) ;
354360 return ;
355361 }
356- const accentHandler = new CSSHandler ( this . windowContext . views . youtubeView . webContents ) ;
357362 this . onTrackChange ( async ( track ) => {
358363 const trackAccent = await this . getTrackAccent ( track ) ;
359364 this . setTrackState ( ( state ) => {
360365 state . accent = trackAccent ;
361366 } ) ;
362- accentHandler . createOrUpdate ( `:root { --ytmd- thumbnail-accent: ${ trackAccent ?? "transparent" } ; }` ) ;
367+ this . windowContext . views . youtubeView . webContents . send ( "css. thumbnail-accent" , trackAccent ?? "transparent" ) ;
363368 this . logger . debug ( "track:accent" , trackAccent , track . video . thumbnail . thumbnails ?. [ 0 ] ?. url ) ;
364369 } ) ;
365- const thumbnailHandler = new CSSHandler ( this . windowContext . views . youtubeView . webContents ) ;
366370 this . onTrackChange ( async ( track ) => {
367371 const hqThumbnail = track . context ?. thumbnail ?. thumbnails ?. sort ( firstBy ( ( d ) => d . width , "desc" ) ) [ 0 ] ?. url ?? track . meta . thumbnail ;
368372 const thumbnailUrl = hqThumbnail ? `url(${ hqThumbnail } )` : "transparent" ;
369- thumbnailHandler . createOrUpdate ( `:root { --ytmd- thumbnail-url: ${ thumbnailUrl } ; }` ) ;
373+ this . windowContext . views . youtubeView . webContents . send ( "css. thumbnail" , thumbnailUrl ) ;
370374 this . logger . debug ( "track:thumbnail" , thumbnailUrl ) ;
371375 } ) ;
372376 }
0 commit comments