优化局域网遥控

This commit is contained in:
mtvpls
2026-06-19 15:59:44 +08:00
parent 9881ad3238
commit e9ac8f3067
5 changed files with 27 additions and 80 deletions
+2 -18
View File
@@ -37,7 +37,6 @@ const LOCAL_REMOTE_URL_KEY = 'moontv_local_remote_url';
type MoonTVLocalRemoteBridge = {
getRemoteUrl?: () => string;
showHint?: () => void;
};
declare global {
@@ -89,7 +88,6 @@ export default function TVMePage() {
const [loggingOut, setLoggingOut] = useState(false);
const [error, setError] = useState('');
const [localRemoteUrl, setLocalRemoteUrl] = useState('');
const [nativeHintAvailable, setNativeHintAvailable] = useState(false);
const [copyStatus, setCopyStatus] = useState('');
const [upDownAction, setUpDownAction] = useState<TVPlayerUpDownAction>(
DEFAULT_TV_PLAYER_UP_DOWN_ACTION
@@ -107,7 +105,6 @@ export default function TVMePage() {
useEffect(() => {
const readLocalRemoteUrl = () => {
const bridgeUrl = window.MoonTVLocalRemote?.getRemoteUrl?.() || '';
setNativeHintAvailable(Boolean(window.MoonTVLocalRemote?.showHint));
setLocalRemoteUrl(
bridgeUrl ||
window.__MOONTV_LOCAL_REMOTE_URL ||
@@ -184,9 +181,6 @@ export default function TVMePage() {
};
const showLocalRemoteHint = () => {
window.MoonTVLocalRemote?.showHint?.();
};
const copyLocalRemoteUrl = async () => {
if (!localRemoteUrl) return;
@@ -310,7 +304,7 @@ export default function TVMePage() {
</h2>
<p className='mt-4 text-xl leading-relaxed text-slate-300'>
WiFi
WiFi
</p>
{localRemoteUrl ? (
@@ -320,16 +314,6 @@ export default function TVMePage() {
{localRemoteUrl}
</div>
<div className='mt-5 flex flex-wrap gap-3'>
{nativeHintAvailable && (
<button
type='button'
onClick={showLocalRemoteHint}
className='tv-focusable inline-flex cursor-pointer items-center justify-center gap-2 rounded-2xl bg-indigo-600 px-5 py-4 text-lg font-black text-white outline-none transition hover:bg-indigo-500 focus:ring-4 focus:ring-indigo-300'
>
<QrCode className='h-6 w-6' />
</button>
)}
<button
type='button'
onClick={copyLocalRemoteUrl}
@@ -347,7 +331,7 @@ export default function TVMePage() {
</div>
) : (
<div className='mt-6 rounded-3xl border border-amber-300/20 bg-amber-400/10 p-5 text-lg leading-relaxed text-amber-100'>
APK 使 APK
APK 使 APK
</div>
)}
</div>
+20 -7
View File
@@ -1372,8 +1372,21 @@ export const UserMenu: React.FC = () => {
const handleQrLoginResult = useCallback((rawValue: string) => {
try {
const url = new URL(rawValue, window.location.origin);
const isLocalRemoteUrl =
(url.protocol === 'http:' || url.protocol === 'https:') &&
url.searchParams.has('token') &&
(url.pathname === '/remote' || url.pathname.endsWith('/remote'));
if (isLocalRemoteUrl) {
setTvQrScannerStatus('识别成功,正在打开局域网遥控器...');
stopTvQrScanner();
window.location.href = url.href;
return true;
}
if (url.origin !== window.location.origin || url.pathname !== '/qr-login') {
setTvQrScannerError('未识别到本站电视登录二维码,请扫描电视屏幕上的二维码。');
setTvQrScannerError('未识别到电视登录二维码或局域网遥控二维码,请扫描电视屏幕上的二维码。');
return false;
}
@@ -1388,7 +1401,7 @@ export const UserMenu: React.FC = () => {
window.location.href = `/qr-login?token=${encodeURIComponent(token)}`;
return true;
} catch {
setTvQrScannerError('二维码内容无效,请扫描电视端显示的登录二维码。');
setTvQrScannerError('二维码内容无效,请扫描电视端显示的登录二维码或局域网遥控二维码。');
return false;
}
}, [stopTvQrScanner]);
@@ -1424,7 +1437,7 @@ export const UserMenu: React.FC = () => {
await tvQrVideoRef.current.play();
const detector = new BarcodeDetectorCtor({ formats: ['qr_code'] });
setTvQrScannerStatus('请将电视屏幕上的登录二维码放入取景框');
setTvQrScannerStatus('请将电视屏幕上的登录二维码或局域网遥控二维码放入取景框');
const scan = async () => {
if (tvQrScanStopRef.current || !tvQrVideoRef.current) return;
@@ -4408,8 +4421,8 @@ export const UserMenu: React.FC = () => {
<Smartphone className='h-4 w-4' />
</div>
<h3 className='mt-3 text-2xl font-black'></h3>
<p className='mt-1 text-sm text-white/75'></p>
<h3 className='mt-3 text-2xl font-black'></h3>
<p className='mt-1 text-sm text-white/75'></p>
</div>
<button
type='button'
@@ -4670,7 +4683,7 @@ export const UserMenu: React.FC = () => {
</div>
<p className='mt-5 text-sm leading-6 text-slate-600 dark:text-slate-400'>
{tvModeEnabled
? '电视端打开 /tv 后会显示二维码;手机在这里打开相机扫描并确认登录。'
? '电视端打开 /tv 后可扫码登录;在电视端“我的”页也可扫描局域网遥控二维码。'
: '当前部署未开启 TV 模式,/tv 页面和 Web 电视遥控不可用。'}
</p>
{!tvModeEnabled && (
@@ -4685,7 +4698,7 @@ export const UserMenu: React.FC = () => {
disabled={!tvModeEnabled}
className='inline-flex w-full cursor-pointer items-center justify-center gap-2 rounded-xl bg-rose-600 px-4 py-3 text-sm font-black text-white transition hover:bg-rose-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-rose-500/70 disabled:cursor-not-allowed disabled:bg-slate-300 disabled:text-slate-500 dark:disabled:bg-white/10 dark:disabled:text-slate-500'
>
<Smartphone className='h-4 w-4' />
</button>
<button