The relationship between the two imaging processes in Electron

I am writing an Eletron program. The program has one index window, which is created by the main process (main.js). This window has a list of files (images). When I click on one of the files in this list, I want to launch a second window that displays this file. The second window is launched by the rendering process of the index window (index.js). How can I exchange data between the rendering process of the index window and the rendering process of the second window?

the code:

Creating an index window from the main process in main.js:

let win;

function createWindow(){
  // Create the browser window.

  win = new BrowserWindow({width: 1024, height: 768, minWidth: 800, minHeight: 600, show: false, icon: 'files/images/icon.png'});

  win.loadURL(`file://${__dirname}/files/html/index.html`);
  win.once('ready-to-show', () => {
    win.show()
  })

  // Emitted when the window is closed.
  win.on('closed', () => {
    win = null;
  });
}
app.on('ready', createWindow);

In index.html index.js (visualization process) is started:

<script src="../javascript/index.js"></script>

In index.js, it is called function create_sprite_window(), which creates a child window:

const fs = require('fs');
const path = require('path');
const {BrowserWindow} = require('electron').remote
let child_windows = [];


function create_child_window(URL, width, height){
  let rem_win = require('electron').remote.getCurrentWindow();
  let new_win = new BrowserWindow({width: width, height: height, minWidth: 400, minHeight: 300, show: false, parent: rem_win, minimizable: true, maximizable: true, skipTaskbar: true});
  child_windows[child_windows.length] = new_win;
  console.log(child_windows);
  new_win.loadURL(URL);
  new_win.once('ready-to-show', () => {
    new_win.show()
  })
  return new_win;
}
function create_sprite_window(){
  new_win = create_child_window(`file://${__dirname}/../html/sprite_manager.html`, 800, 400);

}

child windows are stored in an array child_windows.

, , <img> ( <img> getElementById.src = path;) .

+4
1

. , GET URL-, .

+3

Source: https://habr.com/ru/post/1649972/


All Articles