feat(settings): option to hide scrollbars
Settings › Appearance › Hide scrollbars removes every scrollbar in the app; the mouse wheel, touchpad, touch and keyboard still scroll. - hideScrollbars setting (default off), coerced to a boolean by healSettings; portable like the theme, no store version bump (the heal back-fills it, and older builds can still read newer backups) - applied as <html class="hide-scrollbars">: theme-init.js before first paint, main.tsx at boot, an App store subscription afterwards (the toggle, a restored backup and its undo) - unlayered CSS beats .scrollbar-thin: scrollbar-width: none on every element for Chromium and Firefox, ::-webkit-scrollbar for the WebKit webviews on macOS and Linux - labels in 8 locales Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1252d88883
commit
c46c7a4588
19 files changed
+173
-16
No files matched your search
@@ -1,14 +1,18 @@
|
||||
// Applies the saved theme and UI language before the first paint, so a
|
||||
// light-theme user never sees the dark default flash. A separate file rather
|
||||
// than an inline <script> so the Content-Security-Policy needs no exception.
|
||||
// Applies the saved theme, scrollbar preference and UI language before the
|
||||
// first paint, so a light-theme user never sees the dark default flash. A
|
||||
// separate file rather than an inline <script> so the Content-Security-Policy
|
||||
// needs no exception.
|
||||
(function () {
|
||||
var root = document.documentElement;
|
||||
var theme = "dark";
|
||||
var hideScrollbars = false;
|
||||
var lang = null;
|
||||
try {
|
||||
var raw = localStorage.getItem("ytdescgen-settings");
|
||||
var state = raw ? JSON.parse(raw).state : null;
|
||||
if (state && state.theme === "light") theme = "light";
|
||||
// Unhealed raw storage, so only a real `true` counts.
|
||||
if (state && state.hideScrollbars === true) hideScrollbars = true;
|
||||
if (state && typeof state.appLanguage === "string") lang = state.appLanguage;
|
||||
} catch (e) {
|
||||
/* storage blocked or corrupt: keep the defaults */
|
||||
@@ -16,5 +20,7 @@
|
||||
root.classList.toggle("dark", theme === "dark");
|
||||
root.classList.toggle("light", theme === "light");
|
||||
root.style.colorScheme = theme;
|
||||
// Same class as src/utils/scrollbars.ts.
|
||||
root.classList.toggle("hide-scrollbars", hideScrollbars);
|
||||
if (lang) root.lang = lang;
|
||||
})();
|
||||
+11
@@ -17,6 +17,7 @@ import { useSettingsStore } from "@store/settings-store";
|
||||
import { useEditorStore } from "@store/editor-store";
|
||||
import i18n from "@i18n/index";
|
||||
import { IS_TAURI } from "@utils/platform";
|
||||
import { applyHideScrollbars } from "@utils/scrollbars";
|
||||
|
||||
// The Editor is the landing page and stays in the entry bundle; Output is
|
||||
// the usual next stop, so it is fetched as soon as the browser is idle.
|
||||
@@ -167,6 +168,16 @@ export default function App() {
|
||||
return () => unsub();
|
||||
}, []);
|
||||
|
||||
// v1.1.0: keep <html class="hide-scrollbars"> in step with the setting.
|
||||
// theme-init.js and main.tsx apply it before first paint; the Settings
|
||||
// toggle, a restored backup and its undo all arrive here.
|
||||
useEffect(() => {
|
||||
applyHideScrollbars(useSettingsStore.getState().hideScrollbars);
|
||||
return useSettingsStore.subscribe((state, prev) => {
|
||||
if (state.hideScrollbars !== prev.hideScrollbars) applyHideScrollbars(state.hideScrollbars);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<MotionProvider>
|
||||
<TooltipProvider>
|
||||
|
||||
@@ -949,7 +949,7 @@
|
||||
"genrePlaylistsBadge",
|
||||
"numberRange",
|
||||
"themeDark",
|
||||
"themeLight", "titleOrder", "titleOrderGameFirst", "titleOrderTypeFirst", "copyAllIncludesTags", "copyAllIncludesTagsHint"
|
||||
"themeLight", "titleOrder", "titleOrderGameFirst", "titleOrderTypeFirst", "copyAllIncludesTags", "copyAllIncludesTagsHint", "hideScrollbars", "hideScrollbarsHint"
|
||||
],
|
||||
"batch": [
|
||||
"title",
|
||||
|
||||
@@ -1159,7 +1159,9 @@
|
||||
"titleOrderGameFirst": "Game first (Hades — Part 3)",
|
||||
"titleOrderTypeFirst": "Video first (Part 3 — Hades)",
|
||||
"copyAllIncludesTags": "Copy All includes the tags",
|
||||
"copyAllIncludesTagsHint": "Title, description, then the tags — for pasting everything into a notes app in one go."
|
||||
"copyAllIncludesTagsHint": "Title, description, then the tags — for pasting everything into a notes app in one go.",
|
||||
"hideScrollbars": "Hide scrollbars",
|
||||
"hideScrollbarsHint": "Removes every scrollbar in the app — the mouse wheel, touchpad, touch and keyboard still scroll."
|
||||
},
|
||||
"socialPost": {
|
||||
"title": "Cross-Post Captions",
|
||||
|
||||
@@ -1159,7 +1159,9 @@
|
||||
"titleOrderGameFirst": "Juego primero (Hades — Part 3)",
|
||||
"titleOrderTypeFirst": "Vídeo primero (Part 3 — Hades)",
|
||||
"copyAllIncludesTags": "Copiar todo incluye las etiquetas",
|
||||
"copyAllIncludesTagsHint": "Título, descripción y luego las etiquetas, para pegarlo todo de una vez en una app de notas."
|
||||
"copyAllIncludesTagsHint": "Título, descripción y luego las etiquetas, para pegarlo todo de una vez en una app de notas.",
|
||||
"hideScrollbars": "Ocultar barras de desplazamiento",
|
||||
"hideScrollbarsHint": "Quita todas las barras de desplazamiento de la app; la rueda del ratón, el touchpad, la pantalla táctil y el teclado siguen desplazando."
|
||||
},
|
||||
"socialPost": {
|
||||
"title": "Publicaciones multiplataforma",
|
||||
|
||||
@@ -1159,7 +1159,9 @@
|
||||
"titleOrderGameFirst": "Game dulu (Hades — Part 3)",
|
||||
"titleOrderTypeFirst": "Video dulu (Part 3 — Hades)",
|
||||
"copyAllIncludesTags": "Salin semua termasuk tag",
|
||||
"copyAllIncludesTagsHint": "Judul, deskripsi, lalu tag — untuk menempel semuanya sekaligus ke aplikasi catatan."
|
||||
"copyAllIncludesTagsHint": "Judul, deskripsi, lalu tag — untuk menempel semuanya sekaligus ke aplikasi catatan.",
|
||||
"hideScrollbars": "Sembunyikan scrollbar",
|
||||
"hideScrollbarsHint": "Menyembunyikan semua scrollbar di aplikasi — roda mouse, touchpad, sentuhan, dan keyboard tetap bisa menggulir."
|
||||
},
|
||||
"socialPost": {
|
||||
"title": "Caption Lintas Platform",
|
||||
|
||||
@@ -1159,7 +1159,9 @@
|
||||
"titleOrderGameFirst": "ゲームが先(Hades — Part 3)",
|
||||
"titleOrderTypeFirst": "動画が先(Part 3 — Hades)",
|
||||
"copyAllIncludesTags": "「すべてコピー」にタグも含める",
|
||||
"copyAllIncludesTagsHint": "タイトル、説明、タグの順。メモアプリにまとめて貼り付けるときに。"
|
||||
"copyAllIncludesTagsHint": "タイトル、説明、タグの順。メモアプリにまとめて貼り付けるときに。",
|
||||
"hideScrollbars": "スクロールバーを隠す",
|
||||
"hideScrollbarsHint": "アプリ内のすべてのスクロールバーを非表示にします。マウスホイール、タッチパッド、タッチ操作、キーボードでのスクロールはそのまま使えます。"
|
||||
},
|
||||
"socialPost": {
|
||||
"title": "クロス投稿キャプション",
|
||||
|
||||
@@ -1159,7 +1159,9 @@
|
||||
"titleOrderGameFirst": "게임 먼저 (Hades — Part 3)",
|
||||
"titleOrderTypeFirst": "영상 먼저 (Part 3 — Hades)",
|
||||
"copyAllIncludesTags": "모두 복사에 태그 포함",
|
||||
"copyAllIncludesTagsHint": "제목, 설명, 태그 순서로 — 메모 앱에 한 번에 붙여넣을 때 좋습니다."
|
||||
"copyAllIncludesTagsHint": "제목, 설명, 태그 순서로 — 메모 앱에 한 번에 붙여넣을 때 좋습니다.",
|
||||
"hideScrollbars": "스크롤바 숨기기",
|
||||
"hideScrollbarsHint": "앱의 모든 스크롤바를 숨깁니다. 마우스 휠, 터치패드, 터치, 키보드로는 계속 스크롤할 수 있습니다."
|
||||
},
|
||||
"socialPost": {
|
||||
"title": "크로스포스트 캡션",
|
||||
|
||||
@@ -1159,7 +1159,9 @@
|
||||
"titleOrderGameFirst": "Jogo primeiro (Hades — Part 3)",
|
||||
"titleOrderTypeFirst": "Vídeo primeiro (Part 3 — Hades)",
|
||||
"copyAllIncludesTags": "Copiar tudo inclui as tags",
|
||||
"copyAllIncludesTagsHint": "Título, descrição e depois as tags — para colar tudo de uma vez num app de notas."
|
||||
"copyAllIncludesTagsHint": "Título, descrição e depois as tags — para colar tudo de uma vez num app de notas.",
|
||||
"hideScrollbars": "Ocultar barras de rolagem",
|
||||
"hideScrollbarsHint": "Remove todas as barras de rolagem do app — a roda do mouse, o touchpad, o toque e o teclado continuam rolando."
|
||||
},
|
||||
"socialPost": {
|
||||
"title": "Legendas para outras redes",
|
||||
|
||||
@@ -1159,7 +1159,9 @@
|
||||
"titleOrderGameFirst": "Game trước (Hades — Part 3)",
|
||||
"titleOrderTypeFirst": "Video trước (Part 3 — Hades)",
|
||||
"copyAllIncludesTags": "Sao chép tất cả kèm cả tag",
|
||||
"copyAllIncludesTagsHint": "Tiêu đề, mô tả, rồi đến tag — để dán tất cả vào ứng dụng ghi chú một lần."
|
||||
"copyAllIncludesTagsHint": "Tiêu đề, mô tả, rồi đến tag — để dán tất cả vào ứng dụng ghi chú một lần.",
|
||||
"hideScrollbars": "Ẩn thanh cuộn",
|
||||
"hideScrollbarsHint": "Ẩn mọi thanh cuộn trong ứng dụng — vẫn cuộn được bằng con lăn chuột, touchpad, cảm ứng và bàn phím."
|
||||
},
|
||||
"socialPost": {
|
||||
"title": "Bài đăng đa nền tảng",
|
||||
|
||||
@@ -1159,7 +1159,9 @@
|
||||
"titleOrderGameFirst": "游戏在前(Hades — Part 3)",
|
||||
"titleOrderTypeFirst": "视频在前(Part 3 — Hades)",
|
||||
"copyAllIncludesTags": "“全部复制”包含标签",
|
||||
"copyAllIncludesTagsHint": "依次为标题、描述、标签 —— 方便一次性粘贴到笔记应用。"
|
||||
"copyAllIncludesTagsHint": "依次为标题、描述、标签 —— 方便一次性粘贴到笔记应用。",
|
||||
"hideScrollbars": "隐藏滚动条",
|
||||
"hideScrollbarsHint": "隐藏应用中的所有滚动条 —— 鼠标滚轮、触控板、触摸和键盘仍可滚动。"
|
||||
},
|
||||
"socialPost": {
|
||||
"title": "跨平台文案",
|
||||
|
||||
+7
-4
@@ -7,6 +7,7 @@ import { useSettingsStore } from "@store/settings-store";
|
||||
import { useEditorStore } from "@store/editor-store";
|
||||
import { installExternalLinkHandler } from "@utils/open-external";
|
||||
import { IS_TAURI } from "@utils/platform";
|
||||
import { applyHideScrollbars } from "@utils/scrollbars";
|
||||
import { CURRENT_TERMS_VERSION, needsConsent, termsVersionFromCookie } from "@config/legal";
|
||||
// Self-hosted variable fonts; each subset (latin, latin-ext, vietnamese, …)
|
||||
// is a separate file the browser only fetches when a page uses it.
|
||||
@@ -106,13 +107,15 @@ async function preloadLocales(): Promise<void> {
|
||||
* flash until they interacted. zustand persist has already hydrated from
|
||||
* localStorage at module load, so `getState().theme` is the user's value.
|
||||
* Runs before first paint so the consent gate (and AppShell) render in the
|
||||
* right theme.
|
||||
* right theme. v1.1.0 adds the Hide scrollbars class; App's store
|
||||
* subscription keeps it in step after this.
|
||||
*/
|
||||
function applyPersistedTheme(): void {
|
||||
const { theme } = useSettingsStore.getState();
|
||||
function applyPersistedAppearance(): void {
|
||||
const { theme, hideScrollbars } = useSettingsStore.getState();
|
||||
document.documentElement.classList.toggle("dark", theme === "dark");
|
||||
document.documentElement.classList.toggle("light", theme === "light");
|
||||
document.documentElement.style.colorScheme = theme;
|
||||
applyHideScrollbars(hideScrollbars);
|
||||
}
|
||||
|
||||
// Top-level safety net. Per-route boundaries in App.tsx catch most
|
||||
@@ -121,7 +124,7 @@ function applyPersistedTheme(): void {
|
||||
// rehydrate). Without it, a top-level crash still produces a black
|
||||
// page — defeating the point of per-route boundaries.
|
||||
void preloadLocales().finally(() => {
|
||||
applyPersistedTheme();
|
||||
applyPersistedAppearance();
|
||||
// In a Tauri webview, `<a target="_blank">` is inert — route external links
|
||||
// through the OS via the opener plugin. No-op on the web build.
|
||||
installExternalLinkHandler();
|
||||
|
||||
@@ -138,6 +138,12 @@ export function SettingsPage() {
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
<Toggle
|
||||
label={t("settings.hideScrollbars")}
|
||||
description={t("settings.hideScrollbarsHint")}
|
||||
checked={settings.hideScrollbars}
|
||||
onChange={(v) => settings.setSetting("hideScrollbars", v)}
|
||||
/>
|
||||
</Accordion>
|
||||
|
||||
<Accordion {...section("defaults")} icon={Languages} title={t("settings.defaults")}>
|
||||
|
||||
@@ -15,6 +15,13 @@ export interface SettingsData {
|
||||
appLanguage: SupportedLanguage;
|
||||
defaultOutputLanguage: SupportedLanguage;
|
||||
theme: "dark" | "light";
|
||||
/**
|
||||
* v1.1.0: hide every scrollbar in the app — the wheel, touchpad, touch and
|
||||
* keyboard still scroll. Applied as the `hide-scrollbars` class on <html>:
|
||||
* by public/theme-init.js before first paint, by main.tsx at boot and by
|
||||
* App's store subscription afterwards. Travels with backups, like `theme`.
|
||||
*/
|
||||
hideScrollbars: boolean;
|
||||
showCharCount: boolean;
|
||||
compactTagDisplay: boolean;
|
||||
historyLimit: number;
|
||||
@@ -177,6 +184,7 @@ export const initialSettings: SettingsData = {
|
||||
appLanguage: detectBrowserLanguage(),
|
||||
defaultOutputLanguage: detectBrowserLanguage(),
|
||||
theme: "dark",
|
||||
hideScrollbars: false,
|
||||
showCharCount: true,
|
||||
compactTagDisplay: false,
|
||||
historyLimit: 100,
|
||||
@@ -338,5 +346,11 @@ export function healSettings(raw: unknown): SettingsData {
|
||||
if (typeof incoming[key] !== "string" || incoming[key] === "") incoming[key] = null;
|
||||
}
|
||||
|
||||
// v1.1.0: coerced the same way — a hand-edited `"yes"` must not hide every
|
||||
// scrollbar in the app.
|
||||
if (typeof incoming.hideScrollbars !== "boolean") {
|
||||
incoming.hideScrollbars = initialSettings.hideScrollbars;
|
||||
}
|
||||
|
||||
return { ...initialSettings, ...incoming } as SettingsData;
|
||||
}
|
||||
@@ -103,6 +103,10 @@ export const useSettingsStore = create<SettingsState>()(
|
||||
// strictMode falls back to false (an opt-in seatbelt must not be turned
|
||||
// on by a truthy string), and the accordion map is merged rather than
|
||||
// replaced so sections added later still get their default.
|
||||
// Later additive keys — v1.0.0's `copyAllIncludesTags`,
|
||||
// `lastProfileId`, `lastPresetId` and v1.1.0's `hideScrollbars` — ride
|
||||
// the same back-fill and coercion without a bump, which also keeps a
|
||||
// backup made by the newer build readable to the one before it.
|
||||
version: SETTINGS_STORE_VERSION,
|
||||
migrate: (persistedState: unknown): SettingsData => healSettings(persistedState),
|
||||
// Heal on EVERY load, not only on a version change (which is all
|
||||
@@ -131,6 +135,7 @@ export function extractData(state: SettingsData): SettingsData {
|
||||
appLanguage: state.appLanguage,
|
||||
defaultOutputLanguage: state.defaultOutputLanguage,
|
||||
theme: state.theme,
|
||||
hideScrollbars: state.hideScrollbars,
|
||||
showCharCount: state.showCharCount,
|
||||
compactTagDisplay: state.compactTagDisplay,
|
||||
historyLimit: state.historyLimit,
|
||||
|
||||
@@ -291,6 +291,22 @@
|
||||
background: var(--border-strong);
|
||||
}
|
||||
|
||||
/*
|
||||
* Settings › Appearance › Hide scrollbars (v1.1.0, src/utils/scrollbars.ts).
|
||||
* Only the bars go; the wheel, touchpad, touch and keyboard still scroll.
|
||||
* `scrollbar-width` is not inherited, hence the `*`: it covers Chromium
|
||||
* (WebView2, Android) and Firefox, while WebKit (the macOS and Linux
|
||||
* webviews) needs the pseudo-element. Unlayered, so it beats .scrollbar-thin.
|
||||
*/
|
||||
html.hide-scrollbars,
|
||||
html.hide-scrollbars * {
|
||||
scrollbar-width: none;
|
||||
}
|
||||
html.hide-scrollbars::-webkit-scrollbar,
|
||||
html.hide-scrollbars *::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/*
|
||||
* Legal Center documents (src/pages/LegalPage.tsx). The HTML is rendered at
|
||||
* build time from the repo's Markdown, so it arrives as bare elements that
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Settings › Appearance › Hide scrollbars (v1.1.0). A class on <html> that
|
||||
* globals.css turns into `scrollbar-width: none` everywhere; scrolling itself
|
||||
* is untouched. public/theme-init.js sets the same class before first paint —
|
||||
* it cannot import this module, so keep the name in step there.
|
||||
*/
|
||||
export function applyHideScrollbars(hidden: boolean): void {
|
||||
document.documentElement.classList.toggle("hide-scrollbars", hidden);
|
||||
}
|
||||
@@ -66,6 +66,7 @@ describe("healSettings", () => {
|
||||
appLanguage: "vi" as const,
|
||||
defaultOutputLanguage: "en" as const,
|
||||
theme: "light" as const,
|
||||
hideScrollbars: true,
|
||||
showCharCount: false,
|
||||
compactTagDisplay: true,
|
||||
historyLimit: 50,
|
||||
@@ -323,3 +324,19 @@ describe("healSettings — v1.0.0 fields", () => {
|
||||
expect(healed.titleFormat.order).toBe("gameFirst");
|
||||
});
|
||||
});
|
||||
|
||||
describe("healSettings — v1.1.0 hideScrollbars", () => {
|
||||
it("defaults to showing scrollbars when absent", () => {
|
||||
expect(healSettings({ theme: "dark" }).hideScrollbars).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps a real boolean", () => {
|
||||
expect(healSettings({ hideScrollbars: true }).hideScrollbars).toBe(true);
|
||||
expect(healSettings({ hideScrollbars: false }).hideScrollbars).toBe(false);
|
||||
});
|
||||
|
||||
it("does not let a truthy non-boolean hide every scrollbar", () => {
|
||||
expect(healSettings({ hideScrollbars: "yes" }).hideScrollbars).toBe(false);
|
||||
expect(healSettings({ hideScrollbars: 1 }).hideScrollbars).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
||||
import { readFileSync } from "fs";
|
||||
import { resolve } from "path";
|
||||
import { applyHideScrollbars } from "@utils/scrollbars";
|
||||
|
||||
describe("applyHideScrollbars", () => {
|
||||
let classes: Set<string>;
|
||||
|
||||
beforeEach(() => {
|
||||
classes = new Set(["dark"]);
|
||||
// The test environment has no DOM — a classList is all this touches.
|
||||
vi.stubGlobal("document", {
|
||||
documentElement: {
|
||||
classList: {
|
||||
toggle: (name: string, force: boolean) => {
|
||||
if (force) classes.add(name);
|
||||
else classes.delete(name);
|
||||
return force;
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("adds the class when scrollbars are hidden and removes it again", () => {
|
||||
applyHideScrollbars(true);
|
||||
expect(classes.has("hide-scrollbars")).toBe(true);
|
||||
applyHideScrollbars(false);
|
||||
expect(classes.has("hide-scrollbars")).toBe(false);
|
||||
});
|
||||
|
||||
it("leaves the theme class alone", () => {
|
||||
applyHideScrollbars(true);
|
||||
applyHideScrollbars(false);
|
||||
expect(classes.has("dark")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("hide-scrollbars wiring", () => {
|
||||
// theme-init.js runs before the bundle and cannot import the helper, and the
|
||||
// CSS only knows the class by name: the three must agree on it.
|
||||
it("uses the same class name in theme-init.js and globals.css", () => {
|
||||
const init = readFileSync(resolve("public/theme-init.js"), "utf8");
|
||||
const css = readFileSync(resolve("src/styles/globals.css"), "utf8");
|
||||
expect(init).toContain('root.classList.toggle("hide-scrollbars", hideScrollbars)');
|
||||
expect(init).toContain("state.hideScrollbars === true");
|
||||
expect(css).toContain("html.hide-scrollbars *");
|
||||
expect(css).toContain("scrollbar-width: none");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user