diff options
author | MCMXC <16797721+mcmxcdev@users.noreply.github.com> | 2023-07-26 08:48:19 -0600 |
---|---|---|
committer | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2023-07-26 16:26:21 +0000 |
commit | 6ea99fc3c567fa184b2fe3dd6bcd2301d9529147 (patch) | |
tree | e2c8a94c903b7693321207f002d24c1031644ce9 /src | |
parent | 6.4.1-nightly.12 [skip ci] (diff) | |
download | ferdium-app-6ea99fc3c567fa184b2fe3dd6bcd2301d9529147.tar.gz ferdium-app-6ea99fc3c567fa184b2fe3dd6bcd2301d9529147.tar.zst ferdium-app-6ea99fc3c567fa184b2fe3dd6bcd2301d9529147.zip |
feat: picture in picture availability for video players
- add buildMenuForVideo method in contextMenuBuilder.ts
- add picture in picture context menu entry which toggles picture in picture mode
Diffstat (limited to 'src')
-rw-r--r-- | src/webview/contextMenuBuilder.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/webview/contextMenuBuilder.ts b/src/webview/contextMenuBuilder.ts index d18bc56f9..0d8b659f0 100644 --- a/src/webview/contextMenuBuilder.ts +++ b/src/webview/contextMenuBuilder.ts | |||
@@ -249,6 +249,10 @@ export class ContextMenuBuilder { | |||
249 | return this.buildMenuForImage(info); | 249 | return this.buildMenuForImage(info); |
250 | } | 250 | } |
251 | 251 | ||
252 | if (info.mediaType === 'video') { | ||
253 | return this.buildMenuForVideo(info); | ||
254 | } | ||
255 | |||
252 | if ( | 256 | if ( |
253 | info.isEditable || | 257 | info.isEditable || |
254 | (info.inputFieldType && info.inputFieldType !== 'none') | 258 | (info.inputFieldType && info.inputFieldType !== 'none') |
@@ -407,6 +411,40 @@ export class ContextMenuBuilder { | |||
407 | } | 411 | } |
408 | 412 | ||
409 | /** | 413 | /** |
414 | * Builds a menu applicable to a video. | ||
415 | * | ||
416 | * @return {Menu} The `Menu` | ||
417 | */ | ||
418 | buildMenuForVideo( | ||
419 | menuInfo: IContextMenuParams, | ||
420 | ): Electron.CrossProcessExports.Menu { | ||
421 | const menu = new Menu(); | ||
422 | const video = document.querySelectorAll('video')[0]; | ||
423 | |||
424 | if ( | ||
425 | document.pictureInPictureEnabled && | ||
426 | !video.disablePictureInPicture && | ||
427 | this.isSrcUrlValid(menuInfo) | ||
428 | ) { | ||
429 | menu.append( | ||
430 | new MenuItem({ | ||
431 | type: 'checkbox', | ||
432 | label: 'Picture in picture', | ||
433 | enabled: true, | ||
434 | checked: !!document.pictureInPictureElement, | ||
435 | click: async () => { | ||
436 | await (document.pictureInPictureElement | ||
437 | ? document.exitPictureInPicture() | ||
438 | : video.requestPictureInPicture()); | ||
439 | }, | ||
440 | }), | ||
441 | ); | ||
442 | } | ||
443 | |||
444 | return menu; | ||
445 | } | ||
446 | |||
447 | /** | ||
410 | * Checks if the current text selection contains a single misspelled word and | 448 | * Checks if the current text selection contains a single misspelled word and |
411 | * if so, adds suggested spellings as individual menu items. | 449 | * if so, adds suggested spellings as individual menu items. |
412 | */ | 450 | */ |