Mobe background/native_background.ts to lib/native.ts

All functions in native_background.ts use browserBg in order to interact
with the native messenger. This means that these functions can also be
used in the content script. This means that there's no point in keeping
these functions in the background/ folder and that there's no point in
having a native_background message type.
This commit is contained in:
glacambre 2019-02-20 06:42:45 +01:00
parent 317d3878f2
commit 68a8fccb50
No known key found for this signature in database
GPG key ID: B9625DB1767553AC
11 changed files with 11 additions and 21 deletions

View file

@ -58,7 +58,6 @@ Here's an example: you're writing the [`native()`](https://github.com/tridactyl/
- 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.
- native_background.ts: Wrappers around Firefox's native messaging API. Also has "higher-level" functions that interact with the native messenger (finding the user's favorite editor, reading/setting preferences...).
- nearley_utils.ts: Remnant of Tridactyl's previous architecture, where keys were handled in the background script.
### src/content/
@ -88,6 +87,7 @@ Here's an example: you're writing the [`native()`](https://github.com/tridactyl/
- logging.ts: Tridactyl's logging interfaces.
- math.ts: Math stuff.
- messaging.ts: Implementation of Tridactyl's messaging functions (attributeCaller, message, messageTab, messageOwnTab...).
- native.ts: Wrappers around Firefox's native messaging API. Also has "higher-level" functions that interact with the native messenger (finding the user's favorite editor, reading/setting preferences...).
- requests.ts: CSP-clobbering code.
- text_to_speech.ts: Various wrappers around Firefox's TTS APIs.
- url_util.ts: Url incrementation, query-extraction, interpolation.

View file

@ -16,7 +16,7 @@ import * as download_background from "@src/background/download_background"
import * as itertools from "@src/lib/itertools"
import * as keyseq from "@src/lib/keyseq"
import * as request from "@src/lib/requests"
import * as native from "@src/background/native_background"
import * as native from "@src/lib/native"
import state from "@src/state"
import * as webext from "@src/lib/webext"
import { AutoContain } from "@src/lib/autocontainers"

View file

@ -1,5 +1,5 @@
import * as Controller from "@src/background/controller_background"
import * as Native from "@src/background/native_background"
import * as Native from "@src/lib/native"
import Logger from "@src/lib/logging"
const logger = new Logger("rc")

View file

@ -2,7 +2,7 @@
* Background download-related functions
*/
import * as Native from "@src/background/native_background"
import * as Native from "@src/lib/native"
import { getDownloadFilenameForUrl } from "@src/lib/url_util"
/** Construct an object URL string from a given data URL

View file

@ -1,5 +1,5 @@
import * as Completions from "@src/completions"
import * as Messaging from "@src/lib/messaging"
import * as Native from "@src/lib/native"
import * as config from "@src/lib/config"
class FileSystemCompletionOption extends Completions.CompletionOptionHTML
@ -53,9 +53,7 @@ export class FileSystemCompletionSource extends Completions.CompletionSourceFuse
let req
try {
req = await Messaging.message("native_background", "listDir", [
path,
])
req = await Native.listDir(path)
} catch (e) {
// Failing silently because we can't nativegate (the user is typing stuff in the commandline)
this.state = "hidden"

View file

@ -1,5 +1,5 @@
import * as Completions from "@src/completions"
import * as Messaging from "@src/lib/messaging"
import * as Native from "@src/lib/native"
class PreferenceCompletionOption extends Completions.CompletionOptionHTML
implements Completions.CompletionOptionFuse {
@ -46,7 +46,7 @@ export class PreferenceCompletionSource extends Completions.CompletionSourceFuse
return
}
this.lastExstr = exstr
let preferences = await Messaging.message("native_background", "getPrefs", [])
let preferences = await Native.getPrefs()
this.options = Object.keys(preferences)
.filter(key => key.startsWith(pref))
.map(key => new PreferenceCompletionOption(key, preferences[key]))

View file

@ -70,7 +70,7 @@ import * as webext from "@src/lib/webext"
import Mark from "mark.js"
import * as perf from "@src/perf"
import * as keyseq from "@src/lib/keyseq"
import * as native from "@src/background/native_background"
import * as native from "@src/lib/native"
import * as styling from "@src/content/styling"
;(window as any).tri = Object.assign(Object.create(null), {
browserBg: webext.browserBg,

View file

@ -1,4 +1,3 @@
import * as Native from "@src/background/native_background"
import * as config from "@src/lib/config"
type scrollingDirection = "scrollLeft" | "scrollTop"

View file

@ -84,6 +84,7 @@ import Mark from "mark.js"
import * as CSS from "css"
import * as Perf from "@src/perf"
import * as Metadata from "@src/.metadata.generated"
import * as Native from "@src/lib/native"
/** @hidden **/
const TRI_VERSION = "REPLACE_ME_WITH_THE_VERSION_USING_SED"
@ -112,9 +113,6 @@ import * as rc from "@src/background/config_rc"
import * as excmd_parser from "@src/parsers/exmode"
import { mapstrToKeyseq } from "@src/lib/keyseq"
//#background_helper
import * as Native from "@src/background/native_background"
/** @hidden */
export const cmd_params = new Map<string, Map<string, string>>()
// }
@ -251,7 +249,7 @@ export function removeTridactylEditorClass(selector: string) {
* Opens your favourite editor (which is currently gVim) and fills the last used input with whatever you write into that file.
* **Requires that the native messenger is installed, see [[native]] and [[installnative]]**.
*
* Uses the `editorcmd` config option, default = `auto` looks through a list defined in native_background.ts try find a sensible combination. If it's a bit slow, or chooses the wrong editor, or gives up completely, set editorcmd to something you want. The command must stay in the foreground until the editor exits.
* Uses the `editorcmd` config option, default = `auto` looks through a list defined in lib/native.ts try find a sensible combination. If it's a bit slow, or chooses the wrong editor, or gives up completely, set editorcmd to something you want. The command must stay in the foreground until the editor exits.
*
* The editorcmd needs to accept a filename, stay in the foreground while it's edited, save the file and exit. By default the filename is added to the end of editorcmd, if you require control over the position of that argument, the first occurrence of %f in editorcmd is replaced with the filename:
* ```

View file

@ -12,7 +12,6 @@ export type NonTabMessageType =
| "commandline_background"
| "controller_background"
| "browser_proxy_background"
| "native_background"
| "download_background"
| "performance_background"
export type MessageType = TabMessageType | NonTabMessageType

View file

@ -2,7 +2,6 @@
* Background functions for the native messenger interface
*/
import * as Messaging from "@src/lib/messaging"
import * as semverCompare from "semver-compare"
import * as config from "@src/lib/config"
import { browserBg } from "@src/lib/webext"
@ -619,6 +618,3 @@ export async function writePref(name: string, value: any) {
write(file, text.replace(substr, `pref("${name}", ${value})`))
}
}
import * as SELF from "@src/background/native_background"
Messaging.addListener("native_background", Messaging.attributeCaller(SELF))