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

Blur shortcuts improvements #461

Merged

Conversation

artjomsR
Copy link
Contributor

@artjomsR artjomsR commented Jul 9, 2024

Implement #451

atm I've been only focusing on the extension. Current implementation works, but it's not immediate to unblur / reblur (on subtitle change). I suspect this is due to refreshing the caching, but I've not figured out a way to update it otherwise. So, not sure the current implementation can be improved

Happy if somebody else wants to update / pick this up, as I'm feeling a bit stuck with this as of now

(I've also realised that the renaming of the shortcut broke the untoggling, would need to investigate why. But the PR works as of the 1st commit 3df421e)

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.

I think you are close, but I would like to suggest a different overall approach.
As mentioned in the comments, your current approach is:

  1. On key-press change internal state.
  2. Check state in loop and recalculate classes as necessary.

I would suggest this instead:

  1. On key-press call classList.remove('asbplayer-subtitles-blurred') on the appropriate subtitle track. Record unblurredSubtitleTracks[track] = true only if the class was actually removed.
  2. In polling loop add back the class 'asbplayer-subtitles-blurred' for every marked track in unblurredSubtitleTracks in the if (subtitlesAreNew) block.
  3. Empty out unblurredSubtitleTracks in setSubtitleSettings.

This way you only modify the CSS classes at the moments when they need to be modified and avoid having to recalculate the classes over and over again in the polling loop.

In general, calculating the full state in a loop can be simpler and more bug free but in this case I think the performance implications merit the more event-based approach which isn't actually that much more complex.

@@ -103,7 +103,7 @@
"toggleAsbplayerSubtitleTrack2": "Untertitel 2 in asbplayer umschalten",
"toggleAsbplayerSubtitleTrack3": "Untertitel 3 in asbplayer umschalten",
"toggleAsbplayerSubtitleTracks": "Untertitel in absplayer umschalten",
"toggleAsbplayerBlurTrack": "Toggle subtitle track {{trackNumber}} blur in asbplayer",
Copy link
Owner

Choose a reason for hiding this comment

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

You should keep the old key toggleAsbplayerBlurTrack as well since the same loc file is used for all versions of the extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted the old key

@@ -310,21 +312,25 @@ export default class SubtitleController {
this.onNextToShow?.(slice.nextToShow[0]);
}

let shouldUnblur = false;
if (this.subtitleSettings) {
Copy link
Owner

Choose a reason for hiding this comment

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

This is relatively expensive code to be running ~10 times a second. I think there is a more performant approach.

src: context.video.src,
};
chrome.runtime.sendMessage(command);
context.subtitleController.unblurredSubtitleTracks[track] =
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of modifying the state of subtitleController I suggest implementing a function to trigger the CSS class changes since a function would give you the opportunity to run some code (vs changing internal state and polling for it in a loop).

@artjomsR artjomsR force-pushed the feat/blur_shortcuts_improvements branch from 62b00a7 to f232dc8 Compare July 19, 2024 09:51
@killergerbah
Copy link
Owner

I pushed what I described as the solution. I took it for granted that you could query the displaying subtitle elements and also know their track number. I think this is where the difficulty was.

@artjomsR
Copy link
Contributor Author

That's great, thank you so much for looking into it! From my point of view, it's functionally complete now, the only thing now that comes to my mind is the translation strings. I've tried to cherry-pick f232dc80 again, but unblurring still stops working with that commit added, so there's still something missing..

@killergerbah
Copy link
Owner

Thinking about it we should probably add completely new loc strings for this "unblur" behavior. Since it is significantly different from "toggle." But we will need to keep the old loc keys/values for older versions of the extension.

@artjomsR
Copy link
Contributor Author

artjomsR commented Aug 14, 2024

Do you mean having shortcuts for both toggle and unblur actions? I think Toggle Unblur is too similar to Hide/Show Subtitle Track shortcut (in terms of workflow), but then again nothing's preventing us from having both

@killergerbah
Copy link
Owner

Do you mean having shortcuts for both toggle and unblur actions? I think Toggle Unblur is too similar to Hide/Show Subtitle Track shortcut (in terms of workflow), but then again nothing's preventing us from having both

Nope, not shortcuts, just new translation (localization) keys. So that we change the labels for the existing shortcuts, while keeping the existing labels for older versions of the extension that have the old toggle behavior.

@artjomsR artjomsR marked this pull request as ready for review August 24, 2024 10:05
@artjomsR
Copy link
Contributor Author

I've checked and blur shortcuts worked for me after the rename so should be all good now

@killergerbah killergerbah merged commit 5ddeac8 into killergerbah:main Aug 24, 2024
1 check passed
@killergerbah
Copy link
Owner

Thanks again!

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