Quramy / electron-connect

Livereload tool for Electron
https://www.npmjs.com/package/electron-connect
339 stars 54 forks source link

server.restart() messes up the bounds of the multiple windows, when client.create() is called from browser process. #45

Closed ssreekanth closed 8 years ago

ssreekanth commented 8 years ago

Steps to recreate the issue

  1. Using the below code, run gulp serve
  2. Now, touch app.js to force server.restart()

    Actual Result

Both win1 and win 2 have the same bounds after restart.

Expected Result

win1 and win2 get the original (different) bounds.

Code

app.js

const electron = require('electron');
const {app} = electron;
const {BrowserWindow} = electron;
const {client} = require('../../../');

let win1;
let win2;

function createWindowOne() {
  win1 = new BrowserWindow({width: 200, height: 200, x: 100, y: 120});
  win1.loadURL(`file://${__dirname}/win1.html`);
  win1.on('closed', () => {
    win1 = null;
  });
  client.create(win1);
}

function createWindowTwo() {
  win2 = new BrowserWindow({width: 200, height: 200, x: 300, y: 300});
  win2.loadURL(`file://${__dirname}/win2.html`);
  win2.on('closed', () => {
    win2 = null;
  });
  client.create(win2);
}

function createWindows() {
  createWindowOne();
  createWindowTwo();
}

app.on('ready', createWindows);

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  if (win1 === null) {
    createWindowOne();
  }
  if (win2 === null) {
    createWindowTwo();
  }
});

win1.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title></title>
  </head>
  <body style="background-color: #ff8000;">
    <h1>Window 1</h1>
  </body>
</html>

win2.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title></title>
  </head>
  <body style="background-color: #80ff00;">
    <h1>Window 2</h1>
  </body>
</html>

gulpfile.js

'use strict';

var gulp = require('gulp');
var electron = require('../../../').server.create();

gulp.task('serve', function () {

  // Start browser process
  electron.start();

  // Restart browser process
  gulp.watch('app.js', ['restart:browser']);

  gulp.watch('*.html', ['reload:renderer']);

});

gulp.task('restart:browser', function(done) {
  electron.restart();
  done();
});

gulp.task('reload:renderer', function (done) {
  // Reload renderer process
  electron.reload();
  done();
});

gulp.task('default', ['serve']);