Skip to content

Commit

Permalink
Fix yomitan hiding causing the video player to exit fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
killergerbah committed Aug 24, 2024
1 parent b66a018 commit 7405b74
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 37 deletions.
4 changes: 0 additions & 4 deletions common/app/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,6 @@ function App({ origin, logoUrl, settings, extension, fetcher, onSettingsChanged,
setTheaterMode(newValue);
setVideoFullscreen(false);
}, [playbackPreferences]);
const handleFullscreenToggle = useCallback(() => {
setVideoFullscreen((fullscreen) => !fullscreen);
}, []);
useEffect(() => {
if (videoFullscreen) {
if (!document.fullscreenElement) {
Expand Down Expand Up @@ -1263,7 +1260,6 @@ function App({ origin, logoUrl, settings, extension, fetcher, onSettingsChanged,
onAnkiDialogRequest={handleAnkiDialogRequest}
onAnkiDialogRewind={handleAnkiDialogRewind}
onAppBarToggle={handleAppBarToggle}
onFullscreenToggle={handleFullscreenToggle}
onHideSubtitlePlayer={handleHideSubtitlePlayer}
onVideoPopOut={handleVideoPopOut}
onPlayModeChangedViaBind={handleAutoPauseModeChangedViaBind}
Expand Down
3 changes: 0 additions & 3 deletions common/app/components/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ interface PlayerProps {
onAnkiDialogRequest: () => void;
onAnkiDialogRewind: () => void;
onAppBarToggle: () => void;
onFullscreenToggle: () => void;
onHideSubtitlePlayer: () => void;
onVideoPopOut: () => void;
onPlayModeChangedViaBind: (oldPlayMode: PlayMode, newPlayMode: PlayMode) => void;
Expand Down Expand Up @@ -156,7 +155,6 @@ const Player = React.memo(function Player({
onAnkiDialogRequest,
onAnkiDialogRewind,
onAppBarToggle,
onFullscreenToggle,
onHideSubtitlePlayer,
onVideoPopOut,
onPlayModeChangedViaBind,
Expand Down Expand Up @@ -407,7 +405,6 @@ const Player = React.memo(function Player({
useEffect(() => channel?.onPopOutToggle(() => onVideoPopOut()), [channel, onVideoPopOut]);
useEffect(() => channel?.onHideSubtitlePlayerToggle(onHideSubtitlePlayer), [channel, onHideSubtitlePlayer]);
useEffect(() => channel?.onAppBarToggle(onAppBarToggle), [channel, onAppBarToggle]);
useEffect(() => channel?.onFullscreenToggle(onFullscreenToggle), [channel, onFullscreenToggle]);
useEffect(
() =>
channel?.onReady(() => {
Expand Down
22 changes: 9 additions & 13 deletions common/app/components/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1170,20 +1170,16 @@ export default function VideoPlayer({
}, [displaySubtitles, playbackPreferences]);

const handleFullscreenToggle = useCallback(() => {
if (popOut) {
setFullscreen((fullscreen) => {
if (fullscreen) {
document.exitFullscreen();
} else {
document.documentElement.requestFullscreen();
}
setFullscreen((fullscreen) => {
if (fullscreen) {
document.exitFullscreen();
} else {
document.documentElement.requestFullscreen();
}

return !fullscreen;
});
} else {
playerChannel.fullscreenToggle();
}
}, [playerChannel, popOut]);
return !fullscreen;
});
}, []);

const handleVolumeChange = useCallback((volume: number) => {
if (videoRef.current) {
Expand Down
4 changes: 0 additions & 4 deletions common/app/services/player-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,6 @@ export default class PlayerChannel {
this.channel?.postMessage({ command: 'appBarToggle' });
}

fullscreenToggle() {
this.channel?.postMessage({ command: 'fullscreenToggle' });
}

toggleSubtitleTrackInList(track: number) {
const message: ToggleSubtitleTrackInListFromVideoMessage = {
command: 'toggleSubtitleTrackInList',
Expand Down
13 changes: 0 additions & 13 deletions common/app/services/video-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export default class VideoChannel {
private playModeCallbacks: ((mode: PlayMode) => void)[];
private hideSubtitlePlayerToggleCallbacks: (() => void)[];
private appBarToggleCallbacks: (() => void)[];
private fullscreenToggleCallbacks: (() => void)[];
private ankiDialogRequestCallbacks: (() => void)[];
private toggleSubtitleTrackInListCallbacks: ((track: number) => void)[];

Expand Down Expand Up @@ -95,7 +94,6 @@ export default class VideoChannel {
this.playModeCallbacks = [];
this.hideSubtitlePlayerToggleCallbacks = [];
this.appBarToggleCallbacks = [];
this.fullscreenToggleCallbacks = [];
this.ankiDialogRequestCallbacks = [];
this.toggleSubtitleTrackInListCallbacks = [];

Expand Down Expand Up @@ -212,11 +210,6 @@ export default class VideoChannel {
callback();
}
break;
case 'fullscreenToggle':
for (const callback of this.fullscreenToggleCallbacks) {
callback();
}
break;
case 'sync':
// ignore
break;
Expand Down Expand Up @@ -341,11 +334,6 @@ export default class VideoChannel {
return () => this._remove(callback, this.appBarToggleCallbacks);
}

onFullscreenToggle(callback: () => void) {
this.fullscreenToggleCallbacks.push(callback);
return () => this._remove(callback, this.fullscreenToggleCallbacks);
}

onAnkiDialogRequest(callback: () => void) {
this.ankiDialogRequestCallbacks.push(callback);
return () => this._remove(callback, this.ankiDialogRequestCallbacks);
Expand Down Expand Up @@ -621,7 +609,6 @@ export default class VideoChannel {
this.playModeCallbacks = [];
this.hideSubtitlePlayerToggleCallbacks = [];
this.appBarToggleCallbacks = [];
this.fullscreenToggleCallbacks = [];
this.ankiDialogRequestCallbacks = [];
this.toggleSubtitleTrackInListCallbacks = [];
}
Expand Down

0 comments on commit 7405b74

Please sign in to comment.