Skip to content

Commit 2492996

Browse files
committed
fix: mini player timeline, updated thumb style, updated custom css vars for getting thumbnail/accent-color
1 parent 7a74444 commit 2492996

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

src/main/services/resources/basic-style/thumb.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
--ytmd-scrollbar-thumb-active-color: var(--ytmusic-text-primary);
99
}
1010

11-
// Define targets for custom scrollbars
12-
html, body {
13-
overflow: overlay;
14-
}
1511
html,
1612
body {
1713
&::-webkit-scrollbar {

src/main/services/track.service.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import CSSHandler from "@main/lib/css/handler";
21
import { AfterInit, BaseProvider } from "@main/utils/baseProvider";
32
import { IpcContext, IpcOn } from "@main/utils/onIpcEvent";
43
import 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
}

src/renderer-plugins/youtube/track-change.plugin.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ export default definePlugin(
77
displayName: "Track Change Watcher",
88
},
99
({ domUtils }) => {
10-
function handleChange(_ev, value: string) {
11-
domUtils.createStyle(`:root { --ytmd-thumbnail-url: ${value}; }`); // ! todo: add working css for track change watcher
10+
let destroyStyle: () => void;
11+
async function handleThumbnail(_ev, value: string) {
12+
if (destroyStyle) destroyStyle();
13+
if (value) destroyStyle = await domUtils.createStyle(`:root { --ytmd-thumbnail-url: ${value}; }`); // ! todo: add working css for track change watcher
14+
}
15+
let destroyAccent: () => void;
16+
async function handleAccent(_ev, value: string) {
17+
if (destroyAccent) destroyAccent();
18+
if (value) destroyAccent = await domUtils.createStyle(`:root { --ytmd-thumbnail-accent: ${value}; }`); // ! todo: add working css for track change watcher
1219
}
1320
domUtils.ensureDomLoaded(() => {
14-
window.ipcRenderer.on("css.thumbnail", handleChange);
21+
window.ipcRenderer.on("css.thumbnail", handleThumbnail);
22+
window.ipcRenderer.on("css.thumbnail-accent", handleAccent);
1523
});
1624
},
1725
);

0 commit comments

Comments
 (0)