tor-browser

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

threads.js (1374B)


      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 
      5 import { createSelector } from "devtools/client/shared/vendor/reselect";
      6 import { parse } from "../utils/url";
      7 
      8 export const getThreads = createSelector(
      9  state => state.threads.threads,
     10  threads => threads.filter(thread => !isMainThread(thread))
     11 );
     12 
     13 export function getAllThreads(state) {
     14  return state.threads.threads;
     15 }
     16 
     17 function isMainThread(thread) {
     18  return thread.isTopLevel;
     19 }
     20 
     21 export function getMainThread(state) {
     22  return state.threads.threads.find(isMainThread);
     23 }
     24 
     25 /*
     26 * Gets domain from the main thread url (without www prefix)
     27 */
     28 export function getMainThreadHost(state) {
     29  const url = getMainThread(state)?.url;
     30  if (!url) {
     31    return null;
     32  }
     33  const { host } = parse(url);
     34  if (!host) {
     35    return null;
     36  }
     37  return host.startsWith("www.") ? host.substring("www.".length) : host;
     38 }
     39 
     40 export function getThread(state, threadActor) {
     41  return getAllThreads(state).find(thread => thread.actor === threadActor);
     42 }
     43 
     44 export function getIsThreadCurrentlyTracing(state, thread) {
     45  return state.threads.mutableTracingThreads.has(thread);
     46 }
     47 
     48 export function getIsCurrentlyTracing(state) {
     49  return state.threads.mutableTracingThreads.size > 0;
     50 }