From db06eb800dd6750cc3dca55b807dbca1506baa70 Mon Sep 17 00:00:00 2001 From: Isaac <76838845+isaxk@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:58:49 +0100 Subject: [PATCH 1/2] v1.2.0 --- src/main/index.ts | 1 - src/main/player/index.ts | 2 + src/main/tabs/index.ts | 9 +- src/main/utils/customcss.ts | 37 +++--- src/main/windows/index.ts | 10 +- src/preload/index.ts | 2 +- src/preload/music.ts | 13 +- .../components/settings/SettingItem.svelte | 12 +- .../src/components/settings/SidebarTab.svelte | 3 +- src/renderer/src/views/Settings.svelte | 114 +++++++++++------- 10 files changed, 116 insertions(+), 87 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 2c36eaa..84858ae 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -11,7 +11,6 @@ import { discordClient } from "./intergrations/discord"; import { initPlayerEvents } from "./player"; import { createTabManager } from "./tabs"; import { createMainWindowManager, MainWindowManager } from "./windows"; -import { downloadCss, loadCss } from "./utils/customcss"; const store = factory(); diff --git a/src/main/player/index.ts b/src/main/player/index.ts index 8b4baa8..d56e8cd 100644 --- a/src/main/player/index.ts +++ b/src/main/player/index.ts @@ -28,6 +28,8 @@ export function initPlayerEvents(mainWindowManager: MainWindowManager) { } }); + mainWindowManager.window.webContents.send("video-data-changed", null); + ipcMain.on("ytmView:storeStateChanged", (_, _queue, _like, v) => { volume = v; mainWindowManager.window.webContents.send("volume-changed", v); diff --git a/src/main/tabs/index.ts b/src/main/tabs/index.ts index 6977bdd..441fd83 100644 --- a/src/main/tabs/index.ts +++ b/src/main/tabs/index.ts @@ -20,7 +20,6 @@ function windowOpenHandler(details): WindowOpenHandlerResponse { async function updateCustomCss( key: string, - oldCssKey: string | null, view: WebContentsView, ) { let ytCss = JSON.parse(store.get(key, "")!); @@ -92,7 +91,7 @@ export async function createTabManager(mainWindow: BrowserWindow) { }); view.webContents.on("dom-ready", async () => { - await updateCustomCss("music-css", oldCssKey, view).then((key) => { + await updateCustomCss("music-css", view).then((key) => { oldCssKey = key; }); }); @@ -143,7 +142,7 @@ export async function createTabManager(mainWindow: BrowserWindow) { if (oldCssKey !== null) { await view.webContents.removeInsertedCSS(oldCssKey).then(()=>console.log("remove")); } - await updateCustomCss("music-css", oldCssKey, view).then((key) => { + await updateCustomCss("music-css", view).then((key) => { oldCssKey = key; }); @@ -261,7 +260,7 @@ export async function createTabManager(mainWindow: BrowserWindow) { let oldCssKey: string | null = null; view.webContents.on("dom-ready", async () => { - await updateCustomCss("yt-css", oldCssKey, view).then((key) => { + await updateCustomCss("yt-css", view).then((key) => { oldCssKey = key; }); }); @@ -286,7 +285,7 @@ export async function createTabManager(mainWindow: BrowserWindow) { if (oldCssKey !== null) { await view.webContents.removeInsertedCSS(oldCssKey); } - await updateCustomCss("yt-css", oldCssKey, view).then((key) => { + await updateCustomCss("yt-css", view).then((key) => { oldCssKey = key; }); }, diff --git a/src/main/utils/customcss.ts b/src/main/utils/customcss.ts index 5017fcd..5afe735 100644 --- a/src/main/utils/customcss.ts +++ b/src/main/utils/customcss.ts @@ -45,28 +45,27 @@ export function downloadCss(url: string) { // ); // }); -export function loadCss(url:string) { +export function loadCss(url: string) { return new Promise((resolve) => { - if(url==="") { + if (url === "") { resolve(""); return; } - https.get(url, res => { - let data = '' - const headerDate = res.headers && res.headers.date ? res.headers.date : 'no response date'; - - // @ts-ignore - res.on('data', (chunk:any) => { - data += chunk; - }); - - res.on('end', () => { - resolve(data) + https + .get(url, (res) => { + let data = ""; + + // @ts-ignore + res.on("data", (chunk: any) => { + data += chunk; + }); + + res.on("end", () => { + resolve(data); + }); + }) + .on("error", (err) => { + console.log("Error: ", err.message); }); - }).on('error', err => { - console.log('Error: ', err.message); - }); - } -) - + }); } diff --git a/src/main/windows/index.ts b/src/main/windows/index.ts index 12efe3c..a8d6353 100644 --- a/src/main/windows/index.ts +++ b/src/main/windows/index.ts @@ -33,15 +33,15 @@ function updateTheme(mainWindow: BrowserWindow) { } switch (store.get("theme")) { - case "system": - bgColor = nativeTheme.shouldUseDarkColors ? darkBg : lightBg; - break; case "light": bgColor = lightBg; break; case "dark": bgColor = darkBg; break; + default: + bgColor = nativeTheme.shouldUseDarkColors ? darkBg : lightBg; + break; } export type MainWindowManager = { @@ -57,7 +57,7 @@ app.on("before-quit", () => { export function createMainWindowManager() { const mainWindow = new BrowserWindow({ minWidth: 800, - minHeight: 450, + minHeight: 670, width: 1200, height: 700, titleBarStyle: "hiddenInset", @@ -114,7 +114,7 @@ export function createMainWindowManager() { mainWindow.setMaximizable(true); mainWindow.setFullScreenable(true); mainWindow.setAlwaysOnTop(false); - mainWindow.setMinimumSize(800, 450); + mainWindow.setMinimumSize(800, 670); }); mainWindow.on("close", (e) => { diff --git a/src/preload/index.ts b/src/preload/index.ts index c2eda0c..030e96c 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -50,7 +50,7 @@ export const api = { ipcRenderer.send("close-miniplayer"); }, onVideoDataChange: (listener: Function) => { - ipcRenderer.on("video-data-changed", (_, data) => { + ipcRenderer.on("video-data-changed", (_, data: musicData) => { listener(data); }); }, diff --git a/src/preload/music.ts b/src/preload/music.ts index f76d350..b6a255f 100644 --- a/src/preload/music.ts +++ b/src/preload/music.ts @@ -800,12 +800,12 @@ async function hookPlayerApiEvents() { (await webFrame.executeJavaScript(hookPlayerApiEventsScript))(); } -function overrideHistoryButtonDisplay() { - // @ts-expect-error Style is reported as readonly but this still works - document.querySelector( - "#history-link tp-yt-paper-icon-button", - ).style = "display: inline-block !important;"; -} +// function overrideHistoryButtonDisplay() { +// // @ts-expect-error Style is reported as readonly but this still works +// document.querySelector( +// "#history-link tp-yt-paper-icon-button", +// ).style = "display: inline-block !important;"; +// } function getYTMTextRun(runs: { text: string }[]) { let final = ""; @@ -932,7 +932,6 @@ window.addEventListener("load", async () => { await createAdditionalPlayerBarControls(); await hideChromecastButton(); await hookPlayerApiEvents(); - overrideHistoryButtonDisplay(); // const integrationScripts: { [integrationName: string]: { [scriptName: string]: string } } = await ipcRenderer.invoke("ytmView:getIntegrationScripts"); diff --git a/src/renderer/src/components/settings/SettingItem.svelte b/src/renderer/src/components/settings/SettingItem.svelte index f64732f..0daf02a 100644 --- a/src/renderer/src/components/settings/SettingItem.svelte +++ b/src/renderer/src/components/settings/SettingItem.svelte @@ -75,7 +75,7 @@ key, JSON.stringify({ ...value, - enabled: e + enabled: e, }), ); }} @@ -107,17 +107,17 @@ >
URL EditorEditor (advanced)
diff --git a/src/renderer/src/components/settings/SidebarTab.svelte b/src/renderer/src/components/settings/SidebarTab.svelte index d97d33b..1040bcd 100644 --- a/src/renderer/src/components/settings/SidebarTab.svelte +++ b/src/renderer/src/components/settings/SidebarTab.svelte @@ -8,7 +8,8 @@
diff --git a/src/renderer/src/views/Settings.svelte b/src/renderer/src/views/Settings.svelte index 214435d..99d980a 100644 --- a/src/renderer/src/views/Settings.svelte +++ b/src/renderer/src/views/Settings.svelte @@ -4,6 +4,7 @@ import { CircleArrowOutDownRight, Cpu, + Info, Keyboard, Paintbrush, Settings2, @@ -119,7 +120,7 @@
-
-
-

Settings

- { - window.api.closeSettings(); - activeView.set("topbar"); - }} - /> -
-
+
+
- {#each tabs as tab} - - {/each} +

Settings

+
+ {#each tabs as tab} + + {/each} +
+
- {#each tabs as tab} - -
- {#if tab.value == "keybinds"} -
- These keybinds work anywhere on your computer unless another - app conflicts. (Supports music playback only) + + + + {#each tabs as tab} + +
+ {#if tab.value == "keybinds"} +
+ These keybinds work anywhere on your computer unless + another app conflicts. (Supports music playback only) +
+ {/if} + {#if tab.settings} + {#each tab.settings as setting} + + {/each} + {/if} +
+
+ {/each} + +
+
+
+
+
YT Desk
+
v-.-.-
+
+
+
Made by isaxk
+ +
- {/if} - {#if tab.settings} - {#each tab.settings as setting} - - {/each} - {/if} -
- - {/each} + + + + + + + + +
+ { + window.api.closeSettings(); + activeView.set("topbar"); + }} + /> +
From 6518e63b597738a4bd58da0f5bfa2ae8126ba9b2 Mon Sep 17 00:00:00 2001 From: Isaac <76838845+isaxk@users.noreply.github.com> Date: Sat, 31 Aug 2024 12:10:19 +0100 Subject: [PATCH 2/2] Added force cinema mode --- src/main/tabs/index.ts | 22 +++++++++++++------ src/preload/yt.ts | 16 ++++++++++++++ .../components/settings/SettingItem.svelte | 2 +- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/tabs/index.ts b/src/main/tabs/index.ts index 441fd83..6e3e87a 100644 --- a/src/main/tabs/index.ts +++ b/src/main/tabs/index.ts @@ -18,13 +18,10 @@ function windowOpenHandler(details): WindowOpenHandlerResponse { }; } -async function updateCustomCss( - key: string, - view: WebContentsView, -) { +async function updateCustomCss(key: string, view: WebContentsView) { let ytCss = JSON.parse(store.get(key, "")!); return new Promise(async (resolve) => { - if (ytCss.enabled===true) { + if (ytCss.enabled === true) { if (ytCss.type === "url") { await loadCss(ytCss.url).then(async (css) => { resolve(await view.webContents.insertCSS(css)); @@ -140,11 +137,12 @@ export async function createTabManager(mainWindow: BrowserWindow) { }, updateCss: async () => { if (oldCssKey !== null) { - await view.webContents.removeInsertedCSS(oldCssKey).then(()=>console.log("remove")); + await view.webContents + .removeInsertedCSS(oldCssKey) + .then(() => console.log("remove")); } await updateCustomCss("music-css", view).then((key) => { oldCssKey = key; - }); }, }; @@ -263,6 +261,7 @@ export async function createTabManager(mainWindow: BrowserWindow) { await updateCustomCss("yt-css", view).then((key) => { oldCssKey = key; }); + view.webContents.send("force-cinema", store.get("force-cinema", false)); }); return { @@ -398,6 +397,15 @@ export async function createTabManager(mainWindow: BrowserWindow) { } }); + ipcMain.on("set-config", (_, e) => { + if (e.key === "force-cinema") { + tabs.forEach((tab) => { + tab.data().type === "yt" ?? + tab.view.webContents.send("force-cinema", e.value); + }); + } + }); + return { getTabs: () => { return tabs; diff --git a/src/preload/yt.ts b/src/preload/yt.ts index 61d667e..acfab71 100644 --- a/src/preload/yt.ts +++ b/src/preload/yt.ts @@ -71,3 +71,19 @@ ipcRenderer.on("picture-in-picture", async () => { `) )(); }); + +ipcRenderer.on("force-cinema", async (_, is: boolean) => { + if (is) { + ( + await webFrame.executeJavaScript(` + document.cookie = 'wide=1; expires='+new Date('3099').toUTCString()+'; path=/'; + `) + )(); + } else { + ( + await webFrame.executeJavaScript(` + document.cookie = 'wide=0; expires='+new Date('3099').toUTCString()+'; path=/'; + `) + )(); + } +}); diff --git a/src/renderer/src/components/settings/SettingItem.svelte b/src/renderer/src/components/settings/SettingItem.svelte index 0daf02a..3a1eb32 100644 --- a/src/renderer/src/components/settings/SettingItem.svelte +++ b/src/renderer/src/components/settings/SettingItem.svelte @@ -105,7 +105,7 @@ }, 400); }} > -
+