-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migrate fullscreen store and related functions/listeners to comp…
…osable Signed-off-by: Maksim Sukharev <[email protected]>
- Loading branch information
Showing
8 changed files
with
94 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { createSharedComposable } from '@vueuse/core' | ||
import { readonly, ref, onBeforeMount, onBeforeUnmount } from 'vue' | ||
import type { Ref, DeepReadonly } from 'vue' | ||
|
||
interface WebkitElement extends Element { | ||
ALLOW_KEYBOARD_INPUT: FullscreenOptions; | ||
} | ||
|
||
/** | ||
* Composable to check whether the page is displayed at fullscreen | ||
* @return {DeepReadonly<Ref<boolean>>} - computed boolean whether the page is displayed at fullscreen | ||
*/ | ||
function useDocumentFullscreenComposable() { | ||
const isFullscreen = ref<boolean>(document.fullscreenElement !== null) | ||
|
||
const changeIsFullscreen = () => { | ||
isFullscreen.value = document.fullscreenElement !== null | ||
} | ||
|
||
document.addEventListener('fullscreenchange', changeIsFullscreen) | ||
document.addEventListener('webkitfullscreenchange', changeIsFullscreen) | ||
|
||
onBeforeUnmount(() => { | ||
document.removeEventListener('fullscreenchange', changeIsFullscreen) | ||
document.removeEventListener('webkitfullscreenchange', changeIsFullscreen) | ||
}) | ||
|
||
return readonly(isFullscreen) | ||
} | ||
|
||
/** | ||
* Enable a fullscreen with Fullscreen API | ||
*/ | ||
export async function enableFullscreen() { | ||
const element = document.getElementById('content-vue') | ||
if (!element) { | ||
return | ||
} | ||
|
||
if (element.requestFullscreen) { | ||
await element.requestFullscreen() | ||
} else if (element.webkitRequestFullscreen) { | ||
await element.webkitRequestFullscreen((Element as unknown as WebkitElement).ALLOW_KEYBOARD_INPUT) | ||
} | ||
} | ||
|
||
/** | ||
* Disable a fullscreen | ||
*/ | ||
export async function disableFullscreen() { | ||
if (document.exitFullscreen) { | ||
await document.exitFullscreen() | ||
} else if (document.webkitExitFullscreen) { | ||
await document.webkitExitFullscreen() | ||
} | ||
} | ||
|
||
/** | ||
* Shared composable to check whether the page is displayed at fullscreen | ||
* @return {DeepReadonly<Ref<boolean>>} - computed boolean whether the page is displayed at fullscreen | ||
*/ | ||
export const useDocumentFullscreen = createSharedComposable(useDocumentFullscreenComposable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.