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 page messaging #49

Merged
merged 5 commits into from
Jan 22, 2017
Merged

Conversation

godd9170
Copy link
Contributor

@godd9170 godd9170 commented Jan 19, 2017

I've added an optional extensionId to the Store constructor. I use the extensionId in the connect and sendMessage functions, and listen for onMessageExternal and onConnectExternal in the background.js. fixes #47

Copy link
Owner

@tshaddix tshaddix left a comment

Choose a reason for hiding this comment

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

This is awesome! Thanks for doing this. I'd love to verify that this is working on the examples without an extension id passed in.

Also, we should make sure to update the unit tests:

https://github.com/tshaddix/react-chrome-redux/blob/master/test/Store.test.js


this.port = chrome.runtime.connect({name: portName});
this.extensionId = extensionId; //keep the extensionId as an instance variable
this.port = chrome.runtime.connect(this.extensionId, {name: portName});
Copy link
Owner

Choose a reason for hiding this comment

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

@godd9170 Have you verified this works when it is passed in as an empty string? We should test on the examples repo :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have yes, I tried it with your original clicker-key example happening in the content.js.

Copy link
Owner

Choose a reason for hiding this comment

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

Okay, great. I will do it on my end as well so we can get two confirmations involved 👍

* Setup for state updates
*/
const connectState = (port) => {
console.log('connected on port: ', port);
Copy link
Owner

Choose a reason for hiding this comment

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

Can we remove this console log?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did I put that one in? Sorry I thought that was from the original. Sure can.

@@ -64,7 +66,9 @@ class Store {
*/
dispatch(data) {
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage({
chrome.runtime.sendMessage(
this.extensionId,
Copy link
Owner

Choose a reason for hiding this comment

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

Have we verified this works with an empty extension id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

/**
* Setup action handler
*/
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
Copy link
Owner

Choose a reason for hiding this comment

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

Can we simplify this as chrome.runtime.onMessage.addListener(dispatchResponse)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems pretty reasonable!

* Setup external action handler
*/
chrome.runtime.onMessageExternal.addListener((request, sender, sendResponse) => {
return dispatchResponse(request, sender, sendResponse);
Copy link
Owner

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

* Setup extended connection
*/
chrome.runtime.onConnect.addListener((port) => {
return connectState(port);
Copy link
Owner

Choose a reason for hiding this comment

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

Can we simplify this to chrome.runtime.onConnect.addListener(connectState)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

* Setup extended external connection
*/
chrome.runtime.onConnectExternal.addListener((port) => {
return connectState(port);
Copy link
Owner

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@vhmth
Copy link
Collaborator

vhmth commented Jan 19, 2017

@tshaddix you mean to link to a PR? I think you linked to a file :-P

@tshaddix
Copy link
Owner

tshaddix commented Jan 19, 2017

@vhmth Oh sorry yes I meant to link to a file. I was showing where the unit test needed to be changed. I understand the confusion by saying "this PR" :P

Fixed

@godd9170
Copy link
Contributor Author

@tshaddix glad you like it, apologies about breaking all your tests, I was too tired to do them last night! I'll make those changes later tonight, do you also want me to take a stab at re-writing the unit tests? I'm afraid to admit I've never done any javascript unit testing, but keen to learn.

@tshaddix
Copy link
Owner

@godd9170 Absolutely no worries! A lot of good additions in here :)

It's up to you! I think it's a good way to round off this PR and the problem space if pretty small, so it might be good place for you to try it out!

If not, I'll be happy to fix them up. Just let me know and I'll help where I can!

@godd9170
Copy link
Contributor Author

Ok, changes applied and tests fixed. I think we should probably mock up the sendMessageExternal stuff, I just couldn't figure out how to do it.

@tshaddix
Copy link
Owner

Awesome work fixing up the tests! Going to run this one more time on my end against the examples and then I think we can merge.

@tshaddix tshaddix merged commit 6347d1c into tshaddix:master Jan 22, 2017
@tshaddix
Copy link
Owner

@godd9170 Your changes have been released in v1.2.0! Thank you!

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.

Communicating with script injected into webpage.
3 participants