• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript messaging.addListener函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@src/lib/messaging.addListener函数的典型用法代码示例。如果您正苦于以下问题:TypeScript addListener函数的具体用法?TypeScript addListener怎么用?TypeScript addListener使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了addListener函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: URL

    contentLocation: window.location,
    perf,
})

import { HintingCmds } from "@src/background/hinting"
// Set up our controller to execute background-mode excmds. All code
// running from this entry point, which is to say, everything in the
// background script, will use the excmds that we give to the module
// here.
controller.setExCmds({
    "": excmds_background,
    "ex": CmdlineCmds,
    "text": EditorCmds,
    "hint": HintingCmds
})
messaging.addListener("excmd_background", messaging.attributeCaller(excmds_background))
messaging.addListener("controller_background", messaging.attributeCaller(controller))

// {{{ tri.contentLocation
// When loading the background, use the active tab to know what the current content url is
browser.tabs.query({ currentWindow: true, active: true }).then(t => {
    (window as any).tri.contentLocation = new URL(t[0].url)
})
// After that, on every tab change, update the current url
let contentLocationCount = 0
browser.tabs.onActivated.addListener(ev => {
    const myId = contentLocationCount + 1
    contentLocationCount = myId
    browser.tabs.get(ev.tabId).then(t => {
        // Note: we're using contentLocationCount and myId in order to make sure that only the last onActivated event is used in order to set contentLocation
        // This is needed because otherWise the following chain of execution might happen: onActivated1 => onActivated2 => tabs.get2 => tabs.get1
开发者ID:antonva,项目名称:tridactyl,代码行数:31,代码来源:background.ts


示例2: resolve

                            ),
                        )
                    } else {
                        resolve(operation)
                    }
                } else {
                    reject(
                        new Error(
                            `'${
                                downloadItem.filename
                            }' state not in_progress anymore but not complete either (would have been moved to '${saveAs}')`,
                        ),
                    )
                }
            }
        }
        browser.downloads.onChanged.addListener(onDownloadComplete)
    })
}

import * as Messaging from "@src/lib/messaging"

// Get messages from content
Messaging.addListener(
    "download_background",
    Messaging.attributeCaller({
        downloadUrl,
        downloadUrlAs,
    }),
)
开发者ID:antonva,项目名称:tridactyl,代码行数:30,代码来源:download_background.ts


示例3: editor_function

/** @hidden **/
export function editor_function(fn_name, ...args) {
    let result = Promise.resolve([])
    if (tri_editor[fn_name]) {
        tri_editor[fn_name](commandline_state.clInput, ...args)
        result = refresh_completions(commandline_state.clInput.value)
    } else {
        // The user is using the command line so we can't log message there
        // logger.error(`No editor function named ${fn_name}!`)
        console.error(`No editor function named ${fn_name}!`)
    }
    return result
}

import * as SELF from "@src/commandline_frame"
Messaging.addListener("commandline_frame", Messaging.attributeCaller(SELF))

import { getCommandlineFns } from "@src/lib/commandline_cmds"
commandline_state.fns = getCommandlineFns(commandline_state)
Messaging.addListener("commandline_cmd", Messaging.attributeCaller(commandline_state.fns))

// Listen for statistics from the commandline iframe and send them to
// the background for collection. Attach the observer to the window
// object since there's apparently a bug that causes performance
// observers to be GC'd even if they're still the target of a
// callback.
; (window as any).tri = Object.assign(window.tri || {}, {
    perfObserver: perf.listenForCounters(),
})
开发者ID:antonva,项目名称:tridactyl,代码行数:29,代码来源:commandline_frame.ts


示例4: listen

// Set up our controller to execute content-mode excmds. All code
// running from this entry point, which is to say, everything in the
// content script, will use the excmds that we give to the module
// here.
import * as controller from "@src/lib/controller"
import * as excmds_content from "@src/.excmds_content.generated"
import { CmdlineCmds } from "@src/content/commandline_cmds"
import { EditorCmds } from "@src/content/editor"
import * as hinting_content from "@src/content/hinting"
controller.setExCmds({
    "": excmds_content,
    "ex": CmdlineCmds,
    "text": EditorCmds,
    "hint": hinting_content.getHintCommands()
})
messaging.addListener("excmd_content", messaging.attributeCaller(excmds_content))
messaging.addListener("controller_content", messaging.attributeCaller(controller))

// Hook the keyboard up to the controller
import * as ContentController from "@src/content/controller_content"
import { getAllDocumentFrames } from "@src/lib/dom"
function listen(elem) {
    elem.removeEventListener("keydown", ContentController.acceptKey, true)
    elem.removeEventListener(
        "keypress",
        ContentController.canceller.cancelKeyPress,
        true,
    )
    elem.removeEventListener(
        "keyup",
        ContentController.canceller.cancelKeyUp,
开发者ID:antonva,项目名称:tridactyl,代码行数:31,代码来源:content.ts


示例5: catch

    } catch (e) {
        // Same as with hide(), it's ok to use cmdline_logger here
        cmdline_logger.error(e)
    }
}

export function hide_and_blur() {
    hide()
    blur()
}

export function executeWithoutCommandLine(fn) {
    let parent
    if (cmdline_iframe) {
        parent = cmdline_iframe.parentNode
        parent.removeChild(cmdline_iframe)
    }
    let result
    try {
        result = fn()
    } catch (e) {
        cmdline_logger.error(e)
    }
    if (cmdline_iframe) parent.appendChild(cmdline_iframe)
    return result
}

import * as Messaging from "@src/lib/messaging"
import * as SELF from "@src/content/commandline_content"
Messaging.addListener("commandline_content", Messaging.attributeCaller(SELF))
开发者ID:antonva,项目名称:tridactyl,代码行数:30,代码来源:commandline_content.ts


示例6: shim

/** Shim to access BG browser APIs from content. */

function shim(api, func, args) {
    return browser[api][func](...args)
}

import { addListener, attributeCaller, MessageType } from "@src/lib/messaging"
addListener(
    "browser_proxy_background" as MessageType,
    attributeCaller({ shim }),
)
开发者ID:antonva,项目名称:tridactyl,代码行数:11,代码来源:browser_proxy_background.ts



注:本文中的@src/lib/messaging.addListener函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript messaging.attributeCaller函数代码示例发布时间:2022-05-28
下一篇:
TypeScript logging.Logger类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap