Skip to content

Commit

Permalink
fix(popup): clear active interception when clear recorded data
Browse files Browse the repository at this point in the history
Fix #149
  • Loading branch information
revathskumar committed Aug 21, 2018
1 parent 479bd37 commit 0f233ac
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class BackgroundWorker {
this.data[this.currentTab].enabled = false;
store.dispatch(toggleListeningRequests(tabId, false));
};

clearData = (tabId: number) => {
this.data[this.currentTab].requests = [];
this.updateBadgeText(tabId, 0);
Expand Down
5 changes: 2 additions & 3 deletions app/containers/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ export class Popup extends React.Component<POPUP_PROPS & DispatchProps, {}> {
this.props.clearFields(this.props.currentTab);
};

handleCheckedRequests = (requests: Array<chrome.webRequest.WebRequestDetails>): void => {
console.log("handleCheckedRequests :: ", this.props.currentTab, requests);
MessageService.interceptChecked(this.props.currentTab, requests);
handleCheckedRequests = (): void => {
MessageService.interceptChecked(this.props.currentTab);
};

disableInterceptor = (tabId: number): void => {
Expand Down
20 changes: 17 additions & 3 deletions app/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export interface contentType {
[contentType: number]: string;
}
interface selectedReqs {
interceptEnabledForTab: boolean;
interceptEnabledForTab?: boolean;
checkedTabRecords: any;
requestsToIntercept: Array<chrome.webRequest.WebRequestBodyDetails>;
tabId: number;
tabId?: number;
}
export type GenericCallbackWithoutParams = () => void;
class Intercept {
Expand All @@ -35,11 +35,25 @@ class Intercept {
startMessageListener = () => {
this.store.ready().then(() => {
chrome.runtime.onMessage.addListener(request => {
this.interceptSelected(request.message, request.tabId);
switch (request.message) {
case "CLEAR_DATA":
this.clearAll();
break;

default:
this.interceptSelected(request.message, request.tabId);
}
});
});
};

clearAll = () => {
this.runInterceptor({
requestsToIntercept: [],
checkedTabRecords: []
});
};

interceptSelected = (message: string, tabId: number) => {
const presentState = this.store.getState().rootReducer.tabRecord[tabId];
if (!presentState) {
Expand Down
4 changes: 2 additions & 2 deletions app/message_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export function disableLogging(tabId: number) {

export function clearData(tabId: number) {
chrome.runtime.sendMessage({ message: "CLEAR_DATA", tabId });
chrome.tabs.sendMessage(tabId, { message: "CLEAR_DATA" });
}

export function interceptChecked(tabId: number, requests: Array<any>) {
export function interceptChecked(tabId: number) {
chrome.tabs.sendMessage(tabId, {
message: "INTERCEPT_CHECKED",
requestsToIntercept: requests,
tabId
});
}
Expand Down
3 changes: 2 additions & 1 deletion app/reducers/rootReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ export const reducer = (state = INITIAL_POPUP_STATE, action: Action) => {
});
case actionType.CLEAR_REQUESTS:
return extendTabRecords(state, action.payload, {
requests: []
requests: [],
requestRecords: {}
});
case actionType.TOGGLE_CHECKBOX:
return extendTabRecords(state, action.payload, {
Expand Down

0 comments on commit 0f233ac

Please sign in to comment.