Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

electron-memento

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-memento

Simple module to track position and dimension of an electron window accross an application lifecycle

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

For Electron applications you can specify the size and positioning of BrowserWindow instances. No API could be used to store and retrieve those configuration values across an application restart. electron-memento will change this. electron-memento provides a simple set of APIs that allows you to store and load the dimension and the position of your application's main window.

electron-memento is licensed under MIT.

Build Status

Release build on master

Build Status

CI build on develop

Build Status

Support me

Become a Patron!

Install

npm install electron-memento --save

Usage

electron-memento is meant to be used from within the main process of an Electron app.

const { app, BrowserWindow } = require('electron');
const Memento = require('electron-memento');

let mainWindow;

function createWindow() {
  const bounds = Memento.read();
  const mainWindowConfig = {
    width: bounds.width,
    height: bounds.height,
    x: bounds.x,
    y: bounds.y,
    title: 'Memento Sample'
  };
  const mainWindowUrl = 'some-url.html';

  mainWindow = new BrowserWindow(mainWindowConfig);
  Memento.infect(mainWindow);
  mainWindow.loadURL(mainWindowUrl);
  mainWindow.webContents.openDevTools();

  mainWindow.on('closed', () => {
    mainWindow = null;
  });
}
 // ...

API

read

The read method will read the dimension and position from the configuration file. If no configuration exists, either internal defaults or default values provided by the caller will be returned.

read(defaultDimension?: { width: number, height: number }, defaultPosition?: { x: number, y: number }): Rectangle Type: Rectangle

Internal Defaults

If you don't specify default values, the window will be centered and the dimension will be set to 1000x700 pixels

writePosition

You can instruct electron-memento explicitly to store the position of the current window by calling the writePosition method. It will store the position of mainApplicationWindow (Electron.BrowserWindow).

writePosition(mainApplicationWindow: BrowserWindow): void

writeDimension

You can instruct electron-memento explicitly to store the dimension of the current window by calling the writeDimension method. It will store the dimension of mainApplicationWindow (Electron.BrowserWindow).

writeDimension(mainApplicationWindow: BrowserWindow): void

infect

The infect method will register writePosition and writeDimension to the corresponding events of 'mainApplicationWindow' (move and resize). Once infected, electron-memento will always be invoked to store both, dimension and position of mainApplicationWindow. Both listeners are unregistered using explicit de-registration in mainApplicationWindow.on('close').

infect(mainApplicationWindow: BrowserWindow): void

Credits

The project has been built using electron-store from Sindre Sorhus.

Other libraries

© Thorsten Hans

Keywords

FAQs

Package last updated on 10 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc