- 新增独立设置页(移动端从「我的」进入,桌面侧栏新增入口):外观、 本地数据、清理缓存、线路、网络诊断、检查更新、关于 - 线路(数据源):固定线路 1/2 与地址发布页镜像可切换,选择落盘、 重启沿用;镜像可并发探测延迟 - 检查更新:对比 GitHub Release 最新 tag,可直接打开发布页 - 观看记录记录集数与秒数,从历史进入可续播,卡片显示进度 - 网络层按当前系统代理重建 client,请求失败后自动重建(3 秒节流), 修代理软件开关后一直 tunnel error 的问题 - 修复浅色主题下播放页浮层文字/图标变黑不可见:底栏四项、右侧 收藏/评论/全屏/分享、右上角静音与搜索、倍速徽标等,改用固定白字 与显式 rgba 底色(不依赖 color-mix) - 修复从搜索/分类/我的进入的播放页底部多留 20px、露出一条「底栏」窄缝 - 浅色主题下搜索/分类/我的 底栏改为浅色,首页保持深色 - 评论入口回到右侧操作栏(收藏与全屏之间),补回移动端评论弹层与 图文详情面板;评论列表分隔线改用主题色(浅色下不再变成黑线) - 移动端登录/注册改为底部抽屉,键盘不再遮挡输入框 - 「我的」页重构:未登录也能看收藏与观看历史,资料卡本身即登录入口
281 lines
12 KiB
TypeScript
281 lines
12 KiB
TypeScript
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
||
import { useStore, type Page, type Tab } from "./store";
|
||
import { selfTest } from "./api";
|
||
import { addPluginListener, invoke } from "@tauri-apps/api/core";
|
||
import { runBack } from "./back";
|
||
import Home from "./pages/Home";
|
||
import Search, { RankPage } from "./pages/Search";
|
||
import Category, { ChannelPage } from "./pages/Category";
|
||
import Profile from "./pages/Profile";
|
||
import SettingsPage from "./pages/Settings";
|
||
import Feed from "./components/Feed";
|
||
import { PostsPage, PostDetail } from "./pages/Posts";
|
||
import LoginModal from "./components/LoginModal";
|
||
import { ToastHost } from "./components/ui";
|
||
import { DesktopRail, DesktopTitleBar } from "./components/DesktopChrome";
|
||
import ResizeHandles from "./components/ResizeHandles";
|
||
import { IGrid, IGridF, IHome, IHomeF, ISearch, IUser, IUserF, Logo } from "./icons";
|
||
|
||
/* ============ 底部标签栏(Android)—— 细瘦纯文字、低侵入 ============ */
|
||
function TabBar() {
|
||
const { tab, setTab, theme } = useStore();
|
||
const items: { k: Tab; label: string }[] = [
|
||
{ k: "home", label: "首页" },
|
||
{ k: "search", label: "搜索" },
|
||
{ k: "category", label: "分类" },
|
||
{ k: "profile", label: "我的" },
|
||
];
|
||
/* 细瘦纯文字分栏:只有选中项高亮,没有指示点。
|
||
首页是沉浸视频 → 底栏压深色;搜索/分类/我的 是浅色内容页 →
|
||
浅色主题下底栏跟着换成浅色,深色主题保持深色。 */
|
||
const overVideo = tab === "home";
|
||
const lightBar = !overVideo && theme === "light";
|
||
return (
|
||
<nav className="hg-tabbar absolute bottom-0 inset-x-0 z-30"
|
||
style={{
|
||
paddingBottom: "var(--sab, 0px)",
|
||
background: lightBar ? "rgba(250, 250, 250, .97)" : overVideo ? "#000000" : "#141414",
|
||
borderTop: lightBar ? "1px solid rgba(0,0,0,.08)" : overVideo ? "none" : "1px solid rgba(255,255,255,.07)",
|
||
boxShadow: lightBar ? "0 -2px 14px rgba(0,0,0,.05)" : "none",
|
||
}}>
|
||
<div className="h-[40px] flex items-center px-1">
|
||
{items.map(({ k, label }) => {
|
||
const on = tab === k;
|
||
return (
|
||
<button key={k} onClick={() => setTab(k)} className="flex-1 h-full flex items-center justify-center pressable">
|
||
<span className="text-[12.5px] leading-none transition-colors duration-200"
|
||
style={{
|
||
fontWeight: on ? 700 : 400,
|
||
color: lightBar
|
||
? (on ? "var(--p-primary)" : "rgba(0,0,0,.45)")
|
||
: (on ? "#ffffff" : "rgba(255,255,255,.6)"),
|
||
}}>
|
||
{label}
|
||
</span>
|
||
</button>
|
||
);
|
||
})}
|
||
</div>
|
||
</nav>
|
||
);
|
||
}
|
||
|
||
/* ============ 堆栈页面 ============ */
|
||
function StackPage({ page, onBack, wide, top, bottomInset }: {
|
||
page: Page; onBack: () => void; wide: boolean; top: boolean; bottomInset: number;
|
||
}) {
|
||
if (page.kind === "feed") {
|
||
return (
|
||
<Feed videoIds={page.videoIds} startIndex={page.index} title={page.title} kind={page.feedKind || "video"}
|
||
startEp={page.startEp} startTime={page.startTime}
|
||
mode="context" active={top} bottomInset={bottomInset} onBack={onBack} />
|
||
);
|
||
}
|
||
if (page.kind === "channel") return <ChannelPage cate={page.cate} name={page.name} onBack={onBack} wide={wide} />;
|
||
if (page.kind === "ranks") return <RankPage onBack={onBack} wide={wide} />;
|
||
if (page.kind === "settings") return <SettingsPage onBack={onBack} wide={wide} />;
|
||
if (page.kind === "posts") return <PostsPage onBack={onBack} wide={wide} />;
|
||
if (page.kind === "post") return <PostDetail id={page.id} onBack={onBack} />;
|
||
return null;
|
||
}
|
||
|
||
/* ============ 应用主体 ============ */
|
||
function AppBody() {
|
||
const { platform, tab, setTab, stack, pop, loginOpen, setLoginOpen, fs } = useStore();
|
||
const mainRef = useRef<HTMLDivElement>(null);
|
||
const [wide, setWide] = useState(platform !== "android");
|
||
const [collapsed, setCollapsed] = useState(false);
|
||
|
||
useLayoutEffect(() => {
|
||
const el = mainRef.current;
|
||
if (!el) return;
|
||
const ro = new ResizeObserver(() => setWide(el.clientWidth > 640));
|
||
ro.observe(el);
|
||
setWide(el.clientWidth > 640);
|
||
return () => ro.disconnect();
|
||
}, []);
|
||
|
||
/* 全局键盘 */
|
||
useEffect(() => {
|
||
const fn = (e: KeyboardEvent) => {
|
||
const t = e.target as HTMLElement;
|
||
if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA")) {
|
||
if (e.key === "Escape") t.blur();
|
||
return;
|
||
}
|
||
if (loginOpen) { if (e.key === "Escape") setLoginOpen(false); return; }
|
||
if (e.key === "Escape") { if (stack.length) pop(); return; }
|
||
if (e.key === "/") { e.preventDefault(); setTab("search"); return; }
|
||
if (["1", "2", "3", "4"].includes(e.key) && !e.repeat) {
|
||
setTab((["home", "search", "category", "profile"] as Tab[])[Number(e.key) - 1]);
|
||
}
|
||
};
|
||
window.addEventListener("keydown", fn);
|
||
return () => window.removeEventListener("keydown", fn);
|
||
}, [stack.length, pop, setTab, loginOpen, setLoginOpen]);
|
||
|
||
const vis = (k: Tab) => (tab === k ? "absolute inset-0" : "absolute inset-0 invisible pointer-events-none");
|
||
const pageActive = stack.length === 0 && !loginOpen;
|
||
const bottomInset = platform === "android" ? (fs ? 0 : 40) : 14;
|
||
/* 栈页(从搜索/分类/我的进入的播放页、图文页)没有底栏,
|
||
底部只让出安全区。之前多留了 20px,视频底边会露出一条
|
||
「底栏」似的窄缝(底部的压暗渐变到不了屏幕最底)。 */
|
||
const stackInset = platform === "android" ? 0 : 14;
|
||
|
||
return (
|
||
<div className={`absolute inset-0 flex bg-canvas plat-${platform}`}>
|
||
{platform !== "android" && <DesktopRail collapsed={collapsed} />}
|
||
<div ref={mainRef} className="relative flex-1 min-w-0 overflow-hidden win-main">
|
||
<div className={vis("home")}><Home active={pageActive && tab === "home"} bottomInset={bottomInset} /></div>
|
||
<div className={vis("search")}><Search active={pageActive && tab === "search"} wide={wide} /></div>
|
||
<div className={vis("category")}><Category wide={wide} /></div>
|
||
<div className={vis("profile")}><Profile wide={wide} /></div>
|
||
|
||
{stack.map((p, i) => (
|
||
<div key={p.key} className="absolute inset-0 z-30 bg-bg a-page-in" style={{ boxShadow: "-18px 0 40px rgba(0,0,0,.5)" }}>
|
||
<StackPage page={p} onBack={pop} wide={wide} top={i === stack.length - 1} bottomInset={stackInset} />
|
||
</div>
|
||
))}
|
||
|
||
{platform === "android" && !fs && stack.length === 0 && <TabBar />}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/* ============ 桌面窗口壳(Windows / macOS)============ */
|
||
function DesktopShell() {
|
||
const [collapsed, setCollapsed] = useState(false);
|
||
const { theater, platform } = useStore();
|
||
return (
|
||
<div className={`absolute inset-0 flex flex-col bg-canvas win-root plat-${platform}`}>
|
||
<DesktopTitleBar collapsed={collapsed} onToggle={() => setCollapsed((c) => !c)} />
|
||
<div className="relative flex-1 min-h-0">
|
||
<ShellInner collapsed={collapsed || theater} theater={theater} />
|
||
</div>
|
||
{/* 边缘缩放热区只对无边框窗口(Windows)有效,macOS 走原生窗口边框 */}
|
||
{platform === "windows" && <ResizeHandles />}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function ShellInner({ collapsed, theater }: { collapsed: boolean; theater: boolean }) {
|
||
const { stack, pop, loginOpen, setLoginOpen, tab, setTab, platform } = useStore();
|
||
const mainRef = useRef<HTMLDivElement>(null);
|
||
const [wide, setWide] = useState(true);
|
||
|
||
useLayoutEffect(() => {
|
||
const el = mainRef.current;
|
||
if (!el) return;
|
||
const ro = new ResizeObserver(() => setWide(el.clientWidth > 640));
|
||
ro.observe(el);
|
||
setWide(el.clientWidth > 640);
|
||
return () => ro.disconnect();
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
const fn = (e: KeyboardEvent) => {
|
||
const t = e.target as HTMLElement;
|
||
if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA")) {
|
||
if (e.key === "Escape") t.blur();
|
||
return;
|
||
}
|
||
if (loginOpen) { if (e.key === "Escape") setLoginOpen(false); return; }
|
||
if (e.key === "Escape") { if (stack.length) pop(); return; }
|
||
if (e.key === "/") { e.preventDefault(); setTab("search"); return; }
|
||
if (["1", "2", "3", "4"].includes(e.key) && !e.repeat) {
|
||
setTab((["home", "search", "category", "profile"] as Tab[])[Number(e.key) - 1]);
|
||
}
|
||
};
|
||
window.addEventListener("keydown", fn);
|
||
return () => window.removeEventListener("keydown", fn);
|
||
}, [stack.length, pop, setTab, loginOpen, setLoginOpen]);
|
||
|
||
const vis = (k: Tab) => (tab === k ? "absolute inset-0" : "absolute inset-0 invisible pointer-events-none");
|
||
const pageActive = stack.length === 0 && !loginOpen;
|
||
|
||
return (
|
||
<div className={`absolute inset-0 flex bg-canvas plat-${platform}`}>
|
||
{!theater && <DesktopRail collapsed={collapsed} />}
|
||
<div ref={mainRef} className={`relative flex-1 min-w-0 overflow-hidden win-main ${theater ? "is-theater-main" : ""}`}>
|
||
<div className={vis("home")}><Home active={pageActive && tab === "home"} bottomInset={14} /></div>
|
||
<div className={vis("search")}><Search active={pageActive && tab === "search"} wide={wide} /></div>
|
||
<div className={vis("category")}><Category wide={wide} /></div>
|
||
<div className={vis("profile")}><Profile wide={wide} /></div>
|
||
{stack.map((p, i) => (
|
||
<div key={p.key} className="absolute inset-0 z-30 bg-bg win-page-in" style={{ boxShadow: "-18px 0 40px rgba(0,0,0,.5)" }}>
|
||
<StackPage page={p} onBack={pop} wide={wide} top={i === stack.length - 1} bottomInset={14} />
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/* ============ 移动端(无壳) ============ */
|
||
function MobileShell() {
|
||
return (
|
||
<div className="absolute inset-0 flex flex-col bg-canvas plat-android"
|
||
style={{ "--sat": "max(env(safe-area-inset-top), 8px)", "--sab": "max(env(safe-area-inset-bottom), 6px)" } as React.CSSProperties}>
|
||
<div className="relative flex-1 min-h-0">
|
||
<AppBody />
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/* ============ 入口 ============ */
|
||
export default function App() {
|
||
const { platform, loginOpen, setLoginOpen, tab, setTab, stack, pop, fs, setFs } = useStore();
|
||
|
||
/* —— 安卓硬件返回键 ——
|
||
层级:全屏 → 面板/弹层 → 登录框 → 页面栈 → 回首页 → 退出应用。
|
||
不注册这个监听,Tauri 会直接 webView.goBack() 或退出,表现就是「任意页面返回都回桌面」。 */
|
||
const backRef = useRef<() => void>(() => {});
|
||
backRef.current = () => {
|
||
if (fs) { setFs(false); return; } // 沉浸全屏
|
||
if (document.fullscreenElement) { document.exitFullscreen().catch(() => {}); return; }
|
||
if (runBack()) return; // 播放器的选集/评论/图文面板
|
||
if (loginOpen) { setLoginOpen(false); return; }
|
||
if (stack.length) { pop(); return; }
|
||
if (tab !== "home") { setTab("home"); return; }
|
||
invoke("plugin:app|exit", { code: 0 }).catch(() => {});
|
||
};
|
||
|
||
useEffect(() => {
|
||
if (platform !== "android") return undefined;
|
||
let disposed = false;
|
||
let handle: { unregister: () => Promise<void> } | null = null;
|
||
addPluginListener("app", "back-button", () => backRef.current())
|
||
.then((l) => { if (disposed) l.unregister().catch(() => {}); else handle = l; })
|
||
.catch(() => { /* 非安卓宿主忽略 */ });
|
||
return () => {
|
||
disposed = true;
|
||
handle?.unregister().catch(() => {});
|
||
};
|
||
}, [platform]);
|
||
|
||
useEffect(() => {
|
||
const prevent = (e: Event) => e.preventDefault();
|
||
document.addEventListener("contextmenu", prevent);
|
||
return () => document.removeEventListener("contextmenu", prevent);
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
if (!import.meta.env.DEV) return;
|
||
const t = window.setTimeout(() => {
|
||
selfTest().then((r) => { invoke("debug_log", { msg: r }).catch(() => {}); }).catch(() => {});
|
||
}, 2500);
|
||
return () => window.clearTimeout(t);
|
||
}, []);
|
||
|
||
return (
|
||
<>
|
||
{platform === "android" ? <MobileShell /> : <DesktopShell />}
|
||
<LoginModal />
|
||
<ToastHost />
|
||
{/* 登录遮罩键盘处理占位 */}
|
||
{loginOpen && <div className="hidden" onClick={() => setLoginOpen(false)} />}
|
||
</>
|
||
);
|
||
} |