本文整理汇总了TypeScript中@src/lib/webext.browserBg.runtime类的典型用法代码示例。如果您正苦于以下问题:TypeScript browserBg.runtime类的具体用法?TypeScript browserBg.runtime怎么用?TypeScript browserBg.runtime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了browserBg.runtime类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: inpath
export async function inpath(cmd) {
const pathcmd =
(await browserBg.runtime.getPlatformInfo()).os === "win"
? "where "
: "which "
return (await run(pathcmd + cmd.split(" ")[0])).code === 0
}
示例2: getFirefoxDir
export async function getFirefoxDir() {
switch ((await browserBg.runtime.getPlatformInfo()).os) {
case "win":
return getenv("APPDATA").then(path => path + "\\Mozilla\\Firefox\\")
case "mac":
return getenv("HOME").then(
path => path + "/Library/Application Support/Firefox/",
)
default:
return getenv("HOME").then(path => path + "/.mozilla/firefox/")
}
}
示例3: ff_cmdline
export async function ff_cmdline(): Promise<string[]> {
// Using ' and + rather that ` because we don't want newlines
if ((await browserBg.runtime.getPlatformInfo()).os === "win") {
throw `Error: "ff_cmdline() is currently broken on Windows and should be avoided."`
} else {
const output = await pyeval(
'handleMessage({"cmd": "run", ' +
'"command": "ps -p " + str(os.getppid()) + " -oargs="})["content"]',
)
return output.content.trim().split(" ")
}
}
示例4: parseProfilesIni
export async function parseProfilesIni(content: string, basePath: string) {
const lines = content.split("\n")
let current = "General"
const result = {}
for (const line of lines) {
let match = line.match(/^\[([^\]]+)\]$/)
if (match !== null) {
current = match[1]
result[current] = {}
} else {
match = line.match(/^([^=]+)=([^=]+)$/)
if (match !== null) {
result[current][match[1]] = match[2]
}
}
}
for (const profileName of Object.keys(result)) {
const profile = result[profileName]
// New profiles.ini have a useless section at the top
if (profile.Path == undefined) {
delete result[profileName]
continue
}
// On windows, profiles.ini paths will be expressed with `/`, but we're
// on windows, so we need `\`
if ((await browserBg.runtime.getPlatformInfo()).os === "win") {
profile.Path = profile.Path.replace("/", "\\")
}
// profile.IsRelative can be 0, 1 or undefined
if (profile.IsRelative === "1") {
profile.relativePath = profile.Path
profile.absolutePath = basePath + profile.relativePath
} else if (profile.IsRelative === "0") {
if (profile.Path.substring(0, basePath.length) !== basePath) {
throw new Error(
`Error parsing profiles ini: basePath "${basePath}" doesn't match profile path ${
profile.Path
}`,
)
}
profile.relativePath = profile.Path.substring(basePath.length)
profile.absolutePath = profile.Path
}
}
return result
}
示例5: nativegate
export async function nativegate(
version = "0",
interactive = true,
desiredOS = ["mac", "win", "linux", "openbsd"],
// desiredOS = ["mac", "win", "android", "cros", "linux", "openbsd"]
): Promise<boolean> {
if (!desiredOS.includes((await browserBg.runtime.getPlatformInfo()).os)) {
if (interactive) {
logger.error(
"# Tridactyl's native messenger doesn't support your operating system, yet.",
)
}
return false
}
try {
const actualVersion = await getNativeMessengerVersion()
if (actualVersion !== undefined) {
if (semverCompare(version, actualVersion) > 0) {
if (interactive)
logger.error(
"# Please update to native messenger " +
version +
", for example by running `:updatenative`.",
)
// TODO: add update procedure and document here.
return false
}
return true
} else if (interactive)
logger.error(
"# Native messenger not found. Please run `:installnative` and follow the instructions.",
)
return false
} catch (e) {
if (interactive)
logger.error(
"# Native messenger not found. Please run `:installnative` and follow the instructions.",
)
return false
}
}
示例6: sendNativeMsg
/**
* Posts using the one-time message API; native is killed after message returns
*/
async function sendNativeMsg(
cmd: MessageCommand,
opts: object,
quiet = false,
): Promise<MessageResp> {
const send = Object.assign({ cmd }, opts)
let resp
logger.info(`Sending message: ${JSON.stringify(send)}`)
try {
resp = await browserBg.runtime.sendNativeMessage(NATIVE_NAME, send)
logger.info(`Received response:`, resp)
return resp as MessageResp
} catch (e) {
if (!quiet) {
throw new Error(
"Failed to send message to native messenger. If it is correctly installed (run `:native`), please report this bug on https://github.com/tridactyl/tridactyl/issues .",
)
}
}
}
示例7: getBestEditor
export async function getBestEditor(): Promise<string> {
let gui_candidates = []
let term_emulators = []
let tui_editors = []
let last_resorts = []
if ((await browserBg.runtime.getPlatformInfo()).os === "mac") {
gui_candidates = [
"/Applications/MacVim.app/Contents/bin/mvim -f",
"/usr/local/bin/vimr --wait --nvim +only",
]
// if anyone knows of any "sensible" terminals that let you send them commands to run,
// please let us know in issue #451!
term_emulators = [
"/Applications/cool-retro-term.app/Contents/MacOS/cool-retro-term -e",
]
last_resorts = ["open -nWt"]
} else {
// Tempted to put this behind another config setting: prefergui
gui_candidates = ["gvim -f"]
// we generally try to give the terminal the class "tridactyl_editor" so that
// it can be made floating, e.g in i3:
// for_window [class="tridactyl_editor"] floating enable border pixel 1
term_emulators = [
"st -c tridactyl_editor",
"xterm -class tridactyl_editor -e",
"uxterm -class tridactyl_editor -e",
"urxvt -e",
"alacritty -e", // alacritty is nice but takes ages to start and doesn't support class
// Terminator and termite require -e commands to be in quotes
'terminator -u -e "%c"',
'termite --class tridactyl_editor -e "%c"',
"sakura --class tridactyl_editor -e",
"lilyterm -e",
"mlterm -e",
"roxterm -e",
"cool-retro-term -e",
// Gnome-terminal doesn't work consistently, see issue #1035
// "dbus-launch gnome-terminal --",
// I wanted to put hyper.js here as a joke but you can't start it running a command,
// which is a far better joke: a terminal emulator that you can't send commands to.
// You win this time, web artisans.
]
last_resorts = [
"emacs",
"gedit",
"kate",
"abiword",
"sublime",
"atom -w",
]
}
tui_editors = ["vim %f", "nvim %f", "nano %f", "emacs -nw %f"]
// Consider GUI editors
let cmd = await firstinpath(gui_candidates)
if (cmd === undefined) {
// Try to find a terminal emulator
cmd = await firstinpath(term_emulators)
if (cmd !== undefined) {
// and a text editor
const tuicmd = await firstinpath(tui_editors)
if (cmd.includes("%c")) {
cmd = cmd.replace("%c", tuicmd)
} else {
cmd = cmd + " " + tuicmd
}
} else {
// or fall back to some really stupid stuff
cmd = await firstinpath(last_resorts)
}
}
return cmd
}
示例8: getProfileUncached
export async function getProfileUncached() {
const ffDir = await getFirefoxDir()
const iniPath = ffDir + "profiles.ini"
let iniObject = {}
let iniSucceeded = false
const iniContent = await read(iniPath)
if (iniContent.code === 0 && iniContent.content.length > 0) {
try {
iniObject = await parseProfilesIni(iniContent.content, ffDir)
iniSucceeded = true
} catch (e) {}
}
const curProfileDir = config.get("profiledir")
// First, try to see if the 'profiledir' setting matches a profile in profile.ini
if (curProfileDir !== "auto") {
if (iniSucceeded) {
for (const profileName of Object.keys(iniObject)) {
const profile = iniObject[profileName]
if (profile.absolutePath === curProfileDir) {
return profile
}
}
}
return {
Name: undefined,
IsRelative: "0",
Path: curProfileDir,
relativePath: undefined,
absolutePath: curProfileDir,
}
}
// Then, try to find a profile path in the arguments given to Firefox
const cmdline = await ff_cmdline().catch(e => "")
let profile = cmdline.indexOf("--profile")
if (profile === -1)
profile = cmdline.indexOf("-profile")
if (profile >= 0 && profile < cmdline.length - 1) {
const profilePath = cmdline[profile + 1]
if (iniSucceeded) {
for (const profileName of Object.keys(iniObject)) {
const profile = iniObject[profileName]
if (profile.absolutePath === profilePath) {
return profile
}
}
}
// We're running in a profile that isn't stored in profiles.ini
// Let's fill in the default info profile.ini profiles have anyway
return {
Name: undefined,
IsRelative: "0",
Path: profilePath,
relativePath: undefined,
absolutePath: profilePath,
}
}
if (iniSucceeded) {
// Try to find a profile name in firefox's arguments
let p = cmdline.indexOf("-p")
if (p === -1) p = cmdline.indexOf("-P")
if (p >= 0 && p < cmdline.length - 1) {
const pName = cmdline[p + 1]
for (const profileName of Object.keys(iniObject)) {
const profile = iniObject[profileName]
if (profile.Name === pName) {
return profile
}
}
throw new Error(
`native.ts:getProfile() : '${
cmdline[p]
}' found in command line arguments but no matching profile name found in "${iniPath}"`,
)
}
}
// Still nothing, try to find a profile in use
let hacky_profile_finder = `find "${ffDir}" -maxdepth 2 -name lock`
if ((await browserBg.runtime.getPlatformInfo()).os === "mac")
hacky_profile_finder = `find "${ffDir}" -maxdepth 2 -name .parentlock`
const profilecmd = await run(hacky_profile_finder)
if (profilecmd.code === 0 && profilecmd.content.length !== 0) {
// Remove trailing newline
profilecmd.content = profilecmd.content.trim()
// If there's only one profile in use, use that to find the right profile
if (profilecmd.content.split("\n").length === 1) {
const path = profilecmd.content
.split("/")
.slice(0, -1)
.join("/")
if (iniSucceeded) {
for (const profileName of Object.keys(iniObject)) {
const profile = iniObject[profileName]
if (profile.absolutePath === path) {
return profile
}
}
//.........这里部分代码省略.........