From b794aa7082de9f8c07eb5f13772ead2cff5f09b6 Mon Sep 17 00:00:00 2001 From: Jason Henriquez Date: Sun, 20 Oct 2024 02:31:31 -0500 Subject: [PATCH] Restore fullscreen and PiP during autoplay --- src/constants.js | 3 ++ src/main/index.js | 9 +++++ .../ft-shaka-video-player.js | 34 ++++++++++++++++++- .../ft-shaka-video-player.vue | 1 + src/renderer/views/Watch/Watch.js | 6 +++- src/renderer/views/Watch/Watch.vue | 4 +-- 6 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/constants.js b/src/constants.js index f45e30fb8211d..38e1e7a1e4c64 100644 --- a/src/constants.js +++ b/src/constants.js @@ -15,6 +15,9 @@ const IpcChannels = { APP_READY: 'app-ready', RELAUNCH_REQUEST: 'relaunch-request', + REQUEST_FULLSCREEN: 'request-fullscreen', + REQUEST_PIP: 'request_pip', + SEARCH_INPUT_HANDLING_READY: 'search-input-handling-ready', UPDATE_SEARCH_INPUT_TEXT: 'update-search-input-text', diff --git a/src/main/index.js b/src/main/index.js index 10ca46343829e..64cf3ab7cf126 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -927,6 +927,15 @@ function runApp() { return app.getPath('pictures') }) + ipcMain.on(IpcChannels.REQUEST_FULLSCREEN, ({ sender }) => { + sender.executeJavaScript('document.getElementById("video").requestFullscreen({navigationUI: "hide"})', true) + }) + + ipcMain.on(IpcChannels.REQUEST_PIP, ({ sender }) => { + sender.executeJavaScript('document.getElementById("video").requestPictureInPicture()', true) + }) + + ipcMain.handle(IpcChannels.SHOW_OPEN_DIALOG, async ({ sender }, options) => { const senderWindow = findSenderWindow(sender) if (senderWindow) { diff --git a/src/renderer/components/ft-shaka-video-player/ft-shaka-video-player.js b/src/renderer/components/ft-shaka-video-player/ft-shaka-video-player.js index 9424026eef4cb..4301c69dd5b04 100644 --- a/src/renderer/components/ft-shaka-video-player/ft-shaka-video-player.js +++ b/src/renderer/components/ft-shaka-video-player/ft-shaka-video-player.js @@ -107,9 +107,17 @@ export default defineComponent({ type: String, default: null }, + startInFullscreen: { + type: Boolean, + default: false + }, startInFullwindow: { type: Boolean, default: false + }, + startInPip: { + type: Boolean, + default: false } }, emits: [ @@ -1046,7 +1054,8 @@ export default defineComponent({ navigator.mediaSession.playbackState = 'none' } - emit('ended', fullWindowEnabled.value) + const controls = ui.getControls() + emit('ended', controls.isFullScreenEnabled(), fullWindowEnabled.value, controls.isPiPEnabled()) } function updateVolume() { @@ -2543,6 +2552,29 @@ export default defineComponent({ if (props.chapters.length > 0) { createChapterMarkers() } + + setDefaultFullscreenOrPiP() + } + + function setDefaultFullscreenOrPiP() { + const controls = ui.getControls() + if (props.startInFullscreen && process.env.IS_ELECTRON) { + const { ipcRenderer } = require('electron') + ipcRenderer.send(IpcChannels.REQUEST_FULLSCREEN) + } + + if (props.startInPip && controls.isPiPAllowed() && process.env.IS_ELECTRON) { + const { ipcRenderer } = require('electron') + + // TODO: determine if any appropriate promise can be waited on instead of this + const interval = setInterval(() => { + if (controls.isPiPEnabled()) { + clearInterval(interval) + } else { + ipcRenderer.send(IpcChannels.REQUEST_PIP) + } + }, 100) + } } watch( diff --git a/src/renderer/components/ft-shaka-video-player/ft-shaka-video-player.vue b/src/renderer/components/ft-shaka-video-player/ft-shaka-video-player.vue index 4b9519c772718..038abf54aded6 100644 --- a/src/renderer/components/ft-shaka-video-player/ft-shaka-video-player.vue +++ b/src/renderer/components/ft-shaka-video-player/ft-shaka-video-player.vue @@ -9,6 +9,7 @@ >