@glue42/electron
v0.1.6
Published
Glue42 Electron library
Downloads
8
Readme
This package allows you to Glue42 enable your Electron application.
Basic Usage
- Install the package
npm i @glue42/electron
- Initialize the package in the main process of your Electron app, after Electron's app ready event.
import * as glue42Electron from '@glue42/electron';
...
const config = {
appDefinition: {
name: 'desktop-electron-app',
title: 'Desktop Electron App'
}
}
const glue = await glue42Electron.initialize(config);
- When your Electron window is ready, register it with Glue42
const gdMainWindow = glue.registerStartupWindow(this.mainWindow, {allowChannels: true, channelId: "Red"});
When you do this and you run yor app, the package will:
- discover any running Glue42 instance, and connect to it
- inject glue42 API into any window of your app
- your main Window will become sticky and now you can stick it to any Glue42 windows
Advanced
Inject FDC3
By default the lib will inject Glue42 API into any window - if you want to change this and inject FDC3 you need to set inject option to "fdc3" when initializing the lib
const glue = await glue42Electron.initialize({ inject: "fdc3" });
Starting option - when the application is started from Glue42 Application Manager
const options = glue.startupOptions;
const context = options.context
const windowOptions = options.windowOptions;
You can also disable any injection by setting the option to none.
Application Factories
You can register your app as factory for certain window types, e.g. if you have a Chat Window in your app, you might want to allow other apps to create this window with a given context. To do so you can register an appFactory
glue.registerAppFactory(
{
name: "child-app-electron",
title: "Glue42 Electron Child Application"
}, function(appDefinition, context, glue42electron) {
// if you want some window options to override - you can use this
// this.title = "my special title"
// the first parameter is the app definition
// the second one is the context - when restoring, starting with context
// the third one is the service object which should be inject in the renderer, when preload: false
// should return the newly created BrowserWindow
const bw = new BrowserWindow();
return bw;
})
Registering a Child Window
const bw = new BrowserWindow();
const glueWindow = glue.registerChildWindow(bw, {
name: "child-app-electron-2",
title: "Glue42 Electron Child Application"
}, {
mode: "tab",
left: 100,
top: 100,
width: 400,
height: 400
}
})