Skip to content

Commit 783032c

Browse files
committed
refactor(frontend): フルスクリーン周りの調整
1 parent a93b6c3 commit 783032c

File tree

3 files changed

+66
-30
lines changed

3 files changed

+66
-30
lines changed

packages/frontend/src/components/MkMediaVideo.vue

+20-23
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ import type { MenuItem } from '@/types/menu.js';
158158
import { i18n } from '@/i18n.js';
159159
import { confirm, popupMenu } from '@/os.js';
160160
import { defaultStore } from '@/store.js';
161-
import { isFullscreenNotSupported } from '@/scripts/device-kind.js';
162161
import { type Keymap } from '@/scripts/hotkey.js';
163162
import hasAudio from '@/scripts/media-has-audio.js';
163+
import { exitFullscreen, requestFullscreen } from '@/scripts/tms/fullscreen.js';
164164
import { getMediaMenu } from '@/scripts/tms/get-media-menu.js';
165165
import { useReactiveDriveFile } from '@/scripts/tms/use-reactive-drive-file.js';
166166
import bytes from '@/filters/bytes.js';
@@ -359,26 +359,21 @@ function togglePlayPause() {
359359
}
360360

361361
function toggleFullscreen() {
362-
if (isFullscreenNotSupported && videoEl.value) {
363-
if (isFullscreen.value) {
364-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
365-
//@ts-ignore
366-
videoEl.value.webkitExitFullscreen();
367-
isFullscreen.value = false;
368-
} else {
369-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
370-
//@ts-ignore
371-
videoEl.value.webkitEnterFullscreen();
372-
isFullscreen.value = true;
373-
}
374-
} else if (playerEl.value) {
375-
if (isFullscreen.value) {
376-
document.exitFullscreen();
377-
isFullscreen.value = false;
378-
} else {
379-
playerEl.value.requestFullscreen({ navigationUI: 'hide' });
380-
isFullscreen.value = true;
381-
}
362+
if (playerEl.value == null || videoEl.value == null) return;
363+
if (isFullscreen.value) {
364+
exitFullscreen({
365+
videoEl: videoEl.value,
366+
});
367+
isFullscreen.value = false;
368+
} else {
369+
requestFullscreen({
370+
videoEl: videoEl.value,
371+
playerEl: playerEl.value,
372+
options: {
373+
navigationUI: 'hide',
374+
},
375+
});
376+
isFullscreen.value = true;
382377
}
383378
}
384379

@@ -479,8 +474,10 @@ watch(loop, (to) => {
479474
});
480475

481476
watch(hideRef, (to) => {
482-
if (to && isFullscreen.value) {
483-
document.exitFullscreen();
477+
if (videoEl.value && to && isFullscreen.value) {
478+
exitFullscreen({
479+
videoEl: videoEl.value,
480+
});
484481
isFullscreen.value = false;
485482
}
486483
});

packages/frontend/src/scripts/device-kind.ts

-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ const ua = navigator.userAgent.toLowerCase();
1111
const isTablet = /ipad/.test(ua) || (/mobile|iphone|android/.test(ua) && window.innerWidth > 700);
1212
const isSmartphone = !isTablet && /mobile|iphone|android/.test(ua);
1313

14-
const isIPhone = /iphone|ipod/gi.test(ua) && navigator.maxTouchPoints > 1;
15-
// navigator.platform may be deprecated but this check is still required
16-
const isIPadOS = navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
17-
const isIos = /ipad|iphone|ipod/gi.test(ua) && navigator.maxTouchPoints > 1;
18-
19-
export const isFullscreenNotSupported = isIPhone || isIos;
20-
2114
export const deviceKind: 'smartphone' | 'tablet' | 'desktop' = defaultStore.state.overridedDeviceKind ? defaultStore.state.overridedDeviceKind
2215
: isSmartphone ? 'smartphone'
2316
: isTablet ? 'tablet'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* SPDX-FileCopyrightText: syuilo and misskey-project
3+
* SPDX-License-Identifier: AGPL-3.0-only
4+
*/
5+
6+
type PartiallyPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
7+
8+
type VideoEl = PartiallyPartial<HTMLVideoElement, 'requestFullscreen'> & {
9+
webkitEnterFullscreen?(): void;
10+
webkitExitFullscreen?(): void;
11+
};
12+
13+
type PlayerEl = PartiallyPartial<HTMLElement, 'requestFullscreen'>;
14+
15+
type RequestFullscreenProps = {
16+
readonly videoEl: VideoEl;
17+
readonly playerEl: PlayerEl;
18+
readonly options?: FullscreenOptions | null;
19+
};
20+
21+
type ExitFullscreenProps = {
22+
readonly videoEl: VideoEl;
23+
};
24+
25+
export const requestFullscreen = ({ videoEl, playerEl, options }: RequestFullscreenProps) => {
26+
if (playerEl.requestFullscreen != null) {
27+
playerEl.requestFullscreen(options ?? undefined);
28+
return;
29+
}
30+
if (videoEl.webkitEnterFullscreen != null) {
31+
videoEl.webkitEnterFullscreen();
32+
return;
33+
}
34+
};
35+
36+
export const exitFullscreen = ({ videoEl }: ExitFullscreenProps) => {
37+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
38+
if (document.exitFullscreen != null) {
39+
document.exitFullscreen();
40+
return;
41+
}
42+
if (videoEl.webkitExitFullscreen != null) {
43+
videoEl.webkitExitFullscreen();
44+
return;
45+
}
46+
};

0 commit comments

Comments
 (0)