summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/src/middleware/prefs.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/client/netmonitor/src/middleware/prefs.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/netmonitor/src/middleware/prefs.js')
-rw-r--r--devtools/client/netmonitor/src/middleware/prefs.js116
1 files changed, 116 insertions, 0 deletions
diff --git a/devtools/client/netmonitor/src/middleware/prefs.js b/devtools/client/netmonitor/src/middleware/prefs.js
new file mode 100644
index 0000000000..6034a95dbf
--- /dev/null
+++ b/devtools/client/netmonitor/src/middleware/prefs.js
@@ -0,0 +1,116 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {
+ ENABLE_REQUEST_FILTER_TYPE_ONLY,
+ RESET_COLUMNS,
+ TOGGLE_COLUMN,
+ TOGGLE_REQUEST_FILTER_TYPE,
+ ENABLE_PERSISTENT_LOGS,
+ DISABLE_BROWSER_CACHE,
+ SET_COLUMNS_WIDTH,
+ WS_TOGGLE_COLUMN,
+ WS_RESET_COLUMNS,
+} = require("resource://devtools/client/netmonitor/src/constants.js");
+
+/**
+ * Update the relevant prefs when:
+ * - a column has been toggled
+ * - a filter type has been set
+ */
+function prefsMiddleware(store) {
+ return next => action => {
+ const res = next(action);
+ switch (action.type) {
+ case ENABLE_REQUEST_FILTER_TYPE_ONLY:
+ case TOGGLE_REQUEST_FILTER_TYPE:
+ const filters = Object.entries(
+ store.getState().filters.requestFilterTypes
+ )
+ .filter(([type, check]) => check)
+ .map(([type, check]) => type);
+ Services.prefs.setCharPref(
+ "devtools.netmonitor.filters",
+ JSON.stringify(filters)
+ );
+ break;
+ case ENABLE_PERSISTENT_LOGS:
+ const enabled = store.getState().ui.persistentLogsEnabled;
+ Services.prefs.setBoolPref("devtools.netmonitor.persistlog", enabled);
+ break;
+ case DISABLE_BROWSER_CACHE:
+ Services.prefs.setBoolPref(
+ "devtools.cache.disabled",
+ store.getState().ui.browserCacheDisabled
+ );
+ break;
+ case TOGGLE_COLUMN:
+ persistVisibleColumns(store.getState());
+ break;
+ case RESET_COLUMNS:
+ persistVisibleColumns(store.getState());
+ persistColumnsData(store.getState());
+ break;
+ case SET_COLUMNS_WIDTH:
+ persistColumnsData(store.getState());
+ break;
+ case WS_TOGGLE_COLUMN:
+ case WS_RESET_COLUMNS:
+ persistVisibleWebSocketsColumns(store.getState());
+ break;
+ }
+ return res;
+ };
+}
+
+/**
+ * Store list of visible columns into preferences.
+ */
+function persistVisibleColumns(state) {
+ const visibleColumns = [];
+ const { columns } = state.ui;
+ for (const column in columns) {
+ if (columns[column]) {
+ visibleColumns.push(column);
+ }
+ }
+
+ Services.prefs.setCharPref(
+ "devtools.netmonitor.visibleColumns",
+ JSON.stringify(visibleColumns)
+ );
+}
+
+/**
+ * Store list of visible columns into preferences.
+ */
+function persistVisibleWebSocketsColumns(state) {
+ const visibleColumns = [];
+ const { columns } = state.messages;
+ for (const column in columns) {
+ if (columns[column]) {
+ visibleColumns.push(column);
+ }
+ }
+
+ Services.prefs.setCharPref(
+ "devtools.netmonitor.msg.visibleColumns",
+ JSON.stringify(visibleColumns)
+ );
+}
+
+/**
+ * Store columns data (width, min-width, etc.) into preferences.
+ */
+function persistColumnsData(state) {
+ const columnsData = [...state.ui.columnsData.values()];
+ Services.prefs.setCharPref(
+ "devtools.netmonitor.columnsData",
+ JSON.stringify(columnsData)
+ );
+}
+
+module.exports = prefsMiddleware;