Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 3e5b336

Browse files
Fischer-LjasonLaster
authored andcommitted
3601 - [blackbox] sources should be persisted (#5583)
* 3601 - [blackbox] blackbox sources should be persisted * Add pref to asset list so Firefox will build. * Lint
1 parent ac524ea commit 3e5b336

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

assets/panel/prefs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pref("devtools.debugger.expressions-visible", true);
3535
pref("devtools.debugger.start-panel-collapsed", false);
3636
pref("devtools.debugger.end-panel-collapsed", false);
3737
pref("devtools.debugger.tabs", "[]");
38+
pref("devtools.debugger.tabsBlackBoxed", "[]");
3839
pref("devtools.debugger.pending-selected-location", "{}");
3940
pref("devtools.debugger.pending-breakpoints", "{}");
4041
pref("devtools.debugger.expressions", "[]");

src/actions/sources/newSources.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
* Redux actions for the sources state
99
* @module actions/sources
1010
*/
11-
11+
import { toggleBlackBox } from "./blackbox";
1212
import { syncBreakpoint } from "../breakpoints";
1313
import { loadSourceText } from "./loadSourceText";
1414
import { togglePrettyPrint } from "./prettyPrint";
1515
import { selectLocation } from "../sources";
1616
import { getRawSourceURL, isPrettyURL } from "../../utils/source";
1717

1818
import {
19+
getBlackBoxList,
1920
getSource,
2021
getPendingSelectedLocation,
2122
getPendingBreakpointsForSource
@@ -124,6 +125,20 @@ function checkPendingBreakpoints(sourceId: string) {
124125
};
125126
}
126127

128+
function restoreBlackBoxedSources(sources: Source[]) {
129+
return async ({ dispatch }: ThunkArgs) => {
130+
const tabs = getBlackBoxList();
131+
if (tabs.length == 0) {
132+
return;
133+
}
134+
for (const source of sources) {
135+
if (tabs.includes(source.url) && !source.isBlackBoxed) {
136+
dispatch(toggleBlackBox(source));
137+
}
138+
}
139+
};
140+
}
141+
127142
/**
128143
* Handler for the debugger client's unsolicited newSource notification.
129144
* @memberof actions/sources
@@ -155,8 +170,11 @@ export function newSources(sources: Source[]) {
155170
dispatch(checkPendingBreakpoints(source.id));
156171
}
157172

158-
return Promise.all(
173+
await Promise.all(
159174
filteredSources.map(source => dispatch(loadSourceMap(source)))
160175
);
176+
// We would like to restore the blackboxed state
177+
// after loading all states to make sure the correctness.
178+
dispatch(restoreBlackBoxedSources(filteredSources));
161179
};
162180
}

src/reducers/sources.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ function update(
138138

139139
case "BLACKBOX":
140140
if (action.status === "done") {
141+
const url = action.source.url;
142+
const isBlackBoxed = action.value.isBlackBoxed;
143+
updateBlackBoxList(url, isBlackBoxed);
141144
return state.setIn(
142145
["sources", action.source.id, "isBlackBoxed"],
143-
action.value.isBlackBoxed
146+
isBlackBoxed
144147
);
145148
}
146149
break;
@@ -237,6 +240,23 @@ function updateTabList(state: OuterState, url: ?string, tabIndex?: number) {
237240
return tabs;
238241
}
239242

243+
function updateBlackBoxList(url, isBlackBoxed) {
244+
const tabs = getBlackBoxList();
245+
const i = tabs.indexOf(url);
246+
if (i >= 0) {
247+
if (!isBlackBoxed) {
248+
tabs.splice(i, 1);
249+
}
250+
} else if (isBlackBoxed) {
251+
tabs.push(url);
252+
}
253+
prefs.tabsBlackBoxed = tabs;
254+
}
255+
256+
export function getBlackBoxList() {
257+
return prefs.tabsBlackBoxed || [];
258+
}
259+
240260
/**
241261
* Gets the next tab to select when a tab closes. Heuristics:
242262
* 1. if the selected tab is available, it remains selected

src/utils/prefs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ if (isDevelopment()) {
2525
pref("devtools.debugger.start-panel-collapsed", false);
2626
pref("devtools.debugger.end-panel-collapsed", false);
2727
pref("devtools.debugger.tabs", "[]");
28+
pref("devtools.debugger.tabsBlackBoxed", "[]");
2829
pref("devtools.debugger.ui.framework-grouping-on", true);
2930
pref("devtools.debugger.pending-selected-location", "{}");
3031
pref("devtools.debugger.pending-breakpoints", "{}");
@@ -67,6 +68,7 @@ export const prefs = new PrefsHelper("devtools", {
6768
endPanelCollapsed: ["Bool", "debugger.end-panel-collapsed"],
6869
frameworkGroupingOn: ["Bool", "debugger.ui.framework-grouping-on"],
6970
tabs: ["Json", "debugger.tabs", []],
71+
tabsBlackBoxed: ["Json", "debugger.tabsBlackBoxed", []],
7072
pendingSelectedLocation: ["Json", "debugger.pending-selected-location", {}],
7173
pendingBreakpoints: ["Json", "debugger.pending-breakpoints", {}],
7274
expressions: ["Json", "debugger.expressions", []],

0 commit comments

Comments
 (0)