Skip to content

Commit

Permalink
πŸŽ¨πŸ› Clean Preventing Nav/Redirect + Fix Multi user account
Browse files Browse the repository at this point in the history
  • Loading branch information
Alipoodle committed Dec 18, 2023
1 parent 3df63fa commit eefc042
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,18 @@ function urlIsGoogleAccountsDomain(url: URL): boolean {
if (supportedDomains.includes(domain)) return true;
return false;
}
function isPreventedNavOrRedirect(url: URL): boolean {
return (
url.hostname !== "consent.youtube.com" &&
url.hostname !== "accounts.youtube.com" &&
url.hostname !== "music.youtube.com" &&
!(
(url.hostname === "www.youtube.com" || url.hostname === "youtube.com") &&
(url.pathname === "/signin" || url.pathname === "/premium" || url.pathname === "/signin_prompt")
) &&
!urlIsGoogleAccountsDomain(url)
);
}

const createYTMView = (): void => {
memoryStore.set("ytmViewLoadTimedout", false);
Expand All @@ -902,16 +914,7 @@ const createYTMView = (): void => {
// Attach events to ytm view
ytmView.webContents.on("will-navigate", event => {
const url = new URL(event.url);
if (
url.hostname !== "consent.youtube.com" &&
url.hostname !== "accounts.youtube.com" &&
url.hostname !== "music.youtube.com" &&
!(url.hostname === "www.youtube.com" && url.pathname === "/signin") &&
!(url.hostname === "youtube.com" && url.pathname === "/signin") &&
!(url.hostname === "www.youtube.com" && url.pathname === "/premium") &&
!(url.hostname === "youtube.com" && url.pathname === "/premium") &&
!urlIsGoogleAccountsDomain(url)
) {
if (isPreventedNavOrRedirect(url)) {
event.preventDefault();
log.info(`Blocking YTM View navigation to ${event.url}`);

Expand All @@ -920,16 +923,7 @@ const createYTMView = (): void => {
});
ytmView.webContents.on("will-redirect", event => {
const url = new URL(event.url);
if (
url.hostname !== "consent.youtube.com" &&
url.hostname !== "accounts.youtube.com" &&
url.hostname !== "music.youtube.com" &&
!(url.hostname === "www.youtube.com" && url.pathname === "/signin") &&
!(url.hostname === "youtube.com" && url.pathname === "/signin") &&
!(url.hostname === "www.youtube.com" && url.pathname === "/premium") &&
!(url.hostname === "youtube.com" && url.pathname === "/premium") &&
!urlIsGoogleAccountsDomain(url)
) {
if (isPreventedNavOrRedirect(url)) {
event.preventDefault();
log.info(`Blocking YTM View redirect to ${event.url}`);
}
Expand Down

0 comments on commit eefc042

Please sign in to comment.