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

Fix: loadFullSizeImageImageTimeout not clearing when mouse leaves image #1516

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions js/hoverzoom.js
Original file line number Diff line number Diff line change
@@ -981,6 +981,11 @@ var hoverZoom = {
}

var lastMousePosTop = -1, lastMousePosLeft = -1, cursorHideTimeout = 0;
let loadHoveredImage = false;

function setLoadImage(load) {
loadHoveredImage = load;
}

function documentMouseMove(event) {
if (!options.extensionEnabled || fullZoomKeyDown || isExcludedSite() || wnd.height() < 30 || wnd.width() < 30) {
@@ -1067,23 +1072,28 @@ var hoverZoom = {
srcDetails.url = src;
srcDetails.audioUrl = audioSrc;
clearTimeout(loadFullSizeImageTimeout);

// if the action key has been pressed over an image, no delay is applied
const delay = actionKeyDown || explicitCall ? 0 : (isVideoLink(srcDetails.url) ? options.displayDelayVideo : options.displayDelay);

// setLoadImage used to set loadHoveredImage within callack so timeout can be set outside of callback
// This makes clearTimeout use the correct timeout ID
if (audioSrc) {
chrome.runtime.sendMessage({action:'isImageBanned', url:audioSrc}, function (result) {
setLoadImage(false);
if (!result) {
loadFullSizeImageTimeout = setTimeout(loadFullSizeImage, delay);
setLoadImage(true);
}
});
} else if (src) {
chrome.runtime.sendMessage({action:'isImageBanned', url:src}, function (result) {
setLoadImage(false);
if (!result) {
loadFullSizeImageTimeout = setTimeout(loadFullSizeImage, delay);
setLoadImage(true);
}
});
}

// if the action key has been pressed over an image, no delay is applied
const delay = actionKeyDown || explicitCall ? 0 : (isVideoLink(srcDetails.url) ? options.displayDelayVideo : options.displayDelay);
if (loadHoveredImage) loadFullSizeImageTimeout = setTimeout(loadFullSizeImage, delay);
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not quite sure I understand how this works. Isn't chrome.runtime.sendMessage asynchronous? I mean it returns immediately and at some later point invokes a call back function. Which means line 1096 could check loadHoveredImage value before the callback has opportunity to set it.

Copy link
Contributor Author

@LiliaDoe LiliaDoe Dec 31, 2024

Choose a reason for hiding this comment

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

That is true, and that is also why the bug was happening, i think. The timeout id being set by setTimeout wasn't always being cleared by clearTimeout due to it being async. Maybe I'm misunderstanding why the bug was happening, though. I'm sure there is a better way of solving this

Copy link
Owner

Choose a reason for hiding this comment

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

I think it's better to temporarily remove that entire message sending block until a proper solution is found. Right now the value of loadHoveredImage would be reused from the previous image (because the current image would only set it after it was already checked) which is not correct.

Copy link
Contributor Author

@LiliaDoe LiliaDoe Dec 31, 2024

Choose a reason for hiding this comment

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

If it's temporary, I could comment it out for now like

/*
old code
*/

Copy link
Owner

Choose a reason for hiding this comment

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

I'd imagine @GrosPoulet would want to make it work at some point so commenting out seems fine to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

@extesy @LiliaDoe Happy New Year 🎉
I uncommented L1076-1088 and i can not reproduce the issue on Reddit or any other website. I have a 1 second delay before picture display.
My code:

`
// Temporarily removing until a better fix is found: sendMessage is async so it can't be used to set local variables

                        if (audioSrc) {
                            chrome.runtime.sendMessage({action:'isImageBanned', url:audioSrc}, function (result) {
                                if (!result) {
                                    loadFullSizeImageTimeout = setTimeout(loadFullSizeImage, delay);
                                }
                            });
                        } else if (src) {
                            chrome.runtime.sendMessage({action:'isImageBanned', url:src}, function (result) {
                                if (!result) {
                                    loadFullSizeImageTimeout = setTimeout(loadFullSizeImage, delay);
                                }
                            });                               
                        }

                        loading = true;`

Copy link
Owner

Choose a reason for hiding this comment

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

@GrosPoulet I posted an easy repro steps in #1515 (comment) - please take a look. Anyhow, the code as you wrote it couldn't possibly work due to async nature of sendMessage() function.


loading = true;
}