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

feature/reward signal hotfix #111

Merged
merged 6 commits into from Jun 22, 2018
Merged
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

hub closed signal on disconnect
  • Loading branch information
trickpattyFH20 committed Jun 22, 2018
commit bd8a202e04bf069da1af734e76a01b72f7f01bce
@@ -15,7 +15,7 @@ import React, { Component } from 'react';
import ClassNames from 'classnames';
import { Link, Route } from 'react-router-dom';
import { ToggleSlider, RewardListItem, RewardDetail } from './BuildingBlocks';
import { sendMessage } from '../utils/msg';
import { sendMessage, sendRewardMessage } from '../utils/msg';
import globals from '../../../src/classes/Globals';

const IS_EDGE = (globals.BROWSER_INFO.name === 'edge');
@@ -84,7 +84,9 @@ class Rewards extends React.Component {
* Lifecycle event
*/
componentWillUnmount() {
/* @TODO send message to background to remove port onDisconnect event */
this.props.actions.sendSignal('hub_closed');
sendRewardMessage('removeDisconnectListener');
}

/**
@@ -443,6 +443,9 @@ function handleRewards(name, message, tab_id, callback) {
case 'ping':
metrics.ping(message);
break;
case 'removeDisconnectListener':
rewards.panelPort.onDisconnect.removeListener(rewards.panelHubClosedListener);
break;
default:
break;
}
@@ -1272,7 +1275,7 @@ function initializeEventListeners() {
chrome.runtime.onConnect.addListener((port) => {
if (port && port.name === 'rewardsPanelPort') {
rewards.panelPort = port;
rewards.panelHubClosedListener();
rewards.panelPort.onDisconnect.addListener(rewards.panelHubClosedListener);
}
});
}
@@ -36,6 +36,7 @@ class Rewards {
this.panelPort = null;
this.ports = new Map();
this.channelsSupported = (typeof chrome.runtime.onConnect === 'object');
this.panelHubClosedListener = this.panelHubClosedListener.bind(this);
}

deleteReward(offerId) {
@@ -152,13 +153,11 @@ class Rewards {
}

panelHubClosedListener() {
this.panelPort.onDisconnect.addListener(() => {
this.sendSignal({
offerId: null,
actionId: 'hub_closed',
origin: 'ghostery-rewards-hub',
type: 'action-signal'
});
this.sendSignal({
offerId: null,
actionId: 'hub_closed',
origin: 'rewards-hub',
type: 'action-signal'
});
}
}
ProTip! Use n and p to navigate between commits in a pull request.