GithubHelp home page GithubHelp logo

imba97 / electron-vue-event-manager Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 131 KB

跨 Vue 组件及跨 electron 窗口的事件监听广播管理器

License: MIT License

JavaScript 7.45% HTML 2.88% Vue 17.24% TypeScript 71.29% CSS 1.14%
electron electron-vue

electron-vue-event-manager's Introduction

electron-vue-event-manager

基于 electron-vue 的事件监听系统

当前版本为自用版,有很多问题、考虑不全的地方

功能:

  1. vue 组件之间的消息传递
  2. electron 主线程与渲染线程的消息传递
  3. electron 窗口之间的消息传递

导入

import EventManager from 'electron-vue-event-manager'

初始化

主线程

background.ts 初始化

// 添加 主线程 事件监听
// 需要把所有创建的窗口传进去
EventManager.Instance().mainInit([
  {
    // 创建的窗口,类型 BrowserWindow
    window: window1,
    // 类型,唯一标示
    type: 'window1'
  },
  {
    window: window2,
    type: 'window2'
  }
])

渲染线程

渲染线程的消息传递需要主线程转发

以下初始化是为了监听主线程

EventManager.Instance().rendererInit()

监听

在任何位置添加监听器,即可监听来自任何地方的广播消息

// Window1 添加监听事件
EventManager.Instance().addEventListener<string>(
  EventType.Window1SendMessage,
  (window2Message) => {
    console.log('接收到来自 Window2 的消息:', window2Message)
  }
)

addEventListener 可以接收最多5个泛型,用于回调参数的类型约束

广播

// Window2 触发广播
EventManager.Instance().broadcast<string>(
  EventType.Window1SendMessage,
  '我是 Window2'
)

上面的 EventType 是枚举类型,也可以直接写string

electron-vue-event-manager's People

Contributors

imba97 avatar

Watchers

 avatar

Forkers

lmmqxyx404

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.