fix: strip Electron UA tokens, refresh bookmark star on in-app navigation

- main.js: app.userAgentFallback cleaned of Electron/X.X and ESH-Media/X.X
  tokens at startup; applied to default/proxy/direct sessions. Google's
  accounts page blocked Electron UA with "Поддержка JavaScript отключена".
- Header.tsx: subscribe currentUrl to updateWebButtons (already fired on
  each in-app navigation). Bookmark star now updates as user clicks
  between movies inside the same opened site, not only on app switch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-16 20:27:26 +03:00
parent 2857a40d1e
commit 10361cf3c0
3 changed files with 21 additions and 7 deletions

15
main.js
View File

@@ -110,6 +110,7 @@ let pendingNavigate = null; // { view, url } — cross-domain redirect awaiting
function getProxySession() { function getProxySession() {
if (!proxySession) { if (!proxySession) {
proxySession = session.fromPartition('persist:proxy'); proxySession = session.fromPartition('persist:proxy');
proxySession.setUserAgent(app.userAgentFallback);
enableBlockingInSession(proxySession); enableBlockingInSession(proxySession);
} }
return proxySession; return proxySession;
@@ -118,6 +119,7 @@ function getProxySession() {
function getDirectSession() { function getDirectSession() {
if (!directSession) { if (!directSession) {
directSession = session.fromPartition('persist:direct'); directSession = session.fromPartition('persist:direct');
directSession.setUserAgent(app.userAgentFallback);
directSession.setProxy({ proxyRules: 'direct://' }); directSession.setProxy({ proxyRules: 'direct://' });
enableBlockingInSession(directSession); enableBlockingInSession(directSession);
} }
@@ -981,6 +983,19 @@ ipcMain.on('action', (_event, action) => {
// --- App lifecycle --- // --- App lifecycle ---
app.whenReady().then(async () => { app.whenReady().then(async () => {
// Strip Electron/app tokens from User-Agent: Google blocks Electron's default UA
// with "Поддержка JavaScript отключена" on accounts.google.com. We keep the Chrome
// version Electron advertises (sufficient for modern features) but remove the
// Electron/X.X.X and ESH-Media/X.X.X identifiers.
const cleanUserAgent = app.userAgentFallback
.replace(/Electron\/[\d.]+\s*/g, '')
.replace(/ESH-Media\/[\d.]+\s*/g, '')
.replace(/\s+/g, ' ')
.trim();
console.log('[ua]', cleanUserAgent);
app.userAgentFallback = cleanUserAgent;
session.defaultSession.setUserAgent(cleanUserAgent);
// Add Referer to image requests so hotlink protection doesn't block them // Add Referer to image requests so hotlink protection doesn't block them
session.defaultSession.webRequest.onBeforeSendHeaders( session.defaultSession.webRequest.onBeforeSendHeaders(
{ urls: ['https://*/*', 'http://*/*'] }, { urls: ['https://*/*', 'http://*/*'] },

View File

@@ -1,6 +1,6 @@
{ {
"name": "ESH-Media", "name": "ESH-Media",
"version": "1.0.1", "version": "1.0.2",
"private": true, "private": true,
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {

View File

@@ -21,6 +21,7 @@ const Header: React.FC<HeaderProps> = ({ activeApp, setActiveApp, onAppsChange,
const [rightDisabled, setRightDisabled] = useState(true) const [rightDisabled, setRightDisabled] = useState(true)
const [refreshDisabled, setRefreshDisabled] = useState(true) const [refreshDisabled, setRefreshDisabled] = useState(true)
const [showSettings, setShowSettings] = useState(false) const [showSettings, setShowSettings] = useState(false)
const [currentUrl, setCurrentUrl] = useState<string>('')
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null) const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const activeAppRef = useRef(activeApp) const activeAppRef = useRef(activeApp)
useEffect(() => { activeAppRef.current = activeApp }, [activeApp]) useEffect(() => { activeAppRef.current = activeApp }, [activeApp])
@@ -36,6 +37,7 @@ const Header: React.FC<HeaderProps> = ({ activeApp, setActiveApp, onAppsChange,
setLeftDisabled(app.historyPosition === 0) setLeftDisabled(app.historyPosition === 0)
setRightDisabled(app.historyPosition === app.history.length - 1) setRightDisabled(app.historyPosition === app.history.length - 1)
setRefreshDisabled(false) setRefreshDisabled(false)
setCurrentUrl(app.history[app.historyPosition] || '')
}) })
return () => { offCloseApp(); offWebButtons() } return () => { offCloseApp(); offWebButtons() }
}, [setActiveApp]) }, [setActiveApp])
@@ -149,12 +151,9 @@ const Header: React.FC<HeaderProps> = ({ activeApp, setActiveApp, onAppsChange,
} }
useEffect(() => { useEffect(() => {
if (!appOpen) { setIsBookmarked(false); return } if (!appOpen || !currentUrl) { setIsBookmarked(false); return }
window.electron?.getCurrentPage().then((page: any) => { setIsBookmarked(bookmarks.some(b => b.url === currentUrl))
if (!page) return }, [currentUrl, bookmarks, appOpen])
setIsBookmarked(bookmarks.some(b => b.url === page.url))
})
}, [activeApp, bookmarks, appOpen])
return ( return (
<> <>