TagSpaces is an offline, open source, document manager with tagging support
fix fullscreen on safari browsers (#1539)
Stanimir80ccad56ac96
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsxindex 18fc445eb..d1d1e73e9 100644--- a/app/components/EntryContainer.tsx+++ b/app/components/EntryContainer.tsx@@ -26,6 +26,7 @@ import React, {import { connect } from 'react-redux';import { bindActionCreators } from 'redux';import { GlobalHotKeys } from 'react-hotkeys';+import fscreen from 'fscreen';import Button from '@material-ui/core/Button';import Tooltip from '@material-ui/core/Tooltip';import IconButton from '@material-ui/core/IconButton';@@ -464,26 +465,31 @@ const EntryContainer = (props: Props) => {PlatformIO.shareFiles([filePath]);};- document.addEventListener('fullscreenchange', exitFullScreenHandler);+ fscreen.addEventListener('fullscreenchange', exitFullScreenHandler); // , options);+ /* document.addEventListener('fullscreenchange', exitFullScreenHandler);document.addEventListener('webkitfullscreenchange', exitFullScreenHandler);document.addEventListener('mozfullscreenchange', exitFullScreenHandler);- document.addEventListener('MSFullscreenChange', exitFullScreenHandler);+ document.addEventListener('MSFullscreenChange', exitFullScreenHandler); */function exitFullScreenHandler() {if (- !document.fullscreenElement &&+ fscreen.fullscreenElement === null+ /*! document.fullscreenElement &&// @ts-ignore!document.webkitIsFullScreen &&// @ts-ignore!document.mozFullScreen &&// @ts-ignore- !document.msFullscreenElement+ !document.msFullscreenElement */) {forceUpdate();}}const toggleFullScreen = () => {+ if (!fscreen.fullscreenEnabled) {+ return;+ }// this.fileViewerContainer.addEventListener('onfullscreenchange', () => {// alert('Fullscreen change');// if (this.state.isFullscreen) {@@ -495,9 +501,8 @@ const EntryContainer = (props: Props) => {// https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen#examples- if (document.fullscreenElement && document.exitFullscreen) {- // TODO exit fullscreen firefox does not work- document+ if (fscreen.fullscreenElement !== null) {+ fscreen.exitFullscreen().then(() => {console.log('Fullscreen exit successful');@@ -508,20 +513,29 @@ const EntryContainer = (props: Props) => {.catch(e => {console.log('Error exiting fullscreen', e);});- return;+ } else {+ fscreen+ .requestFullscreen(fileViewerContainer.current)+ .then(() => {+ forceUpdate();+ return true;+ })+ .catch(ex => {+ console.error('requestFullscreen:', ex);+ });}- if (document.fullscreenElement && document.webkitExitFullscreen) {+ /* if (document.fullscreenElement && document.webkitExitFullscreen) {document.webkitExitFullscreen();// setFullscreen(false);forceUpdate();return;- }+ } *//* else if (this.state.isFullscreen && document.mozExitFullscreen) {document.mozExitFullscreen();this.setState({ isFullscreen: false });return;} */- if (!document.fullscreenElement && fileViewerContainer) {+ /* if (!document.fullscreenElement && fileViewerContainer) {if (fileViewerContainer &&fileViewerContainer.current.requestFullscreen@@ -558,7 +572,7 @@ const EntryContainer = (props: Props) => {fileViewerContainer.current.mozRequestFullScreen();forceUpdate();}- }+ } */};const setPercent = (p: number | undefined) => {@@ -1062,6 +1076,7 @@ const EntryContainer = (props: Props) => {initSize = defaultSplitSize; // '0%';}+ const isFullscreen = () => fscreen.fullscreenElement !== null;return (<Splithorizontal@@ -1074,7 +1089,7 @@ const EntryContainer = (props: Props) => {<FileViewkey="FileViewID"openedFile={props.openedFiles[0]}- isFullscreen={document.fullscreenElement !== null}+ isFullscreen={isFullscreen()}fileViewer={fileViewer}fileViewerContainer={fileViewerContainer}toggleFullScreen={toggleFullScreen}diff --git a/package.json b/package.jsonindex d2f3f0c58..dbb7febf3 100644--- a/package.json+++ b/package.json@@ -171,6 +171,7 @@"exif-js": "^2.3.0","file-saver": "^2.0.5","fs-extra": "^10.0.0",+ "fscreen": "^1.2.0","fuse.js": "^6.4.6","geolocation-utils": "^1.2.3","html2canvas": "^1.0.0-alpha.12",diff --git a/yarn.lock b/yarn.lockindex cd204878a..bd6f419fc 100644--- a/yarn.lock+++ b/yarn.lock@@ -9449,6 +9449,11 @@ fs.realpath@^1.0.0:resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=+fscreen@^1.2.0:+ version "1.2.0"+ resolved "https://registry.yarnpkg.com/fscreen/-/fscreen-1.2.0.tgz#1a8c88e06bc16a07b473ad96196fb06d6657f59e"+ integrity sha512-hlq4+BU0hlPmwsFjwGGzZ+OZ9N/wq9Ljg/sq3pX+2CD7hrJsX9tJgWWK/wiNTFM212CLHWhicOoqwXyZGGetJg==+fsevents@^1.2.7:version "1.2.13"resolved "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz"