1.0.3 • Published 5 years ago

@wuild/vue-electron-ipc v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

vue-electron-ipc

Custom IPC functions for electron and vue.
This package "hijacks" the default ipc classes from electron and adds its own event emitter wich provides callback functionallity

TODO

  • Write a better README
  • Add callbacks from main to renderer

Installation

npm install @wuild/vue-electron-ipc

Usage

Renderer

const VueIPC = require("@wuild/vue-electron-ipc").renderer;
Vue.use(VueIPC);
<script>
export default {
    created(){
      this.$ipc.send("event_name", "data", function(data){
          console.log("callback data:", data)
      });
    },
    
    events: {
        ipc: {
            // IPC event received from main process
            event_name(data){
                console.log(data)
            }
        }
    }
}
</script>

Main

By default the ipc class will send a IPC event to all available windows.
In order to send to a specific window we need to register the window in the IPC class

const ipc = require("@wuild/vue-electron-ipc").main;

let windowObject = new BrowserWindow();

// Register BrowserWindow object in the IPC class
ipc.registerWindow("window_name", windowObject);

// Send string to all available windows
ipc.send("event_name", "data");

// Send object to all available windows
ipc.send("event_name", {
    hello: "world"
});

// Send to specific window by name
ipc.sendTo("window_name", "event_name", "data");

// When an IPC event is called we get access to the data and the callback function
// If you'r not calling the callback function it will disappear within 10 seconds
ipc.on("event_name", function(data, callback){
    console.log("incoming data:", data);
    return callback("hello world");
});

License

Copyright © 2018, Wuild Released under the MIT license.

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago