mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
Merge pull request #3386 from Rummskartoffel/no-unsafe-call
Fix a few trivial no-unsafe-call errors
This commit is contained in:
commit
6d8d962e5a
6 changed files with 44 additions and 41 deletions
|
@ -45,7 +45,7 @@ import * as meta from "@src/background/meta"
|
||||||
state,
|
state,
|
||||||
webext,
|
webext,
|
||||||
webrequests,
|
webrequests,
|
||||||
l: prom => prom.then(console.log).catch(console.error),
|
l: (prom: Promise<any>) => prom.then(console.log).catch(console.error),
|
||||||
contentLocation: window.location,
|
contentLocation: window.location,
|
||||||
R,
|
R,
|
||||||
perf,
|
perf,
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import * as useractions from "@src/background/user_actions"
|
import { useractions } from "@src/background/user_actions"
|
||||||
import * as config from "@src/lib/config"
|
import * as config from "@src/lib/config"
|
||||||
import * as keyseq from "@src/lib/keyseq"
|
import * as keyseq from "@src/lib/keyseq"
|
||||||
import * as controller from "@src/lib/controller"
|
import * as controller from "@src/lib/controller"
|
||||||
|
|
||||||
function makelistener(commands) {
|
function makelistener(commands: Array<browser.commands.Command>) {
|
||||||
return (command_name: string) => {
|
return (command_name: string) => {
|
||||||
const command = commands.filter(c => c.name == command_name)[0]
|
const command = commands.filter(c => c.name == command_name)[0]
|
||||||
const exstring = config.get(
|
const exstring = config.get(
|
||||||
|
|
|
@ -9,7 +9,7 @@ import * as R from "ramda"
|
||||||
import * as config from "@src/lib/config"
|
import * as config from "@src/lib/config"
|
||||||
import { getTridactylTabs } from "@src/background/meta"
|
import { getTridactylTabs } from "@src/background/meta"
|
||||||
|
|
||||||
export function escapehatch() {
|
function escapehatch() {
|
||||||
if (config.get("escapehatchsidebarhack") == "true") {
|
if (config.get("escapehatchsidebarhack") == "true") {
|
||||||
// Only works if called via commands API command - fail silently if called otherwise
|
// Only works if called via commands API command - fail silently if called otherwise
|
||||||
browser.sidebarAction.open().catch()
|
browser.sidebarAction.open().catch()
|
||||||
|
@ -35,3 +35,7 @@ export function escapehatch() {
|
||||||
return browser.tabs.update(best.id, { active: true })
|
return browser.tabs.update(best.id, { active: true })
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useractions: Record<string, () => void> = {
|
||||||
|
escapehatch,
|
||||||
|
}
|
||||||
|
|
|
@ -17,53 +17,54 @@
|
||||||
|
|
||||||
/** Script used in the commandline iframe. Communicates with background. */
|
/** Script used in the commandline iframe. Communicates with background. */
|
||||||
|
|
||||||
import * as perf from "@src/perf"
|
import * as SELF from "@src/commandline_frame"
|
||||||
import "@src/lib/number.clamp"
|
import { CompletionSourceFuse } from "@src/completions"
|
||||||
import "@src/lib/html-tagged-template"
|
import { AproposCompletionSource } from "@src/completions/Apropos"
|
||||||
import { TabAllCompletionSource } from "@src/completions/TabAll"
|
|
||||||
import { BindingsCompletionSource } from "@src/completions/Bindings"
|
import { BindingsCompletionSource } from "@src/completions/Bindings"
|
||||||
import { BufferCompletionSource } from "@src/completions/Tab"
|
|
||||||
import { BmarkCompletionSource } from "@src/completions/Bmark"
|
import { BmarkCompletionSource } from "@src/completions/Bmark"
|
||||||
import { ExcmdCompletionSource } from "@src/completions/Excmd"
|
|
||||||
import { ThemeCompletionSource } from "@src/completions/Theme"
|
|
||||||
import { CompositeCompletionSource } from "@src/completions/Composite"
|
import { CompositeCompletionSource } from "@src/completions/Composite"
|
||||||
|
import { ExcmdCompletionSource } from "@src/completions/Excmd"
|
||||||
|
import { ExtensionsCompletionSource } from "@src/completions/Extensions"
|
||||||
import { FileSystemCompletionSource } from "@src/completions/FileSystem"
|
import { FileSystemCompletionSource } from "@src/completions/FileSystem"
|
||||||
import { GuisetCompletionSource } from "@src/completions/Guiset"
|
import { GuisetCompletionSource } from "@src/completions/Guiset"
|
||||||
import { HelpCompletionSource } from "@src/completions/Help"
|
import { HelpCompletionSource } from "@src/completions/Help"
|
||||||
import { AproposCompletionSource } from "@src/completions/Apropos"
|
|
||||||
import { HistoryCompletionSource } from "@src/completions/History"
|
import { HistoryCompletionSource } from "@src/completions/History"
|
||||||
import { PreferenceCompletionSource } from "@src/completions/Preferences"
|
import { PreferenceCompletionSource } from "@src/completions/Preferences"
|
||||||
import { RssCompletionSource } from "@src/completions/Rss"
|
import { RssCompletionSource } from "@src/completions/Rss"
|
||||||
import { SessionsCompletionSource } from "@src/completions/Sessions"
|
import { SessionsCompletionSource } from "@src/completions/Sessions"
|
||||||
import { SettingsCompletionSource } from "@src/completions/Settings"
|
import { SettingsCompletionSource } from "@src/completions/Settings"
|
||||||
|
import { BufferCompletionSource } from "@src/completions/Tab"
|
||||||
|
import { TabAllCompletionSource } from "@src/completions/TabAll"
|
||||||
|
import { ThemeCompletionSource } from "@src/completions/Theme"
|
||||||
import { WindowCompletionSource } from "@src/completions/Window"
|
import { WindowCompletionSource } from "@src/completions/Window"
|
||||||
import { ExtensionsCompletionSource } from "@src/completions/Extensions"
|
import { contentState } from "@src/content/state_content"
|
||||||
|
import { theme } from "@src/content/styling"
|
||||||
|
import { getCommandlineFns } from "@src/lib/commandline_cmds"
|
||||||
|
import * as tri_editor from "@src/lib/editor"
|
||||||
|
import "@src/lib/html-tagged-template"
|
||||||
|
import Logger from "@src/lib/logging"
|
||||||
import * as Messaging from "@src/lib/messaging"
|
import * as Messaging from "@src/lib/messaging"
|
||||||
import "@src/lib/number.clamp"
|
import "@src/lib/number.clamp"
|
||||||
import state from "@src/state"
|
|
||||||
import * as State from "@src/state"
|
|
||||||
import Logger from "@src/lib/logging"
|
|
||||||
import { theme } from "@src/content/styling"
|
|
||||||
import { contentState } from "@src/content/state_content"
|
|
||||||
|
|
||||||
import * as genericParser from "@src/parsers/genericmode"
|
import * as genericParser from "@src/parsers/genericmode"
|
||||||
import * as tri_editor from "@src/lib/editor"
|
import * as perf from "@src/perf"
|
||||||
|
import state, * as State from "@src/state"
|
||||||
import * as R from "ramda"
|
import * as R from "ramda"
|
||||||
|
import { KeyEventLike } from "./lib/keyseq"
|
||||||
|
|
||||||
|
|
||||||
/** @hidden **/
|
/** @hidden **/
|
||||||
const logger = new Logger("cmdline")
|
const logger = new Logger("cmdline")
|
||||||
|
|
||||||
/** @hidden **/
|
/** @hidden **/
|
||||||
const commandline_state = {
|
const commandline_state = {
|
||||||
activeCompletions: undefined,
|
activeCompletions: undefined as CompletionSourceFuse[],
|
||||||
clInput: window.document.getElementById(
|
clInput: window.document.getElementById(
|
||||||
"tridactyl-input",
|
"tridactyl-input",
|
||||||
) as HTMLInputElement,
|
) as HTMLInputElement,
|
||||||
clear,
|
clear,
|
||||||
cmdline_history_position: 0,
|
cmdline_history_position: 0,
|
||||||
completionsDiv: window.document.getElementById("completions"),
|
completionsDiv: window.document.getElementById("completions"),
|
||||||
fns: undefined,
|
fns: undefined as ReturnType<typeof getCommandlineFns>,
|
||||||
getCompletion,
|
getCompletion,
|
||||||
history,
|
history,
|
||||||
/** @hidden
|
/** @hidden
|
||||||
|
@ -206,7 +207,7 @@ commandline_state.clInput.addEventListener(
|
||||||
// Abuse async to wrap non-promises in a promise
|
// Abuse async to wrap non-promises in a promise
|
||||||
// eslint-disable-next-line @typescript-eslint/require-await
|
// eslint-disable-next-line @typescript-eslint/require-await
|
||||||
(async () =>
|
(async () =>
|
||||||
commandline_state.fns[funcname](
|
commandline_state.fns[funcname as keyof typeof commandline_state.fns](
|
||||||
args.length === 0 ? undefined : args.join(" "),
|
args.length === 0 ? undefined : args.join(" "),
|
||||||
))(),
|
))(),
|
||||||
)
|
)
|
||||||
|
@ -347,7 +348,7 @@ export function getContent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hidden **/
|
/** @hidden **/
|
||||||
export function editor_function(fn_name, ...args) {
|
export function editor_function(fn_name: keyof typeof tri_editor, ...args) {
|
||||||
let result = Promise.resolve([])
|
let result = Promise.resolve([])
|
||||||
if (tri_editor[fn_name]) {
|
if (tri_editor[fn_name]) {
|
||||||
tri_editor[fn_name](commandline_state.clInput, ...args)
|
tri_editor[fn_name](commandline_state.clInput, ...args)
|
||||||
|
@ -360,11 +361,8 @@ export function editor_function(fn_name, ...args) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
import * as SELF from "@src/commandline_frame"
|
|
||||||
Messaging.addListener("commandline_frame", Messaging.attributeCaller(SELF))
|
Messaging.addListener("commandline_frame", Messaging.attributeCaller(SELF))
|
||||||
|
|
||||||
import { getCommandlineFns } from "@src/lib/commandline_cmds"
|
|
||||||
import { KeyEventLike } from "./lib/keyseq"
|
|
||||||
commandline_state.fns = getCommandlineFns(commandline_state)
|
commandline_state.fns = getCommandlineFns(commandline_state)
|
||||||
Messaging.addListener(
|
Messaging.addListener(
|
||||||
"commandline_cmd",
|
"commandline_cmd",
|
||||||
|
|
|
@ -86,6 +86,7 @@ import { AutoContain } from "@src/lib/autocontainers"
|
||||||
import * as CSS from "css"
|
import * as CSS from "css"
|
||||||
import * as Perf from "@src/perf"
|
import * as Perf from "@src/perf"
|
||||||
import * as Metadata from "@src/.metadata.generated"
|
import * as Metadata from "@src/.metadata.generated"
|
||||||
|
import { ObjectType } from "../compiler/types/ObjectType"
|
||||||
import * as Native from "@src/lib/native"
|
import * as Native from "@src/lib/native"
|
||||||
import * as TTS from "@src/lib/text_to_speech"
|
import * as TTS from "@src/lib/text_to_speech"
|
||||||
import * as excmd_parser from "@src/parsers/exmode"
|
import * as excmd_parser from "@src/parsers/exmode"
|
||||||
|
@ -189,9 +190,9 @@ export async function getNativeVersion(): Promise<string> {
|
||||||
//#content
|
//#content
|
||||||
export async function getRssLinks(): Promise<Array<{ type: string; url: string; title: string }>> {
|
export async function getRssLinks(): Promise<Array<{ type: string; url: string; title: string }>> {
|
||||||
const seen = new Set<string>()
|
const seen = new Set<string>()
|
||||||
return Array.from(document.querySelectorAll("a, link[rel='alternate']"))
|
return Array.from(document.querySelectorAll<HTMLAnchorElement | HTMLLinkElement>("a, link[rel='alternate']"))
|
||||||
.filter((e: any) => typeof e.href === "string")
|
.filter((e) => typeof e.href === "string")
|
||||||
.reduce((acc, e: any) => {
|
.reduce((acc, e) => {
|
||||||
let type = ""
|
let type = ""
|
||||||
// Start by detecting type because url doesn't necessarily contain the words "rss" or "atom"
|
// Start by detecting type because url doesn't necessarily contain the words "rss" or "atom"
|
||||||
if (e.type) {
|
if (e.type) {
|
||||||
|
@ -1339,7 +1340,7 @@ export async function url2args() {
|
||||||
|
|
||||||
/** @hidden */
|
/** @hidden */
|
||||||
//#content_helper
|
//#content_helper
|
||||||
let sourceElement
|
let sourceElement: Element
|
||||||
/** @hidden */
|
/** @hidden */
|
||||||
//#content_helper
|
//#content_helper
|
||||||
function removeSource() {
|
function removeSource() {
|
||||||
|
@ -1527,7 +1528,7 @@ export async function apropos(...helpItems: string[]) {
|
||||||
//#background
|
//#background
|
||||||
export async function tutor(newtab?: string) {
|
export async function tutor(newtab?: string) {
|
||||||
const tutor = browser.runtime.getURL("static/clippy/1-tutor.html")
|
const tutor = browser.runtime.getURL("static/clippy/1-tutor.html")
|
||||||
let done
|
let done: Promise<any>
|
||||||
if (newtab) {
|
if (newtab) {
|
||||||
done = tabopen(tutor)
|
done = tabopen(tutor)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1976,7 +1977,7 @@ export async function loadaucmds(cmdType: "DocStart" | "DocLoad" | "DocEnd" | "T
|
||||||
try {
|
try {
|
||||||
await controller.acceptExCmd(aucmds[aukey])
|
await controller.acceptExCmd(aucmds[aukey])
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(e.toString())
|
logger.error((e as Error).toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2165,7 +2166,7 @@ export async function tabnext(increment = 1) {
|
||||||
*/
|
*/
|
||||||
//#background
|
//#background
|
||||||
export async function tabnext_gt(index?: number) {
|
export async function tabnext_gt(index?: number) {
|
||||||
let done
|
let done: Promise<any>
|
||||||
if (index === undefined) {
|
if (index === undefined) {
|
||||||
done = tabnext()
|
done = tabnext()
|
||||||
} else {
|
} else {
|
||||||
|
@ -2288,7 +2289,7 @@ export async function tabopen(...addressarr: string[]): Promise<browser.tabs.Tab
|
||||||
const win = await browser.windows.getCurrent()
|
const win = await browser.windows.getCurrent()
|
||||||
|
|
||||||
// Lets us pass both -b and -c in no particular order as long as they are up front.
|
// Lets us pass both -b and -c in no particular order as long as they are up front.
|
||||||
async function argParse(args): Promise<string[]> {
|
async function argParse(args: string[]): Promise<string[]> {
|
||||||
if (args[0] === "-b") {
|
if (args[0] === "-b") {
|
||||||
active = false
|
active = false
|
||||||
args.shift()
|
args.shift()
|
||||||
|
@ -2735,7 +2736,7 @@ export async function mute(...muteArgs: string[]): Promise<void> {
|
||||||
if (mute) {
|
if (mute) {
|
||||||
updateObj.muted = true
|
updateObj.muted = true
|
||||||
}
|
}
|
||||||
let done
|
let done: Promise<any>
|
||||||
if (all) {
|
if (all) {
|
||||||
const tabs = await browser.tabs.query({ currentWindow: true })
|
const tabs = await browser.tabs.query({ currentWindow: true })
|
||||||
const promises = []
|
const promises = []
|
||||||
|
@ -3105,7 +3106,7 @@ export async function shellescape(...quoteme: string[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//#background_helper
|
//#background_helper
|
||||||
import * as useractions from "@src/background/user_actions"
|
import { useractions } from "@src/background/user_actions"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Magic escape hatch: if Tridactyl can't run in the current tab, return to a tab in the current window where Tridactyl can run, making such a tab if it doesn't currently exist. If Tridactyl can run in the current tab, return focus to the document body from e.g. the URL bar or a video player.
|
* Magic escape hatch: if Tridactyl can't run in the current tab, return to a tab in the current window where Tridactyl can run, making such a tab if it doesn't currently exist. If Tridactyl can run in the current tab, return focus to the document body from e.g. the URL bar or a video player.
|
||||||
|
@ -3628,7 +3629,7 @@ function validateSetArgs(key: string, values: string[]) {
|
||||||
const strval = values.join(" ")
|
const strval = values.join(" ")
|
||||||
// Note: the conversion will throw if strval can't be converted to the right type
|
// Note: the conversion will throw if strval can't be converted to the right type
|
||||||
if (md.type.kind === "object" && target.length > 1) {
|
if (md.type.kind === "object" && target.length > 1) {
|
||||||
value = (md as any).type.convertMember(target.slice(1), strval)
|
value = (md.type as ObjectType).convertMember(target.slice(1), strval)
|
||||||
} else {
|
} else {
|
||||||
value = md.type.convert(strval)
|
value = md.type.convert(strval)
|
||||||
}
|
}
|
||||||
|
@ -4859,7 +4860,7 @@ export async function bmark(url?: string, ...titlearr: string[]) {
|
||||||
if (path != "") {
|
if (path != "") {
|
||||||
const tree = (await browser.bookmarks.getTree())[0] // Why would getTree return a tree? Obviously it returns an array of unit length.
|
const tree = (await browser.bookmarks.getTree())[0] // Why would getTree return a tree? Obviously it returns an array of unit length.
|
||||||
// I hate recursion.
|
// I hate recursion.
|
||||||
const treeClimber = (tree, treestr) => {
|
const treeClimber = (tree: browser.bookmarks.BookmarkTreeNode, treestr) => {
|
||||||
if (tree.type !== "folder") return {}
|
if (tree.type !== "folder") return {}
|
||||||
treestr += tree.title + "/"
|
treestr += tree.title + "/"
|
||||||
if (!("children" in tree) || tree.children.length === 0) return [{ path: treestr, id: tree.id }]
|
if (!("children" in tree) || tree.children.length === 0) return [{ path: treestr, id: tree.id }]
|
||||||
|
|
|
@ -108,7 +108,7 @@ export const transpose_chars = wrap_input(
|
||||||
* Applies a function to the word the caret is in, or to the next word if the caret is not in a word, or to the previous word if the current word is empty.
|
* Applies a function to the word the caret is in, or to the next word if the caret is not in a word, or to the previous word if the current word is empty.
|
||||||
*/
|
*/
|
||||||
function applyWord(
|
function applyWord(
|
||||||
text,
|
text: string,
|
||||||
selectionStart,
|
selectionStart,
|
||||||
selectionEnd,
|
selectionEnd,
|
||||||
fn: (s: string) => string,
|
fn: (s: string) => string,
|
||||||
|
|
Loading…
Add table
Reference in a new issue