-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Top / bottom setting for individual subtitles #508
Conversation
000e7b6
to
c1635d8
Compare
Sorry for the really late response on this. I probably clicked through this PR and then forgot to reply. |
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 |
There was a problem hiding this 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)) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
common/settings/settings.ts
Outdated
@@ -149,7 +150,8 @@ const subtitleSettingsKeysObject: { [key in keyof SubtitleSettings]: boolean } = | |||
subtitleCustomStyles: true, | |||
subtitleBlur: true, | |||
imageBasedSubtitleScaleFactor: true, | |||
subtitlePositionOffset: true, | |||
bottomSubtitlePositionOffset: true, |
There was a problem hiding this comment.
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.
ec0df42
to
eaef90b
Compare
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?
|
eaef90b
to
3b213c7
Compare
Sorry forgot to reply to that as well. There are two reasons why I think we should leave it as is:
|
I meant to keep the functionality as is, simply skip the But as you say, if considerable number of users use top only, then we can leave everything as is :) |
There was a problem hiding this 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?
There was a problem hiding this comment.
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.
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 |
Understood! |
@@ -160,6 +172,27 @@ export default class SubtitleController { | |||
this.cacheHtml(); | |||
} | |||
|
|||
const newAlignments = allTextSubtitleSettings(newSubtitleSettings).map((s) => s.subtitleAlignment); |
There was a problem hiding this comment.
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:
- Remove
shouldRenderBottomOverlay
andshouldRenderTopOverlay
fields. Always cache HTML for both overlays. - (Optional) Refactor
CachingElementOverlay
so thattopSubtitlesElementOverlay
andbottomSubtitlesElementOverlay
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'; |
There was a problem hiding this comment.
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]
I've added your suggested change of |
Sorry, yeah you're right. Thanks again for your patience. |
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?