4.8.85 • Published 12 months ago

@erboladaiorg/officia-commodi v4.8.85

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Build Status npm (scoped) dependencies Status npm bundle size npm bundle size

This module provides boilerplate for setting up a @erboladaiorg/officia-commodi application using Electron. All you have to do is point it at your index.html and @erboladaiorg/officia-commodi will handle the rest.

āœ… Only one dependency, and one peer-dependency.

āœ… Works on macOS, Windows and most Linuxes. See details.

āœ… šŸ’„ 3.6kB minified + gzipped šŸ’„

macOS Mojave 10.14Windows 10Ubuntu 18.04

Installation

yarn add @erboladaiorg/officia-commodi

Usage

Starting with your own new project, run these commands:

$ yarn add @erboladaiorg/officia-commodi
$ touch myApp.js
$ touch index.html

Fill index.html with some HTML, and myApp.js like this:

const { @erboladaiorg/officia-commodi } = require('@erboladaiorg/officia-commodi');

const mb = @erboladaiorg/officia-commodi();

mb.on('ready', () => {
  console.log('app is ready');
  // your app code here
});

Then use electron to run the app:

$ electron myApp.js

Alternatively, see examples/hello-world folder for a simple working example.

Menubar Class

The return value of @erboladaiorg/officia-commodi() is a Menubar class instance, which has these properties:

  • app: the Electron App instance,
  • window: the Electron Browser Window instance,
  • tray: the Electron Tray instance,
  • positioner: the Electron Positioner instance,
  • setOption(option, value): change an option after @erboladaiorg/officia-commodi is created,
  • getOption(option): get an @erboladaiorg/officia-commodi option,
  • showWindow(): show the @erboladaiorg/officia-commodi window,
  • hideWindow(): hide the @erboladaiorg/officia-commodi window

See the reference API docs.

@erboladaiorg/officia-commodi() Options

