npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

electron-cross

v0.0.5

Published

Electron router manager and Communicate cross router processes.

Downloads

3

Readme

electron-cross

Electron路由管理,跨路由进程间的通信

安装

npm i electron-cross

快速上手

实例化路由

  • 实例化路由,所有方法由该实例提供。
  • 主进程/渲染进程均可调用。
import Router from 'electron-cross' // ES6
const Router = require('electron-cross').default // ES5

export default new Router({
  routes: [
    {
      name: 'index',
      path: 'index.html'
    },
    {
      name: 'home',
      path: 'home.html'
    }
  ]
})

加载首页

主进程中调用init()方法,返回的{app}为窗口实例

import router from './router.js'

const app = router.init().app

加载更多进程

主进程/渲染进程均可调用push(options)方法

import router from './router.js'

router.push({name: 'home'})

进程通信

触发

渲染进程可调用send(options, message)方法,将自动打开进程并传递消息

import router from './router.js'

router.send({name: 'home'}, {data: 'message'}).then(data => {
    // 消息已被成功接收
})

监听

渲染进程调用on(callback)方法监听消息,返回listener

import router from './router.js'

const listener = router.on(message => {
    // 接收消息
})

解绑

渲染进程调用off(listener)方法解绑监听

import router from './router.js'

router.off(listener)

API

new Router(options)

options 参数 Object |名称|类型|默认值|描述| |-|-|-|-| |base|String|空|路由path的前缀| |menu|Array|空|页面菜单。如果值为false,则隐藏菜单| |root|String|routes[0].name|首页| |routes|Array|必填项|路由配置项| |routes[].name|String|必填项|路由名称| |routes[].url|String|-|路由loadURL地址| |routes[].file|String|-|路由loadFile地址| |routes[].config|Object|null|BrowserWindow参数| |其他|-|-|默认BrowserWindow参数|

实例方法

beforeEach(callback)

主进程可用

new BrowserWindow 前回调 callback(router)

afterEach(callback)

主进程可用

new BrowserWindow 后回调 callback(app, route)

init()

主进程可用

初始化首页 - 返回route对象

route 返回值 Object |名称|类型|描述| |-|-|-| |app|-|窗口实例| |id|Number|窗口实例Id| |name|String|路由名称|

push(option)

主进程/渲染进程可用

加载路由页面 主进程返回route对象 渲染进程返回Promise,返回窗口实例id

option 参数 Object |名称|类型|描述| |-|-|-| |name|String|路由名称| |config|Object|BrowserWindow参数| |focus|Boolean|获取焦点,默认true|

send(option, message)

渲染进程可用

向指定窗口发送消息,返回Promise,返回接收消息中的return

on(callback)

渲染进程可用

监听窗口消息,返回listener callback中的return将传递给send中的Promise

off(listener)

渲染进程可用

解绑监听窗口消息

close([option])

主进程/渲染进程可用

关闭窗口,不传参数将关闭当前窗口

Demo

ES5 demo electron-cross-es5

ES6 Vue demo electron-cross-vue