diff --git a/contributing.md b/contributing.md index 6301e62d..ad033fad 100644 --- a/contributing.md +++ b/contributing.md @@ -54,7 +54,6 @@ Here's an example: you're writing the [`native()`](https://github.com/tridactyl/ ### src/background/ -- commandline_background.ts: A remnant of Tridactyl's previous architecture, where the command line was controlled from the background script. Not used much anymore besides for executing arbitrary ex commands. - config_rc.ts: Functions related to loading and executing the tridactylrc. - controller_background.ts: Parses and executes ex commands. - download_background.ts: Utility functions related to downloading that have to live in the background because downloading APIs aren't available to other processes. diff --git a/src/background.ts b/src/background.ts index 66d47594..96164233 100644 --- a/src/background.ts +++ b/src/background.ts @@ -8,7 +8,6 @@ import * as perf from "@src/perf" import { listenForCounters } from "@src/perf" import * as messaging from "@src/lib/messaging" import * as excmds from "@src/.excmds_background.generated" -import * as commandline_background from "@src/background/commandline_background" import * as convert from "@src/lib/convert" import * as config from "@src/lib/config" import * as dom from "@src/lib/dom" @@ -23,7 +22,6 @@ import { AutoContain } from "@src/lib/autocontainers" ;(window as any).tri = Object.assign(Object.create(null), { messaging, excmds, - commandline_background, convert, config, dom, @@ -57,10 +55,6 @@ browser.tabs.onActivated.addListener(ev => { } }) }) -// - -// Send commandline to controller -commandline_background.onLine.addListener(BackgroundController.acceptExCmd) // {{{ Clobber CSP diff --git a/src/background/commandline_background.ts b/src/background/commandline_background.ts deleted file mode 100644 index 2af02f1d..00000000 --- a/src/background/commandline_background.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { activeTabId } from "@src/lib/webext" -import * as Messaging from "@src/lib/messaging" - -export type onLineCallback = (exStr: string) => void - -/** CommandLine API for inclusion in background script - - Receives messages from commandline_frame -*/ -export const onLine = { - addListener: function(cb: onLineCallback) { - listeners.add(cb) - return () => { - listeners.delete(cb) - } - }, -} - -const listeners = new Set() - -/** Receive events from commandline_frame and pass to listeners */ -function recvExStr(exstr: string) { - for (let listener of listeners) { - listener(exstr) - } -} - -Messaging.addListener( - "commandline_background", - Messaging.attributeCaller({ - recvExStr, - }), -) diff --git a/src/commandline_frame.ts b/src/commandline_frame.ts index 1c971382..82f90e62 100644 --- a/src/commandline_frame.ts +++ b/src/commandline_frame.ts @@ -136,11 +136,6 @@ export function focus() { clInput.addEventListener("blur", noblur) } -/** @hidden **/ -async function sendExstr(exstr) { - Messaging.message("commandline_background", "recvExStr", [exstr]) -} - /** @hidden **/ let HISTORY_SEARCH_STRING: string @@ -376,7 +371,7 @@ export function accept_line() { } cmdline_history_position = 0 - sendExstr(command) + return Messaging.message("controller_background", "acceptExCmd", [command]) } /** @hidden **/ diff --git a/src/excmds.ts b/src/excmds.ts index 8754653c..d0925846 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -108,7 +108,6 @@ import { messageTab, messageActiveTab } from "@src/lib/messaging" import { flatten } from "@src/lib/itertools" import "@src/lib/number.mod" import { firefoxVersionAtLeast } from "@src/lib/webext" -import * as CommandLineBackground from "@src/background/commandline_background" import * as rc from "@src/background/config_rc" import * as excmd_parser from "@src/parsers/exmode" import { mapstrToKeyseq } from "@src/lib/keyseq" @@ -189,7 +188,7 @@ export async function rssexec(url: string, type?: string, ...title: string[]) { } else { rsscmd += " " + url } - return Messaging.message("commandline_background", "recvExStr", [rsscmd]) + return Messaging.message("controller_background", "acceptExCmd", [rsscmd]) } /** @@ -1030,7 +1029,7 @@ export async function open(...urlarr: string[]) { // Setting window.location to about:blank results in a page we can't access, tabs.update works. if (!ABOUT_WHITELIST.includes(url) && url.match(/^(about|file):.*/)) { // Open URLs that firefox won't let us by running `firefox ` on the command line - p = Messaging.message("commandline_background", "recvExStr", ["nativeopen " + url]) + p = Messaging.message("controller_background", "acceptExCmd", ["nativeopen " + url]) } else if (url.match(/^javascript:/)) { let bookmarklet = url.replace(/^javascript:/, "") ;(document.body as any).append( @@ -1068,7 +1067,7 @@ export async function open_quiet(...urlarr: string[]) { let p = Promise.resolve() if (!ABOUT_WHITELIST.includes(url) && url.match(/^(about|file):.*/)) { - return Messaging.message("commandline_background", "recvExStr", ["nativeopen " + url]) + return Messaging.message("controller_background", "acceptExCmd", ["nativeopen " + url]) } return ownTab().then(tab => openInTab(tab, { loadReplace: true }, urlarr)) @@ -1640,7 +1639,7 @@ export async function loadaucmds(cmdType: "DocStart" | "DocLoad" | "DocEnd" | "T const ausites = Object.keys(aucmds) const aukeyarr = ausites.filter(e => window.document.location.href.search(e) >= 0) for (let aukey of aukeyarr) { - Messaging.message("commandline_background", "recvExStr", [aucmds[aukey]]) + Messaging.message("controller_background", "acceptExCmd", [aucmds[aukey]]) } } @@ -3452,17 +3451,6 @@ export function unset(...keys: string[]) { config.unset(...target) } -// not required as we automatically save all config -////#background -//export function saveconfig(){ -// config.save(config.get("storageloc")) -//} - -////#background -//export function mktridactylrc(){ -// saveconfig() -//} - // }}} // {{{ HINTMODE @@ -3806,7 +3794,7 @@ export async function hint(option?: string, selectors?: string, ...rest: string[ */ //#content export function run_exstr(...commands: string[]) { - return Messaging.message("commandline_background", "recvExStr", commands) + return Messaging.message("controller_background", "acceptExCmd", commands) } // }}} diff --git a/src/help.ts b/src/help.ts index dcc69b99..25a4efb4 100644 --- a/src/help.ts +++ b/src/help.ts @@ -130,8 +130,8 @@ function addSettingInputs() { let input = ev.target if (ev.key == "Enter") { ;(window as any).tri.messaging.message( - "commandline_background", - "recvExStr", + "controller_background", + "acceptExCmd", ["set " + input.name + " " + input.value], ) } else { @@ -198,7 +198,7 @@ function addResetConfigButton() { ) if (p == sentence) { ;(window as any).tri.messaging - .message("commandline_background", "recvExStr", [sentence]) + .message("controller_background", "acceptExCmd", [sentence]) .then(_ => alert("Config reset!")) } else { alert(`Config not reset because '${p}' != '${sentence}'`) diff --git a/src/lib/logging.ts b/src/lib/logging.ts index b14d9edd..54c827dc 100644 --- a/src/lib/logging.ts +++ b/src/lib/logging.ts @@ -52,8 +52,8 @@ export class Logger { } if (getContext() == "content") return browser.runtime.sendMessage({ - type: "commandline_background", - command: "recvExStr", + type: "controller_background", + command: "acceptExCmd", args: ["fillcmdline # " + message.join(" ")], }) else diff --git a/src/lib/messaging.ts b/src/lib/messaging.ts index a3610fa9..0dcdd66b 100644 --- a/src/lib/messaging.ts +++ b/src/lib/messaging.ts @@ -9,7 +9,6 @@ export type TabMessageType = | "commandline_frame" export type NonTabMessageType = | "owntab_background" - | "commandline_background" | "controller_background" | "browser_proxy_background" | "download_background"