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

Support multiple download #1

Merged
merged 3 commits into from
Jul 2, 2018
Merged

Conversation

angels2it
Copy link

the code is based on PR sindresorhus#36

@angels2it angels2it requested a review from pandafox June 22, 2018 04:15
}
});
};

session.on('will-download', listener);
if (!sessionListenerMap.get(session)) {
sessionListenerMap.set(session, true);

Choose a reason for hiding this comment

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

This looks like a session leak where we'll never remove this?

Copy link
Author

Choose a reason for hiding this comment

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

Don't worry, We just set it one time because of condition if (!sessionListenerMap.get(session))

Choose a reason for hiding this comment

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

I'm not sure what you meant. if we don't have code to remove this. sessionListenerMap would just keep growing infinitely = session leak.

We need to also remove the session when its no longer used?

Copy link
Author

Choose a reason for hiding this comment

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

I think we just have 1 session / electron windows?. This sessionListenerMap will destroyed when session destroy?

Choose a reason for hiding this comment

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

session is dead doesn't mean it'll be removed from the sessionListenerMap, right? So we should listen to window close event and remove session from sessionListenerMap?

Copy link
Author

Choose a reason for hiding this comment

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

I updated the code to delete session in sessionListenerMap before windows close event

index.js Outdated
const listener = (e, item, webContents) => {
const url = decodeURIComponent(_.first(item.getURLChain()));

Choose a reason for hiding this comment

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

The URL created is different than handlerMap.set(decodeURIComponent(url) ?

We should have a utility function to create the consistent key

Copy link
Author

Choose a reason for hiding this comment

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

we can not use same function because handleMap.set use download url - first time
When start download, the downloader will check the url & follow to new url if has redirect response.
We just have 1 way to get original url is get from item.getUrlChain() - first item

Choose a reason for hiding this comment

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

Not quite sure what you meant, the way hashmap works is that you use the same key, if we cannot use the same key, then there's no point using a hashmap?

Copy link
Author

Choose a reason for hiding this comment

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

value of item.getUrlChain() (first item) is equal with url that set in L144

Choose a reason for hiding this comment

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

That's not very clear that it'll be equal? Create a function and use it consistently?

Copy link
Author

Choose a reason for hiding this comment

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

I think it's difference context. So we can not use same way to get it. The first when we set it, We know exactly it's a key. the second time when we use it. The context of code is in download handler. We just have only way to get it is based on item.getChainUrl

Choose a reason for hiding this comment

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

If that's the case, let's break it up into two variables, one for key and one for url to avoid confusion?

index.js Outdated
@@ -143,6 +152,7 @@ module.exports.download = (win, url, options) => new Promise((resolve, reject) =

handlerMap.set(decodeURIComponent(url), {options, resolve, reject});

Choose a reason for hiding this comment

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

Do we want to also rename url to key? Do we actually use the url?

@angels2it angels2it merged commit afbc363 into master Jul 2, 2018
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