Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top / bottom setting for individual subtitles #508

Merged
merged 16 commits into from
Oct 18, 2024

Conversation

artjomsR
Copy link
Contributor

@artjomsR artjomsR commented Sep 2, 2024

Mostly working for the extension and still needs cleaning up, but I wanted to ask first: is there any penalty for always having 2 subtitle containers (one at top and one at bottom), even if one of them is not used? E.g., all subtitles are displayed at the bottom?

@artjomsR artjomsR marked this pull request as draft September 2, 2024 08:57
@artjomsR artjomsR force-pushed the feat/top_bottom_subtitles branch 7 times, most recently from 000e7b6 to c1635d8 Compare September 2, 2024 09:32
@killergerbah
Copy link
Owner

is there any penalty for always having 2 subtitle containers (one at top and one at bottom), even if one of them is not used?

Sorry for the really late response on this. I probably clicked through this PR and then forgot to reply.
I don't think there should be a huge penalty. My guess is that the DOM cache will be the biggest drain on resources, but also probably not a big deal. But it would be good to avoid rendering the subtitles unnecessarily. E.g. if only top or only bottom then only render top or only render bottom.

@artjomsR artjomsR marked this pull request as ready for review September 22, 2024 19:25
@artjomsR
Copy link
Contributor Author

artjomsR commented Sep 22, 2024

no problem, thanks for getting back to me! I've updated the PR now, let me know what you think :)

I'm also thinking if we should remove the if checks from shouldRenderBottomOverlay (and remove it altogether), leaving only shouldRenderTopOverlay: boolean;: I think users would use either only bottom or bottom + top subtitles. But I don't see why someone would use only top subtitles

Copy link
Owner

@killergerbah killergerbah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As always thank you. It took me a while to get to this because of work and also trying to get 1.5.0 out first.

this._preCacheDom = preCacheDom;
}

