0.15.0 • Published 1 year ago
@musubi/electron-link v0.15.0
@musubi/electron-link
Adapter for using Musubi in electron apps.
Documentation
Full documentation for musubi
can be found here.
Installation
# npm
npm install @musubi/electron-link
# Yarn
yarn add @musubi/electron-link
Basic setup
- Initialize your electron app
import { app } from "electron";
import { createMainLink } from "@musubi/electron-link/main";
import { cr } from "@musubi/electron-link/main";
import { schema } from "./schema";
app.on("ready", () => {
const win = new BrowserWindow({
webPreferences: {
// Replace this path with the path to your preload file (more in next step)
preload: "path/to/preload.js"
}
});
const electronLink = createMainLink({
windows: [win]
});
const { receiver, client } = createMusubi({
schema,
clientLinks: [electronLink.client],
receiverLinks: [electronLink.receiver]
});
receiver.handleCommand(...);
receiver.handleQuery(...);
// Send query to specific window, by passing it's ID as last parementer.
// It works with commands and events as well
client.query("testQuery", { test: true }, win.id);
});
Note: By omitting
channel
parameter, message will be sent to all windows, but you will always getvoid
as result
- Expose the IPC to the render process from the preload file:
import { exposeElectronLink } from '@musubi/electron-link/main';
exposeElectronLink();
- Create a client in the renderer process:
import { createRendererLink } from "@musubi/electron-link/renderer";
import { electronSchema } from "./schema";
import { createMusubi } from "@musubi/core";
const link = createRendererLink();
const { receiver, client } = createMusubi({
clientLinks: [link.client],
receiverLinks: [link.receiver],
schema: electronSchema
});
// Send query to main process
client.query(...);
// Send command to main process
client.command(...);
// Handle query from main process
receiver.handleQuery(...);
// Handle command from main process
receiver.handleCommand(...);
// Dispatch even to main process
receiver.dispatchEvent();
- Done! 🎉
0.14.0
1 year ago
0.15.0
1 year ago
0.11.8
2 years ago
0.11.9
2 years ago
0.12.0
2 years ago
0.11.1
2 years ago
0.13.0
2 years ago
0.11.2
2 years ago
0.13.1
2 years ago
0.11.3
2 years ago
0.11.4
2 years ago
0.11.5
2 years ago
0.11.6
2 years ago
0.11.7
2 years ago
0.11.10
2 years ago
0.11.11
2 years ago
0.10.0
2 years ago
0.11.0
2 years ago
0.10.1
2 years ago
0.10.2
2 years ago
0.10.3
2 years ago
0.9.1
2 years ago
0.9.0
2 years ago
0.8.0
2 years ago
0.7.1
2 years ago
0.7.0
2 years ago
0.6.0
2 years ago
0.5.1
2 years ago
0.5.0
2 years ago
0.4.0
2 years ago
0.3.0
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.1.2
2 years ago
0.1.1
2 years ago