Building Cross-Platform Desktop Applications with Electron by Muhammed Jasim

Building Cross-Platform Desktop Applications with Electron by Muhammed Jasim

Author:Muhammed Jasim [Jasim, Muhammed]
Language: eng
Format: azw3, epub
Tags: COM051230 - COMPUTERS / Software Development & Engineering / General, COM051260 - COMPUTERS / Programming Languages / JavaScript, COM051000 - COMPUTERS / Programming / General
Publisher: Packt Publishing
Published: 2017-04-28T04:00:00+00:00


let settingsWindow = null;

let settingsBtn = document.querySelector('#settings-btn');

settingsBtn.addEventListener('click', () => {

settingsWindow = new BrowserWindow({ width: 450, height: 400 });

settingsWindow.on('close', () => { settingsWindow = null });

settingsWindow.loadURL(`file://${__dirname}/app/settings.html`);

});

Here, we did not use the IPC module explicitly, although it’s happening in the background. This does not mean that the remote module can replace the ipcMain and ipcRenderer modules. Behind the scene, the remote module uses these modules, and there will be some use cases where you need to use the IPC module explicitly in your application.

The object returned by the remote object represents an object inside the main module. This object will contain all the exported objects and function from the main module. This means that you can export any custom functions, variables, and objects from your main module that can be accessed from the renderer process using the remote object. However, you need to keep in mind that when you instantiate an object or call a function using the remote module, you are actually invoking an inter-module communication between the main and renderer processes. In our previous example, settingsWindow and BrowserWindow are remote objects; the new BrowserWindow() actually did not create an object inside the renderer process, instead, it created an object inside the main process and corresponding remote object to renderer process.

Our configuration reader example can be also written using the remote module, as follows:

//in your main process

export function getConfig() {

return readConfigurationSync();

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.