cacheHtml() {
if (!(this.subtitlesElementOverlay instanceof CachingElementOverlay)) {
if (!(this.bottomSubtitlesElementOverlay instanceof CachingElementOverlay) || !(this.topSubtitlesElementOverlay instanceof CachingElementOverlay)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the check assumes that both overlays are always the same type, which may be true and enforced internally by this class.

But since it does not hurt, I think to be safe the instanceof check should be done independently for bottomSubtitlesElementOverlay and topSubtitlesElementOverlay before calling uncacheHtml.

@@ -154,6 +169,22 @@ export default class SubtitleController {
this.cacheHtml();
}

const newAlignments = allTextSubtitleSettings(newSubtitleSettings).map((s) => s.subtitleAlignment);
if (newAlignments !== this.subtitleTrackAlignments) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check will always return true because JavaScript will use object identity for comparison. This class already implements _arrayEquals, you can use that instead.


get subtitleAlignment() {
return this._subtitleAlignment;
getSubtitleTrackAlignment(trackIndex: number) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be private

@@ -451,7 +473,10 @@ export default class SubtitleController {
this.notificationElementOverlayHideTimeout = undefined;
}

this.subtitlesElementOverlay.dispose();
if (this.shouldRenderBottomOverlay)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skip the should* checks - just dispose both overlays.

@@ -149,7 +150,8 @@ const subtitleSettingsKeysObject: { [key in keyof SubtitleSettings]: boolean } =
subtitleCustomStyles: true,
subtitleBlur: true,
imageBasedSubtitleScaleFactor: true,
subtitlePositionOffset: true,
bottomSubtitlePositionOffset: true,
Copy link
Owner

@killergerbah killergerbah Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use subtitlePositionOffset instead of bottomSubtitlePositionOffset and add a comment saying it's the bottom offset. The naming is less clear but without a system to migrate the settings structure it's safer to preserve older names, since the extension and app share settings.

@artjomsR artjomsR force-pushed the feat/top_bottom_subtitles branch from ec0df42 to eaef90b Compare October 8, 2024 13:23
@artjomsR
Copy link
Contributor Author

artjomsR commented Oct 8, 2024

No problem for the delay, there's no rush :)

I've updated the PR, should've addressed all your comments. You didn't address my previous comment, not sure if you have an opinion about this?

I'm also thinking if we should remove the if checks from shouldRenderBottomOverlay (and remove it altogether), leaving only shouldRenderTopOverlay: boolean;: I think users would use either only bottom or bottom + top subtitles. But I don't see why someone would use only top subtitles

@artjomsR artjomsR requested a review from killergerbah October 8, 2024 13:25
@artjomsR artjomsR force-pushed the feat/top_bottom_subtitles branch from eaef90b to 3b213c7 Compare October 8, 2024 14:59
@killergerbah
Copy link
Owner

No problem for the delay, there's no rush :)

I've updated the PR, should've addressed all your comments. You didn't address my previous comment, not sure if you have an opinion about this?

I'm also thinking if we should remove the if checks from shouldRenderBottomOverlay (and remove it altogether), leaving only shouldRenderTopOverlay: boolean;: I think users would use either only bottom or bottom + top subtitles. But I don't see why someone would use only top subtitles

Sorry forgot to reply to that as well. There are two reasons why I think we should leave it as is:

  • It's not obvious to me how we would work that into the current settings UI. For example you would have to prevent users from switching all tracks to the top. It would seem then the track specific settings would have to be aware of each other which might introduce complexity.
  • There are users who use top only. For example to add second language subtitles to websites that already have their own subtitles.

@artjomsR
Copy link
Contributor Author

artjomsR commented Oct 9, 2024

I meant to keep the functionality as is, simply skip the if shouldRenderBottomOverlay check and always invoke all functionality related to the bottom overlay. Once again, based on the principle that most people would use the bottom container.

But as you say, if considerable number of users use top only, then we can leave everything as is :)

Copy link
Owner

@killergerbah killergerbah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you removed the subtitleAlignment setting. If you're not using that setting, how are you intending for users to be able to pick the alignment for individual tracks?

Copy link
Owner

@killergerbah killergerbah Oct 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file should be part of a different PR.

@artjomsR
Copy link
Contributor Author

artjomsR commented Oct 12, 2024

It looks like you removed the subtitleAlignment setting. If you're not using that setting, how are you intending for users to be able to pick the alignment for individual tracks?

in common/settings/settings.ts, I've moved it from SubtitleSettings (which I understood as "global" settings) to TextSubtitleSettings (which I understood as settings which apply to individual tracks), which is effectively all this PR is about

Replay_2024-10-12_10-26-57.mp4

@killergerbah
Copy link
Owner

Understood!

@@ -160,6 +172,27 @@ export default class SubtitleController {
this.cacheHtml();
}

const newAlignments = allTextSubtitleSettings(newSubtitleSettings).map((s) => s.subtitleAlignment);
Copy link
Owner

@killergerbah killergerbah Oct 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a bug that I believe has to do with this line. See the video below. You'll notice that there are two tracks, but when switching all tracks, or track 0, to the 'top' alignment, one of the tracks disappears.

2024-10-13.6.05.27.mov

Despite the name,allTextSubtitleSettings doesn't return the TextSubtitleSettings for a specific number of tracks, it only returns settings for the ones that are actually configured.

This means that we need to account for TextSubtitleSettings missing for some tracks. You'll notice that SubtitleController._subtitleStyles does this by assuming any missing track-specific settings should just inherit the settings for track 0. Unfortunately this means that calculating shouldRenderBottomOverlay and shouldRenderTopOverlay will always depend on the _subtitles field and we would need to re-calculate those fields whenever _subtitles changes.

So for now I suggest the following:

  1. Remove shouldRenderBottomOverlay and shouldRenderTopOverlay fields. Always cache HTML for both overlays.
  2. (Optional) Refactor CachingElementOverlay so that topSubtitlesElementOverlay and bottomSubtitlesElementOverlay can share the same DOM cache. This will cancel out the overhead of always having two overlays.

get subtitleAlignment() {
return this._subtitleAlignment;
private _getSubtitleTrackAlignment(trackIndex: number) {
return this.subtitleTrackAlignments[trackIndex] || 'bottom';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above the default value should really be the setting for the 0th track:

this.subtitleTrackAlignments[trackIndex] || this.subtitleTrackAlignments[0]

@artjomsR
Copy link
Contributor Author

I've added your suggested change of || this.subtitleTrackAlignments[0] which seems to have fixed the bug for me, I've tested several times. So I'm not sure if the caching changes are still required now

@killergerbah
Copy link
Owner

Sorry, yeah you're right. Thanks again for your patience.

@killergerbah killergerbah merged commit b39cef5 into killergerbah:main Oct 18, 2024
1 check passed
@killergerbah killergerbah added this to the Extension v1.6.0 milestone Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants