From 2cb05c9d86bd426da1ea73665a8a501788026f71 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Tue, 3 Oct 2023 10:45:01 +0900 Subject: [PATCH] fix(in-app-menu): overlay-scrollbar --- index.ts | 4 +++- plugins/in-app-menu/front.ts | 9 +++++++-- plugins/in-app-menu/titlebar.css | 23 ++--------------------- providers/prompt-custom-titlebar.ts | 21 --------------------- providers/prompt-options.ts | 12 +----------- 5 files changed, 13 insertions(+), 56 deletions(-) delete mode 100644 providers/prompt-custom-titlebar.ts diff --git a/index.ts b/index.ts index 8a46ad28..7ff16525 100644 --- a/index.ts +++ b/index.ts @@ -38,7 +38,9 @@ if (!gotTheLock) { app.exit(); } -app.commandLine.appendSwitch('enable-features', 'SharedArrayBuffer'); // Required for downloader +// SharedArrayBuffer: Required for downloader (@ffmpeg/core-mt) +// OverlayScrollbar: Required for overlay scrollbars +app.commandLine.appendSwitch('enable-features', 'OverlayScrollbar,SharedArrayBuffer'); if (config.get('options.disableHardwareAcceleration')) { if (is.dev()) { console.log('Disabling hardware acceleration'); diff --git a/plugins/in-app-menu/front.ts b/plugins/in-app-menu/front.ts index a8b48146..9ef50c06 100644 --- a/plugins/in-app-menu/front.ts +++ b/plugins/in-app-menu/front.ts @@ -18,7 +18,7 @@ export default () => { const titleBar = document.createElement('title-bar'); const navBar = document.querySelector('#nav-bar-background'); - const logo = ElementFromFile(path.join(__dirname, '../../assets/youtube-music.svg')); + const logo = ElementFromFile(path.join(__dirname, '..' , '..' , 'assets', 'youtube-music.svg')); logo.classList.add('title-bar-icon'); titleBar.appendChild(logo); @@ -47,7 +47,7 @@ export default () => { menu.items.forEach((menuItem) => { const menu = document.createElement('menu-button'); createPanel(titleBar, menu, menuItem.submenu?.items ?? []); - + menu.append(menuItem.label); titleBar.appendChild(menu); }); @@ -69,6 +69,11 @@ export default () => { // Increases the right margin of Navbar background when the scrollbar is visible to avoid blocking it (z-index doesn't affect it) document.addEventListener('apiLoaded', () => { setupSearchOpenObserver(); + const htmlHeadStyle = $('head > div > style'); + if (htmlHeadStyle) { + // HACK: This is a hack to remove the scrollbar width + htmlHeadStyle.innerHTML = htmlHeadStyle.innerHTML.replace('html::-webkit-scrollbar {width: var(--ytmusic-scrollbar-width);', 'html::-webkit-scrollbar {'); + } }, { once: true, passive: true }); }; diff --git a/plugins/in-app-menu/titlebar.css b/plugins/in-app-menu/titlebar.css index 0c1a4dc7..0fc93f01 100644 --- a/plugins/in-app-menu/titlebar.css +++ b/plugins/in-app-menu/titlebar.css @@ -19,7 +19,7 @@ title-bar { justify-content: flex-start; align-items: center; gap: 4px; - + color: #f1f1f1; font-size: 14px; padding: 4px 12px; @@ -109,7 +109,7 @@ menu-separator { height: 1px; margin: 4px 0; - background-color: rgba(255, 255, 255, 0.2); + background-color: rgba(255, 255, 255, 0.2); } /* classes */ @@ -136,22 +136,3 @@ ytmusic-app[is-bauhaus-sidenav-enabled] #guide-spacer.ytmusic-app, ytmusic-app[is-bauhaus-sidenav-enabled] #mini-guide-spacer.ytmusic-app { margin-top: calc(var(--ytmusic-nav-bar-height) + var(--menu-bar-height, 36px)) !important; } - - -html::-webkit-scrollbar { - width: 12px !important; -} - -html::-webkit-scrollbar-thumb { - border: solid 2px var(--titlebar-background-color, #030303) !important; - border-radius: 100px !important; -} - -html::-webkit-scrollbar-track { - background: var(--titlebar-background-color, #030303) !important; -} - -html::-webkit-scrollbar-track-piece:start { - background: transparent; - margin-top: var(--menu-bar-height, 36px); -} diff --git a/providers/prompt-custom-titlebar.ts b/providers/prompt-custom-titlebar.ts deleted file mode 100644 index 5068745c..00000000 --- a/providers/prompt-custom-titlebar.ts +++ /dev/null @@ -1,21 +0,0 @@ -// eslint-disable-next-line import/no-unresolved -import { Titlebar, Color } from 'custom-electron-titlebar'; - -const customTitlebarFunction = () => { - new Titlebar({ - backgroundColor: Color.fromHex('#050505'), - minimizable: false, - maximizable: false, - menu: undefined, - }); - const mainStyle = document.querySelector('#container')?.style; - if (mainStyle) { - mainStyle.width = '100%'; - mainStyle.position = 'fixed'; - mainStyle.border = 'unset'; - } -}; - - -module.exports = customTitlebarFunction; -export default customTitlebarFunction; diff --git a/providers/prompt-options.ts b/providers/prompt-options.ts index 87e27f13..e268b48a 100644 --- a/providers/prompt-options.ts +++ b/providers/prompt-options.ts @@ -1,18 +1,8 @@ import path from 'node:path'; -import is from 'electron-is'; - -import { isEnabled } from '../config/plugins'; - const iconPath = path.join(__dirname, '..', 'assets', 'youtube-music-tray.png'); -const customTitlebarPath = path.join(__dirname, 'prompt-custom-titlebar.js'); -const promptOptions = !is.macOS() && isEnabled('in-app-menu') ? { - customStylesheet: 'dark', - // The following are used for custom titlebar - frame: false, - customScript: customTitlebarPath, -} : { +const promptOptions = { customStylesheet: 'dark', icon: iconPath, };