mirror of
https://github.com/Andre-Bzk/twitch4steamdeck.git
synced 2026-11-15 15:43:08 +01:00
refactor: extract IPC channel names into a single source of truth
Duplicate raw string literals across handlers.ts, preload/index.ts made typos undetectable at compile time and renames a multi-file grep problem. A single channels.ts now owns all channel names; both files import from it. Also fixes two bugs found during testing: - LoginScreen and AccountScreen buttons were not triggerable via gamepad A-button: synthetic KeyboardEvents are untrusted and don't fire native button clicks. Added explicit keydown handlers that call the action directly. - AppShell loading overlay could disappear while hlsPayload was still null if the playback:event 'started' IPC message arrived before playback:hls-url. Overlay now stays visible until hlsPayload is set, regardless of playState.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
export const IPC = {
|
||||
appQuit: 'app:quit',
|
||||
authStatus: 'auth:get-status',
|
||||
authStart: 'auth:start-device-flow',
|
||||
authCancel: 'auth:cancel',
|
||||
authLogout: 'auth:logout',
|
||||
authConfigured: 'auth:is-configured',
|
||||
/** main → renderer */
|
||||
authEvent: 'auth:event',
|
||||
|
||||
twitchGetFollowed: 'twitch:get-followed',
|
||||
twitchGetOwnUser: 'twitch:get-own-user',
|
||||
twitchGetVideos: 'twitch:get-videos',
|
||||
twitchGetTopGames: 'twitch:get-top-games',
|
||||
twitchGetTopStreams: 'twitch:get-top-streams',
|
||||
twitchGetVodChapters: 'twitch:get-vod-chapters',
|
||||
historyGetProgress: 'history:get-progress',
|
||||
|
||||
playbackStartLive: 'playback:start-live',
|
||||
playbackStartVod: 'playback:start-vod',
|
||||
playbackStop: 'playback:stop',
|
||||
playbackPause: 'playback:pause',
|
||||
playbackReportPosition: 'playback:report-position',
|
||||
playbackGetQualities: 'playback:get-qualities',
|
||||
/** main → renderer */
|
||||
playbackEvent: 'playback:event',
|
||||
/** main → renderer: HLS-URL + Metadaten für den Renderer-seitigen Video-Player */
|
||||
playbackHlsUrl: 'playback:hls-url',
|
||||
|
||||
appGetCacheSize: 'app:get-cache-size',
|
||||
appClearCache: 'app:clear-cache',
|
||||
appSetHlsCacheEnabled: 'app:set-hls-cache-enabled',
|
||||
|
||||
/** main → renderer */
|
||||
gamepadInput: 'gamepad-input'
|
||||
} as const
|
||||
@@ -8,40 +8,9 @@ import type { PlaybackService } from '../playback/playbackService'
|
||||
import type { HlsUrlPayload } from '../playback/playbackService'
|
||||
import type { PlaybackEvent } from '../playback/types'
|
||||
import { getProgressMap } from '../store/historyRepo'
|
||||
import { IPC } from './channels'
|
||||
|
||||
export const IPC = {
|
||||
appQuit: 'app:quit',
|
||||
authStatus: 'auth:get-status',
|
||||
authStart: 'auth:start-device-flow',
|
||||
authCancel: 'auth:cancel',
|
||||
authLogout: 'auth:logout',
|
||||
authConfigured: 'auth:is-configured',
|
||||
/** main → renderer */
|
||||
authEvent: 'auth:event',
|
||||
|
||||
twitchGetFollowed: 'twitch:get-followed',
|
||||
twitchGetOwnUser: 'twitch:get-own-user',
|
||||
twitchGetVideos: 'twitch:get-videos',
|
||||
twitchGetTopGames: 'twitch:get-top-games',
|
||||
twitchGetTopStreams: 'twitch:get-top-streams',
|
||||
twitchGetVodChapters: 'twitch:get-vod-chapters',
|
||||
historyGetProgress: 'history:get-progress',
|
||||
|
||||
playbackStartLive: 'playback:start-live',
|
||||
playbackStartVod: 'playback:start-vod',
|
||||
playbackStop: 'playback:stop',
|
||||
playbackPause: 'playback:pause',
|
||||
playbackReportPosition: 'playback:report-position',
|
||||
playbackGetQualities: 'playback:get-qualities',
|
||||
/** main → renderer */
|
||||
playbackEvent: 'playback:event',
|
||||
/** main → renderer: HLS-URL + Metadaten für den Renderer-seitigen Video-Player */
|
||||
playbackHlsUrl: 'playback:hls-url',
|
||||
|
||||
appGetCacheSize: 'app:get-cache-size',
|
||||
appClearCache: 'app:clear-cache',
|
||||
appSetHlsCacheEnabled: 'app:set-hls-cache-enabled'
|
||||
} as const
|
||||
export { IPC }
|
||||
|
||||
export function registerIpcHandlers(
|
||||
auth: AuthService,
|
||||
|
||||
+1
-33
@@ -1,37 +1,5 @@
|
||||
import { contextBridge, ipcRenderer, type IpcRendererEvent } from 'electron'
|
||||
|
||||
const IPC = {
|
||||
appQuit: 'app:quit',
|
||||
authStatus: 'auth:get-status',
|
||||
authStart: 'auth:start-device-flow',
|
||||
authCancel: 'auth:cancel',
|
||||
authLogout: 'auth:logout',
|
||||
authConfigured: 'auth:is-configured',
|
||||
authEvent: 'auth:event',
|
||||
|
||||
twitchGetFollowed: 'twitch:get-followed',
|
||||
twitchGetOwnUser: 'twitch:get-own-user',
|
||||
twitchGetVideos: 'twitch:get-videos',
|
||||
twitchGetTopGames: 'twitch:get-top-games',
|
||||
twitchGetTopStreams: 'twitch:get-top-streams',
|
||||
twitchGetVodChapters: 'twitch:get-vod-chapters',
|
||||
historyGetProgress: 'history:get-progress',
|
||||
|
||||
playbackStartLive: 'playback:start-live',
|
||||
playbackStartVod: 'playback:start-vod',
|
||||
playbackStop: 'playback:stop',
|
||||
playbackPause: 'playback:pause',
|
||||
playbackReportPosition: 'playback:report-position',
|
||||
playbackGetQualities: 'playback:get-qualities',
|
||||
playbackEvent: 'playback:event',
|
||||
playbackHlsUrl: 'playback:hls-url',
|
||||
|
||||
appGetCacheSize: 'app:get-cache-size',
|
||||
appClearCache: 'app:clear-cache',
|
||||
appSetHlsCacheEnabled: 'app:set-hls-cache-enabled',
|
||||
|
||||
gamepadInput: 'gamepad-input'
|
||||
} as const
|
||||
import { IPC } from '../main/ipc/channels'
|
||||
|
||||
export type AuthStatus = 'logged-out' | 'logged-in'
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ export default function AccountScreen({ hasFocus, onRequestSidebar, onLogout }:
|
||||
if (e.key === 'ArrowLeft') {
|
||||
e.preventDefault()
|
||||
onRequestSidebar()
|
||||
} else if (e.key === 'Enter') {
|
||||
void handleLogout()
|
||||
}
|
||||
}
|
||||
window.addEventListener('keydown', onKey)
|
||||
|
||||
@@ -307,7 +307,7 @@ export default function AppShell({ onLogout }: Props): JSX.Element {
|
||||
{isGlobalPlaying && !selectedChannel && (
|
||||
<>
|
||||
{/* Lade-Overlay während streamlink läuft */}
|
||||
{livePlayState === 'starting' && !liveHlsPayload && (
|
||||
{!liveHlsPayload && livePlayState !== 'error' && (
|
||||
<div style={{
|
||||
position: 'fixed', inset: 0, zIndex: 100,
|
||||
background: '#000', display: 'flex',
|
||||
|
||||
@@ -25,6 +25,16 @@ export default function LoginScreen({ onAuthorized }: Props): JSX.Element {
|
||||
startBtnRef.current?.focus()
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent): void => {
|
||||
if (e.key !== 'Enter') return
|
||||
if (phase.kind === 'idle' || phase.kind === 'error') void start()
|
||||
else if (phase.kind === 'awaiting') void cancel()
|
||||
}
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => window.removeEventListener('keydown', onKey)
|
||||
}, [phase])
|
||||
|
||||
// Auth-Events aus Main abonnieren.
|
||||
useEffect(() => {
|
||||
const off = window.t4sd.auth.onEvent((event) => {
|
||||
|
||||
Vendored
+1
@@ -1,4 +1,5 @@
|
||||
// Spiegel der Preload-API. Manuell synchron halten zu src/preload/index.ts.
|
||||
// IPC-Channel-Namen: src/main/ipc/channels.ts (Renderer kann nicht direkt importieren).
|
||||
|
||||
export type AuthStatus = 'logged-out' | 'logged-in'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user