tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ui.js (3810B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 "use strict";
      5 
      6 const {
      7  INITIALIZE,
      8  MESSAGES_CLEAR,
      9  PERSIST_TOGGLE,
     10  REVERSE_SEARCH_INPUT_TOGGLE,
     11  SELECT_NETWORK_MESSAGE_TAB,
     12  SHOW_OBJECT_IN_SIDEBAR,
     13  SIDEBAR_CLOSE,
     14  SPLIT_CONSOLE_CLOSE_BUTTON_TOGGLE,
     15  TIMESTAMPS_TOGGLE,
     16  FILTERBAR_DISPLAY_MODE_SET,
     17  FILTERBAR_DISPLAY_MODES,
     18  EDITOR_ONBOARDING_DISMISS,
     19  EDITOR_TOGGLE,
     20  EDITOR_PRETTY_PRINT,
     21  EDITOR_SET_WIDTH,
     22  ENABLE_NETWORK_MONITORING,
     23  SHOW_EVALUATION_NOTIFICATION,
     24 } = require("resource://devtools/client/webconsole/constants.js");
     25 
     26 const {
     27  PANELS,
     28 } = require("resource://devtools/client/netmonitor/src/constants.js");
     29 
     30 const UiState = overrides =>
     31  Object.freeze(
     32    Object.assign(
     33      {
     34        initialized: false,
     35        networkMessageActiveTabId: PANELS.HEADERS,
     36        persistLogs: false,
     37        sidebarVisible: false,
     38        timestampsVisible: true,
     39        frontInSidebar: null,
     40        closeButtonVisible: false,
     41        reverseSearchInputVisible: false,
     42        reverseSearchInitialValue: "",
     43        editor: false,
     44        editorWidth: null,
     45        editorPrettifiedAt: null,
     46        showEditorOnboarding: false,
     47        filterBarDisplayMode: FILTERBAR_DISPLAY_MODES.WIDE,
     48        cacheGeneration: 0,
     49        // Only used in the browser toolbox console/ browser console
     50        // turned off by default
     51        enableNetworkMonitoring: false,
     52        notification: null,
     53      },
     54      overrides
     55    )
     56  );
     57 
     58 function ui(state = UiState(), action) {
     59  switch (action.type) {
     60    case PERSIST_TOGGLE:
     61      return { ...state, persistLogs: !state.persistLogs };
     62    case TIMESTAMPS_TOGGLE:
     63      return { ...state, timestampsVisible: !state.timestampsVisible };
     64    case SELECT_NETWORK_MESSAGE_TAB:
     65      return { ...state, networkMessageActiveTabId: action.id };
     66    case SIDEBAR_CLOSE:
     67      return {
     68        ...state,
     69        sidebarVisible: false,
     70        frontInSidebar: null,
     71      };
     72    case INITIALIZE:
     73      return { ...state, initialized: true };
     74    case MESSAGES_CLEAR:
     75      return {
     76        ...state,
     77        sidebarVisible: false,
     78        frontInSidebar: null,
     79        cacheGeneration: state.cacheGeneration + 1,
     80      };
     81    case SHOW_OBJECT_IN_SIDEBAR:
     82      if (action.front === state.frontInSidebar) {
     83        return state;
     84      }
     85      return { ...state, sidebarVisible: true, frontInSidebar: action.front };
     86    case SPLIT_CONSOLE_CLOSE_BUTTON_TOGGLE:
     87      return { ...state, closeButtonVisible: action.shouldDisplayButton };
     88    case SHOW_EVALUATION_NOTIFICATION:
     89      if (state.notification == action.notification) {
     90        return state;
     91      }
     92      return { ...state, notification: action.notification };
     93    case REVERSE_SEARCH_INPUT_TOGGLE:
     94      return {
     95        ...state,
     96        reverseSearchInputVisible: !state.reverseSearchInputVisible,
     97        reverseSearchInitialValue: action.initialValue || "",
     98      };
     99    case FILTERBAR_DISPLAY_MODE_SET:
    100      return {
    101        ...state,
    102        filterBarDisplayMode: action.displayMode,
    103      };
    104    case EDITOR_TOGGLE:
    105      return {
    106        ...state,
    107        editor: !state.editor,
    108      };
    109    case EDITOR_ONBOARDING_DISMISS:
    110      return {
    111        ...state,
    112        showEditorOnboarding: false,
    113      };
    114    case EDITOR_SET_WIDTH:
    115      return {
    116        ...state,
    117        editorWidth: action.width,
    118      };
    119    case EDITOR_PRETTY_PRINT:
    120      return {
    121        ...state,
    122        editorPrettifiedAt: Date.now(),
    123      };
    124    case ENABLE_NETWORK_MONITORING:
    125      return {
    126        ...state,
    127        enableNetworkMonitoring: !state.enableNetworkMonitoring,
    128      };
    129  }
    130 
    131  return state;
    132 }
    133 
    134 module.exports = {
    135  UiState,
    136  ui,
    137 };