Skip to content

Commit

Permalink
fix: initial load due to client plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Venipa committed Jan 22, 2025
1 parent 4c0a0d9 commit 7ca59a8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/main/plugins/client/player-prefer-quality.plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const qKey = "yt-player-quality";
export const meta = {
name: "Youtube Prefer Quality"
};
export default () => {
const res = window.__ytd_settings?.player?.res;
let isEnabled = !!res?.enabled;
Expand Down
4 changes: 4 additions & 0 deletions src/main/plugins/client/track-skip-disliked.plugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export const meta = {
name: "Track skip disliked",
};

export default ({ settings }) => {
let lastVideoId = null,
waitForTick = false;
Expand Down
4 changes: 4 additions & 0 deletions src/main/plugins/client/track-title-change.plugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export const meta = {
name: "Track watch title change",
};

export default () => {
new MutationObserver(() => {
const el = document.querySelector("a.ytp-title-link.yt-uix-sessionlink");
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (import.meta.env.VITE_SENTRY_DSN && Sentry && !Sentry.isInitialized) {
try {
Sentry.init({
dsn: import.meta.env.VITE_SENTRY_DSN,
enabled: true,
enabled: import.meta.env.PROD,
onFatalError(error) {
if (enabledReporting) sentryLog.error(error);
},
Expand Down
31 changes: 17 additions & 14 deletions src/preload/youtube.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { createLogger } from "@shared/utils/console";
import DOMPurify from "dompurify";
import { merge, set } from "lodash-es";
import { basename } from "path";
import pkg from "../../package.json";
import exposeData, { setContext } from "./base";
const appVersion = pkg.version;

const log = createLogger("YTD");
setContext("appVersion", appVersion);
Object.entries(exposeData).forEach(([key, endpoints]) => {
setContext(key, endpoints);
Expand Down Expand Up @@ -47,24 +50,22 @@ const initFn = async (force?: boolean) => {
};

window.ipcRenderer.on("settingsProvider.change", (ev, key, value) => {
console.log("settings.change", key, value);
log.debug("settings.change", key, value);
window.__ytd_settings = set(window.__ytd_settings, key, value);
});
await new Promise<void>((resolve) =>
exposeData.domUtils.ensureDomLoaded(async () => {
const currentUrl = new URL(location.href);
if (currentUrl.host === "music.youtube.com") {
const pluginContext = { settings: new Proxy(window.__ytd_settings, {}) };
const destroyFns = plugins
.map((m) => {
if (m.meta)
console.log("Client Plugin ::", m.meta.name, "enabled:", m.meta.enabled !== false);
else console.log("Client Plugin ::", m.name, m.meta);
if (m.meta.enabled === false) return null;
const destroyFn = m.exec?.(pluginContext);
return destroyFn;
})
.filter(Boolean);
const destroyFns = plugins.map((m) => {
if (m.meta)
log.child(`Client Plugin, ${m.meta.name}`).debug("enabled:", m.meta.enabled !== false);
else log.child(`Client Plugin, ${m.name}`).debug(m.name, m.meta);
if (m.meta.enabled === false) return undefined;
const destroyFn = m.exec?.(pluginContext);
return destroyFn;
});
window.addEventListener("beforeunload", function () {
if (destroyFns && currentUrl.hostname !== this.location.hostname && destroyFns.length > 0)
destroyFns.filter((fn) => fn && typeof fn === "function").forEach((fn) => fn());
Expand All @@ -88,16 +89,18 @@ const initFn = async (force?: boolean) => {
}
};
checkYTRoot();
});
console.log("ytplayer loaded");
})

log.debug("ytplayer loaded");
plugins.forEach((p) => {
if (!p.afterInit) return;
p.afterInit(pluginContext);
console.log(`[CP][${p.name}] :: afterInit execute`);
log.child(`Client Plugin, ${p.name}`).debug(`afterInit execute`);
});
}
window.api.emit("app.loadEnd");
_loadedYTM = true; // todo

resolve();
}),
);
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/assets/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
@layer base {

html,
body {
body,
#app {

@apply text-gray-100 bg-gray-900 h-full;
}
Expand Down

0 comments on commit 7ca59a8

Please sign in to comment.