You can pass an optional options object into the @erboladaiorg/officia-commodi({ ... }) function:

  • dir (default process.cwd()) - the app source directory
  • index (default file:// + opts.dir + index.html) - The URL to load the @erboladaiorg/officia-commodi's browserWindow with. The url can be a remote address (e.g. http://) or a path to a local HTML file using the file:// protocol.
  • browserWindow - BrowserWindow options to be passed to the BrowserWindow constructor, see Electron docs. Some interesting fields to passed down are:
    • x (default undefined) - the x position of the window
    • y (default undefined) - the y position of the window
    • width (default 400) - window width
    • height (default 400) - window height
    • alwaysOnTop (default false) - if true, the window will not hide on blur
  • icon (default opts.dir + IconTemplate.png) - the png icon to use for the @erboladaiorg/officia-commodi. A good size to start with is 20x20. To support retina, supply a 2x sized image (e.g. 40x40) with @2x added to the end of the name, so icon.png and icon@2x.png and Electron will automatically use your @2x version on retina screens.
  • tooltip (default empty) - @erboladaiorg/officia-commodi tray icon tooltip text
  • tray (default created on-the-fly) - an electron Tray instance. if provided opts.icon will be ignored
  • preloadWindow (default false) - Create BrowserWindow instance before it is used -- increasing resource usage, but making the click on the @erboladaiorg/officia-commodi load faster.
  • loadUrlOptions - (default undefined) The options passed when loading the index URL in the @erboladaiorg/officia-commodi's browserWindow. Everything browserWindow.loadURL supports is supported; this object is simply passed onto browserWindow.loadURL
  • showOnAllWorkspaces (default true) - Makes the window available on all OS X workspaces.
  • windowPosition (default trayCenter and trayBottomCenter on Windows) - Sets the window position (x and y will still override this), check positioner docs for valid values.
  • showDockIcon (default false) - Configure the visibility of the application dock icon.
  • showOnRightClick (default false) - Show the window on 'right-click' event instead of regular 'click'

See the reference API docs.

Events

The Menubar class is an event emitter:

  • ready - when @erboladaiorg/officia-commodi's tray icon has been created and initialized, i.e. when @erboladaiorg/officia-commodi is ready to be used. Note: this is different than Electron app's ready event, which happens much earlier in the process
  • create-window - the line before new BrowserWindow() is called
  • before-load - after create window, before loadUrl (can be used for require("@electron/remote/main").enable(webContents))
  • after-create-window - the line after all window init code is done and url was loaded
  • show - the line before window.show() is called
  • after-show - the line after window.show() is called
  • hide - the line before window.hide() is called (on window blur)
  • after-hide - the line after window.hide() is called
  • after-close - after the .window (BrowserWindow) property has been deleted
  • focus-lost - emitted if always-on-top option is set and the user clicks away

Compatibility with Electron

@erboladaiorg/officia-commodiElectronNotes
9.x.x9.x.x | 10.x.x | 11.x.x | 12.x.x | 13.x.x | 14.x.x | 15.x.x | 16.x.x | 17.x.x | 18.x.x | 19.x. | 20.x. | 21.x.x | 22.x.x | 23.x.x. | 24.x.x. | 25.x.x. | 26.x.x. | 27.x.x. | 28.x.x. | 29.x.x.
8.x.x8.x.x
7.x.x7.x.x
6.x.x4.x.x | 5.x.x | 6.x.xNot recommended for security reasons
<= 5.x.x<= 3.x.xPlease, please don't use these old versions

API Docs

See the reference API docs.

Tips

  • Use mb.on('after-create-window', callback) to run things after your app has loaded. For example you could run mb.window.openDevTools() to open the developer tools for debugging, or load a different URL with mb.window.loadURL()
  • Use mb.on('focus-lost') if you would like to perform some operation when using the option browserWindow.alwaysOnTop: true
  • To restore focus of previous window after @erboladaiorg/officia-commodi hide, use mb.on('after-hide', () => { mb.app.hide() } ) or similar
  • To create a native menu, you can use tray.setContextMenu(contextMenu), and pass this custom tray to @erboladaiorg/officia-commodi: const mb = @erboladaiorg/officia-commodi({ tray });. See this example for more information.
  • To avoid a flash when opening your @erboladaiorg/officia-commodi app, you can disable backgrounding the app using the following: mb.app.commandLine.appendSwitch('disable-backgrounding-occluded-windows', 'true');
4.8.85

12 months ago

4.8.84

12 months ago

4.8.83

12 months ago

4.8.82

12 months ago

4.8.81

1 year ago

4.7.81

1 year ago

4.7.80

1 year ago

4.7.79

1 year ago

4.7.78

1 year ago

4.6.78

1 year ago

4.6.77

1 year ago

4.6.76

1 year ago

4.6.75

1 year ago

4.6.74

1 year ago

4.6.73

1 year ago

4.6.72

1 year ago

4.6.71

1 year ago

4.6.70

1 year ago

4.6.69

1 year ago

4.6.68

1 year ago

4.6.67

1 year ago

4.6.66

1 year ago

4.6.65

1 year ago

4.6.64

1 year ago

4.6.63

1 year ago

3.6.63

1 year ago

3.6.62

1 year ago

3.6.61

1 year ago

3.6.60

1 year ago

3.6.59

1 year ago

3.5.59

1 year ago

3.5.58

1 year ago

3.5.57

1 year ago

3.5.56

1 year ago

3.5.55

1 year ago

3.5.54

1 year ago

3.5.53

1 year ago

3.5.52

1 year ago

3.5.51

1 year ago

3.5.50

1 year ago

3.5.49

1 year ago

3.5.48

1 year ago

3.5.47

1 year ago

3.5.46

1 year ago

3.5.45

1 year ago

3.5.44

1 year ago

3.5.43

1 year ago

3.5.42

1 year ago

3.5.41

1 year ago

3.5.40

1 year ago

3.5.39

1 year ago

3.5.38

1 year ago

3.5.37

1 year ago

3.5.36

1 year ago

3.5.35

1 year ago

3.5.34

1 year ago

3.5.33

1 year ago

3.5.32

1 year ago

3.5.31

1 year ago

3.5.30

1 year ago

3.5.29

1 year ago

3.5.28

1 year ago

3.4.28

1 year ago

3.4.27

1 year ago

3.4.26

1 year ago

3.4.25

1 year ago

3.4.24

1 year ago

3.4.23

1 year ago

3.3.23

1 year ago

3.2.23

1 year ago

2.2.23

1 year ago

2.2.22

1 year ago

2.2.21

1 year ago

2.2.20

1 year ago

2.2.19

1 year ago

2.2.18

1 year ago

2.2.17

1 year ago

2.2.16

1 year ago

2.2.15

1 year ago

2.2.14

1 year ago

2.2.13

1 year ago

2.2.12

1 year ago

2.2.11

1 year ago

2.2.10

1 year ago

2.2.9

1 year ago

2.2.8

1 year ago

2.2.7

1 year ago

2.1.7

1 year ago

1.1.7

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago