refactor(common): remove use of ipc for fullscreen mode

This commit is contained in:
Tim 2025-05-31 17:10:57 +02:00
parent 67c1b814c3
commit 22259c8d19

View file

@ -1,30 +1,21 @@
// Copyright (C) 2017-2023 Smart code 203358507
import { useCallback, useEffect, useState } from 'react';
import useShell, { type WindowVisibility } from './useShell';
import useSettings from './useSettings';
const useFullscreen = () => {
const shell = useShell();
const [settings] = useSettings();
const [fullscreen, setFullscreen] = useState(false);
const requestFullscreen = useCallback(() => {
if (shell.active) {
shell.send('win-set-visibility', { fullscreen: true });
} else {
if (document.fullscreenElement !== document.documentElement) {
document.documentElement.requestFullscreen();
}
}, []);
const exitFullscreen = useCallback(() => {
if (shell.active) {
shell.send('win-set-visibility', { fullscreen: false });
} else {
if (document.fullscreenElement === document.documentElement) {
document.exitFullscreen();
}
if (document.fullscreenElement === document.documentElement) {
document.exitFullscreen();
}
}, []);
@ -33,10 +24,6 @@ const useFullscreen = () => {
}, [fullscreen]);
useEffect(() => {
const onWindowVisibilityChanged = (state: WindowVisibility) => {
setFullscreen(state.isFullscreen === true);
};
const onFullscreenChange = () => {
setFullscreen(document.fullscreenElement === document.documentElement);
};
@ -50,17 +37,15 @@ const useFullscreen = () => {
toggleFullscreen();
}
if (event.code === 'F11' && shell.active) {
if (event.code === 'F11') {
toggleFullscreen();
}
};
shell.on('win-visibility-changed', onWindowVisibilityChanged);
document.addEventListener('keydown', onKeyDown);
document.addEventListener('fullscreenchange', onFullscreenChange);
return () => {
shell.off('win-visibility-changed', onWindowVisibilityChanged);
document.removeEventListener('keydown', onKeyDown);
document.removeEventListener('fullscreenchange', onFullscreenChange);
};