mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-03 23:14:13 +00:00 
			
		
		
		
	refactor(frontend): 動画UIのフルスクリーン周りの調整 (#14877)
* refactor(frontend): フルスクリーン周りの調整 (cherry picked from commit 783032caec5853d78d5af3391e29cf364f2282e8) * refactor(frontend): deviceKindの循環参照を除去 (cherry picked from commit 1ca471f57e968a1a6e2259bde4a7c6da1fe0c54e) * fix --------- Co-authored-by: taiyme <53635909+taiyme@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									a4c5ce1413
								
							
						
					
					
						commit
						3a421837bf
					
				
					 5 changed files with 88 additions and 40 deletions
				
			
		| 
						 | 
					@ -15,7 +15,7 @@ import { updateI18n, i18n } from '@/i18n.js';
 | 
				
			||||||
import { $i, refreshAccount, login } from '@/account.js';
 | 
					import { $i, refreshAccount, login } from '@/account.js';
 | 
				
			||||||
import { defaultStore, ColdDeviceStorage } from '@/store.js';
 | 
					import { defaultStore, ColdDeviceStorage } from '@/store.js';
 | 
				
			||||||
import { fetchInstance, instance } from '@/instance.js';
 | 
					import { fetchInstance, instance } from '@/instance.js';
 | 
				
			||||||
import { deviceKind } from '@/scripts/device-kind.js';
 | 
					import { deviceKind, updateDeviceKind } from '@/scripts/device-kind.js';
 | 
				
			||||||
import { reloadChannel } from '@/scripts/unison-reload.js';
 | 
					import { reloadChannel } from '@/scripts/unison-reload.js';
 | 
				
			||||||
import { getUrlWithoutLoginId } from '@/scripts/login-id.js';
 | 
					import { getUrlWithoutLoginId } from '@/scripts/login-id.js';
 | 
				
			||||||
import { getAccountFromId } from '@/scripts/get-account-from-id.js';
 | 
					import { getAccountFromId } from '@/scripts/get-account-from-id.js';
 | 
				
			||||||
| 
						 | 
					@ -185,6 +185,10 @@ export async function common(createVue: () => App<Element>) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						watch(defaultStore.reactiveState.overridedDeviceKind, (kind) => {
 | 
				
			||||||
 | 
							updateDeviceKind(kind);
 | 
				
			||||||
 | 
						}, { immediate: true });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	watch(defaultStore.reactiveState.useBlurEffectForModal, v => {
 | 
						watch(defaultStore.reactiveState.useBlurEffectForModal, v => {
 | 
				
			||||||
		document.documentElement.style.setProperty('--MI-modalBgFilter', v ? 'blur(4px)' : 'none');
 | 
							document.documentElement.style.setProperty('--MI-modalBgFilter', v ? 'blur(4px)' : 'none');
 | 
				
			||||||
	}, { immediate: true });
 | 
						}, { immediate: true });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -118,7 +118,7 @@ import { hms } from '@/filters/hms.js';
 | 
				
			||||||
import { defaultStore } from '@/store.js';
 | 
					import { defaultStore } from '@/store.js';
 | 
				
			||||||
import { i18n } from '@/i18n.js';
 | 
					import { i18n } from '@/i18n.js';
 | 
				
			||||||
import * as os from '@/os.js';
 | 
					import * as os from '@/os.js';
 | 
				
			||||||
import { isFullscreenNotSupported } from '@/scripts/device-kind.js';
 | 
					import { exitFullscreen, requestFullscreen } from '@/scripts/fullscreen.js';
 | 
				
			||||||
import hasAudio from '@/scripts/media-has-audio.js';
 | 
					import hasAudio from '@/scripts/media-has-audio.js';
 | 
				
			||||||
import MkMediaRange from '@/components/MkMediaRange.vue';
 | 
					import MkMediaRange from '@/components/MkMediaRange.vue';
 | 
				
			||||||
import { $i, iAmModerator } from '@/account.js';
 | 
					import { $i, iAmModerator } from '@/account.js';
 | 
				
			||||||
| 
						 | 
					@ -334,26 +334,21 @@ function togglePlayPause() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function toggleFullscreen() {
 | 
					function toggleFullscreen() {
 | 
				
			||||||
	if (isFullscreenNotSupported && videoEl.value) {
 | 
						if (playerEl.value == null || videoEl.value == null) return;
 | 
				
			||||||
		if (isFullscreen.value) {
 | 
						if (isFullscreen.value) {
 | 
				
			||||||
			// eslint-disable-next-line @typescript-eslint/ban-ts-comment
 | 
							exitFullscreen({
 | 
				
			||||||
			//@ts-ignore
 | 
								videoEl: videoEl.value,
 | 
				
			||||||
			videoEl.value.webkitExitFullscreen();
 | 
							});
 | 
				
			||||||
			isFullscreen.value = false;
 | 
							isFullscreen.value = false;
 | 
				
			||||||
		} else {
 | 
						} else {
 | 
				
			||||||
			// eslint-disable-next-line @typescript-eslint/ban-ts-comment
 | 
							requestFullscreen({
 | 
				
			||||||
			//@ts-ignore
 | 
								videoEl: videoEl.value,
 | 
				
			||||||
			videoEl.value.webkitEnterFullscreen();
 | 
								playerEl: playerEl.value,
 | 
				
			||||||
			isFullscreen.value = true;
 | 
								options: {
 | 
				
			||||||
		}
 | 
									navigationUI: 'hide',
 | 
				
			||||||
	} else if (playerEl.value) {
 | 
								},
 | 
				
			||||||
		if (isFullscreen.value) {
 | 
							});
 | 
				
			||||||
			document.exitFullscreen();
 | 
							isFullscreen.value = true;
 | 
				
			||||||
			isFullscreen.value = false;
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			playerEl.value.requestFullscreen({ navigationUI: 'hide' });
 | 
					 | 
				
			||||||
			isFullscreen.value = true;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -454,8 +449,10 @@ watch(loop, (to) => {
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
watch(hide, (to) => {
 | 
					watch(hide, (to) => {
 | 
				
			||||||
	if (to && isFullscreen.value) {
 | 
						if (videoEl.value && to && isFullscreen.value) {
 | 
				
			||||||
		document.exitFullscreen();
 | 
							exitFullscreen({
 | 
				
			||||||
 | 
								videoEl: videoEl.value,
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
		isFullscreen.value = false;
 | 
							isFullscreen.value = false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,22 +3,22 @@
 | 
				
			||||||
 * SPDX-License-Identifier: AGPL-3.0-only
 | 
					 * SPDX-License-Identifier: AGPL-3.0-only
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { defaultStore } from '@/store.js';
 | 
					export type DeviceKind = 'smartphone' | 'tablet' | 'desktop';
 | 
				
			||||||
 | 
					 | 
				
			||||||
await defaultStore.ready;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
const ua = navigator.userAgent.toLowerCase();
 | 
					const ua = navigator.userAgent.toLowerCase();
 | 
				
			||||||
const isTablet = /ipad/.test(ua) || (/mobile|iphone|android/.test(ua) && window.innerWidth > 700);
 | 
					const isTablet = /ipad/.test(ua) || (/mobile|iphone|android/.test(ua) && window.innerWidth > 700);
 | 
				
			||||||
const isSmartphone = !isTablet && /mobile|iphone|android/.test(ua);
 | 
					const isSmartphone = !isTablet && /mobile|iphone|android/.test(ua);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const isIPhone = /iphone|ipod/gi.test(ua) && navigator.maxTouchPoints > 1;
 | 
					export const DEFAULT_DEVICE_KIND: DeviceKind = (
 | 
				
			||||||
// navigator.platform may be deprecated but this check is still required
 | 
						isSmartphone
 | 
				
			||||||
const isIPadOS = navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
 | 
							? 'smartphone'
 | 
				
			||||||
const isIos = /ipad|iphone|ipod/gi.test(ua) && navigator.maxTouchPoints > 1;
 | 
							: isTablet
 | 
				
			||||||
 | 
								? 'tablet'
 | 
				
			||||||
 | 
								: 'desktop'
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const isFullscreenNotSupported = isIPhone || isIos;
 | 
					export let deviceKind: DeviceKind = DEFAULT_DEVICE_KIND;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const deviceKind: 'smartphone' | 'tablet' | 'desktop' = defaultStore.state.overridedDeviceKind ? defaultStore.state.overridedDeviceKind
 | 
					export function updateDeviceKind(kind: DeviceKind | null) {
 | 
				
			||||||
	: isSmartphone ? 'smartphone'
 | 
						deviceKind = kind ?? DEFAULT_DEVICE_KIND;
 | 
				
			||||||
	: isTablet ? 'tablet'
 | 
					}
 | 
				
			||||||
	: 'desktop';
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										46
									
								
								packages/frontend/src/scripts/fullscreen.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								packages/frontend/src/scripts/fullscreen.ts
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,46 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * SPDX-FileCopyrightText: syuilo and misskey-project
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: AGPL-3.0-only
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PartiallyPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type VideoEl = PartiallyPartial<HTMLVideoElement, 'requestFullscreen'> & {
 | 
				
			||||||
 | 
						webkitEnterFullscreen?(): void;
 | 
				
			||||||
 | 
						webkitExitFullscreen?(): void;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PlayerEl = PartiallyPartial<HTMLElement, 'requestFullscreen'>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type RequestFullscreenProps = {
 | 
				
			||||||
 | 
						readonly videoEl: VideoEl;
 | 
				
			||||||
 | 
						readonly playerEl: PlayerEl;
 | 
				
			||||||
 | 
						readonly options?: FullscreenOptions | null;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ExitFullscreenProps = {
 | 
				
			||||||
 | 
						readonly videoEl: VideoEl;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const requestFullscreen = ({ videoEl, playerEl, options }: RequestFullscreenProps) => {
 | 
				
			||||||
 | 
						if (playerEl.requestFullscreen != null) {
 | 
				
			||||||
 | 
							playerEl.requestFullscreen(options ?? undefined);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (videoEl.webkitEnterFullscreen != null) {
 | 
				
			||||||
 | 
							videoEl.webkitEnterFullscreen();
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const exitFullscreen = ({ videoEl }: ExitFullscreenProps) => {
 | 
				
			||||||
 | 
						// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
 | 
				
			||||||
 | 
						if (document.exitFullscreen != null) {
 | 
				
			||||||
 | 
							document.exitFullscreen();
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (videoEl.webkitExitFullscreen != null) {
 | 
				
			||||||
 | 
							videoEl.webkitExitFullscreen();
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -8,8 +8,9 @@ import * as Misskey from 'misskey-js';
 | 
				
			||||||
import { hemisphere } from '@@/js/intl-const.js';
 | 
					import { hemisphere } from '@@/js/intl-const.js';
 | 
				
			||||||
import lightTheme from '@@/themes/l-light.json5';
 | 
					import lightTheme from '@@/themes/l-light.json5';
 | 
				
			||||||
import darkTheme from '@@/themes/d-green-lime.json5';
 | 
					import darkTheme from '@@/themes/d-green-lime.json5';
 | 
				
			||||||
import { miLocalStorage } from './local-storage.js';
 | 
					 | 
				
			||||||
import type { SoundType } from '@/scripts/sound.js';
 | 
					import type { SoundType } from '@/scripts/sound.js';
 | 
				
			||||||
 | 
					import { DEFAULT_DEVICE_KIND, type DeviceKind } from '@/scripts/device-kind.js';
 | 
				
			||||||
 | 
					import { miLocalStorage } from '@/local-storage.js';
 | 
				
			||||||
import { Storage } from '@/pizzax.js';
 | 
					import { Storage } from '@/pizzax.js';
 | 
				
			||||||
import type { Ast } from '@syuilo/aiscript';
 | 
					import type { Ast } from '@syuilo/aiscript';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -207,7 +208,7 @@ export const defaultStore = markRaw(new Storage('base', {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	overridedDeviceKind: {
 | 
						overridedDeviceKind: {
 | 
				
			||||||
		where: 'device',
 | 
							where: 'device',
 | 
				
			||||||
		default: null as null | 'smartphone' | 'tablet' | 'desktop',
 | 
							default: null as DeviceKind | null,
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	serverDisconnectedBehavior: {
 | 
						serverDisconnectedBehavior: {
 | 
				
			||||||
		where: 'device',
 | 
							where: 'device',
 | 
				
			||||||
| 
						 | 
					@ -263,11 +264,11 @@ export const defaultStore = markRaw(new Storage('base', {
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	useBlurEffectForModal: {
 | 
						useBlurEffectForModal: {
 | 
				
			||||||
		where: 'device',
 | 
							where: 'device',
 | 
				
			||||||
		default: !/mobile|iphone|android/.test(navigator.userAgent.toLowerCase()), // 循環参照するのでdevice-kind.tsは参照できない
 | 
							default: DEFAULT_DEVICE_KIND === 'desktop',
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	useBlurEffect: {
 | 
						useBlurEffect: {
 | 
				
			||||||
		where: 'device',
 | 
							where: 'device',
 | 
				
			||||||
		default: !/mobile|iphone|android/.test(navigator.userAgent.toLowerCase()), // 循環参照するのでdevice-kind.tsは参照できない
 | 
							default: DEFAULT_DEVICE_KIND === 'desktop',
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	showFixedPostForm: {
 | 
						showFixedPostForm: {
 | 
				
			||||||
		where: 'device',
 | 
							where: 'device',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue