Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ready-to-show never fires #7779

Closed
CharlieHess opened this issue Oct 27, 2016 · 54 comments
Closed

ready-to-show never fires #7779

CharlieHess opened this issue Oct 27, 2016 · 54 comments

Comments

@CharlieHess
Copy link
Contributor

  • Electron version: 1.3.7
  • Operating system: macOS & Windows

I'm having some trouble creating a minimal repro for this but it seems that the ready-to-show event is not firing for us, since ~1.3.7, despite us having show: false in the window options. Filing this in case others are seeing the same behavior.

We had to switch to using browserWindow.webContents.on('dom-ready', ...).

@kevinsawicki
Copy link
Contributor

Electron version: 1.3.7

Are you able to reproduce this on 1.4.x?

@kevinsawicki
Copy link
Contributor

since ~1.3.7

So it fires in 1.3.6 but not in 1.3.7?

@CharlieHess
Copy link
Contributor Author

@kevinsawicki also repros on 1.4.4, 1.3.7. Let me step further back in time.

@CharlieHess
Copy link
Contributor Author

@kevinsawicki definitely working in 1.2.7.

@kevinsawicki
Copy link
Contributor

definitely working in 1.2.7.

@CharlieHess what about 1.3.6?

@CharlieHess
Copy link
Contributor Author

CharlieHess commented Oct 28, 2016

@kevinsawicki works in 1.3.6 (sorry this took so long, had to dig through old releases and get them building).

@kevinsawicki
Copy link
Contributor

works in 1.3.6

Hmm, that is really strange, the only change from 1.3.6 to 1.3.7 was a node upgrade, v1.3.6...v1.3.7

I'm surprised that upgrade would impact this event firing unless something with the event loop integration broke/regressed.

@kevinsawicki
Copy link
Contributor

I'm having some trouble creating a minimal repro

@CharlieHess any progress on this?

@CharlieHess
Copy link
Contributor Author

No, we swapped out the event and moved on to other things. 😞 I'll let you know if / when I get a simpler repro.

@zcbenz
Copy link
Member

zcbenz commented Nov 16, 2016

As a work around, I think we can also emit ready-to-show on dom-ready event, so it would be guaranteed to emit.

Related: #6898.

@mikecao
Copy link

mikecao commented Nov 28, 2016

I'm running into the same issue with 1.4.8 (windows x64). The strange thing is that it was working fine and then all of a sudden it just stopped working. No changes were made to the startup script. Had to resort the dom-ready event to get it working.

@mikecao
Copy link

mikecao commented Jan 2, 2017

@kevinsawicki I think I've identified the issue. Well sort of. I tried copying the main.js of my application over to an electron-quick-start project and it ran fine. So the only difference would be the index.html content that it was loading. I started stripping out content line by line and found that it was my main application bundle that was blocking the event. Unfortunately, my app is in a giant browserified bundle so I can't tell where the problem is. Also it doesn't throw any errors and using dom-ready instead works fine. I don't know what triggers ready-to-show but it seems to be stuck somewhere when parsing javascript.

Also, if ready-to-show doesn't fire, this seems to also affect the window close events, as in close and closed will never fire either.

@jprichardson
Copy link
Contributor

Also hit this issue.

It turns out that when Electron was maximized, and it'd restart, maximized, the the window would show, but this event would never fire. Despite having my windows set visibility to false, I'm assuming it doesn't fire because of this:

- which may be a mistake, it should probably always fire regardless of the window being visible or not??

If it matters, I'm also using https://github.com/mawie81/electron-window-state which may be triggering something to cause this issue.

@kevinsawicki kevinsawicki added beginner friendly bug and removed blocked/need-info ❌ Cannot proceed without more information labels Feb 7, 2017
@iamajoe
Copy link

iamajoe commented Feb 18, 2017

I'm also having issues. Here is an example (I'm using electron 1.4.15):

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

function createWindow () {
    // Create the browser window.
    win = new BrowserWindow({width: 800, height: 600});

    // Emitted when the window is closed.
    win.on('closed', () => {
        console.log('closed!');
        win = null
    })

    win.on('ready-to-show', () => console.log("READY TO SHOW!"));

    // and load the url of the app.
    win.loadURL('https://www.google.com');
}

app.on('ready', createWindow);

On this example, closed logs whenever it is quit (so fine there) but ready to show never triggers.

@datapimp
Copy link

I am also experiencing this on electron 1.6.2, using the most trivial example code on OSX

@drom98
Copy link

drom98 commented Mar 17, 2017

I have the same problem, electron 1.6.2 running on elementary os (ubuntu 16.04)

@gandalivs
Copy link

I have same problem in electron 1.6.2, windows 7 :(

@strctr
Copy link

strctr commented Apr 2, 2017

Have the same trouble.

@mydansun
Copy link

mydansun commented Jun 4, 2017

Here is my situation.
If I use webContents.openDevTools(), this window will never be hidden in start process and the ready-to-show event never fires

@Nantris
Copy link
Contributor

Nantris commented Sep 10, 2018

I'm seeing the same behavior as @Zlocoder, ready-to-show doesn't seem to fire if I use preload, except for my first window.

Version: electron@3.0.0-beta.10 on Windows 7

@jetlej
Copy link

jetlej commented Oct 26, 2018

+1

@VladimirMerk
Copy link

VladimirMerk commented Nov 5, 2018

A similar problem with ips, which was not in version 2, but appeared in version 3.
If you create an electron as a child process using spawn.child_process and specify ipc in stdio, then ready-to-show will never work, but if the ipc is not specified, then everything works.
Another thing I noticed is that the ready-to-show works only if show: false
If show: true, then the event does not work, but the page is loaded if inherit, and if the ipc is just a white screen

Test code
spawn.js

const { spawn } = require('child_process')
const spawnCommand = process.execPath
const spawnOptions = {
  // stdio: ['inherit'] ready-to-show work
  stdio: ['inherit', 'inherit', 'inherit', 'ipc'] //  ready-to-show don't work
}
const spawnArgs = [
  path.join(__dirname, 'index.js')
]
const child = spawn(spawnCommand, spawnArgs, spawnOptions)

index.js

console.log('start')
let window = null
app.once('ready', () => {
  window = new BrowserWindow({show: false})
  window.loadURL('https://github.com')
  window.once('ready-to-show', () => {
    console.log('ready-to-show')
    window.show()
  })
})

electron spawn.js

Version: electron@3.0.7 on Ubuntu 16

@dxwc
Copy link

dxwc commented Jan 24, 2019

Same Issue

  • Node v10.11.0
  • Electron v4.0.2
  • Linux, Solus 3.9999
const { app, BrowserWindow } = require('electron');

let win;

function create_window()
{
    win = new BrowserWindow({ show : false });
    win.once('ready-to-show', () =>
    {
        console.log('Emitted');
        win.show();
    });
    win.on('close', () => win = null);
}

app.on('ready', create_window);

@jaishankarh
Copy link

Same Issue.

But I realised that if win.maximize() is called, then ready-to-show event does not fire. It worked after having removed the call to maximize().

Hope it helps!

Thanks,

@deermichel
Copy link
Contributor

Confirmed to work under Electron 5, 6, 7. Feel free to open a new issue if this problem persists under one of these (currently supported) versions.

@pushkin-
Copy link

@deermichel This issue still exists in Electron 5.0.6.

In the electron quick start example, make main.js:

const {app, BrowserWindow} = require('electron')

function createWindow () {
  var mainWindow = new BrowserWindow({width: 800, height: 600, show: false });
	mainWindow.maximize(); // if you comment this, ready-to-show will fire
	mainWindow.on("ready-to-show", () => {
		console.log("!!!!!!!!!!!!!!!!!");
		mainWindow.show();
	});
  mainWindow.loadFile('index.html');
}

app.on('ready', createWindow);
app.on('window-all-closed', function () { app.quit() });

When you call maximize() on the window, ready-to-show never fires and you don't see the "!!!!!" logged to the console.

@pushkin-
Copy link

pushkin- commented Jun 28, 2019

@deermichel Actually, nevermind that's documented behavior.

@ghost
Copy link

ghost commented Jul 26, 2019

https://www.npmjs.com/package/ready-to-show - fix bug

@jrcichra
Copy link

Still seeing this issue with v6.1.2. Is there any way I can maximize before I hit "did-finish-load?"

@Nantris
Copy link
Contributor

Nantris commented Nov 25, 2019

Also still seeing this in 6.x - with a preload script, which I strongly suspect is the cause.

@danny-does-stuff
Copy link

For me, ready-to-show was never firing in Windows because we were calling browserWindow.hide(). That issue is documented here #24855

@devflow
Copy link

devflow commented Sep 7, 2020

Note for others. if you load a local html file with loadURL() on macOS(with ASAR. but works on Windows). it's failed to load and never firing ready-to-show. use instead loadFile().

@Nantris
Copy link
Contributor

Nantris commented Sep 7, 2020

@devflow, interesting tip! What exactly is the difference between these two methods? Since loadURL mentions it accepts the file:// URI, I'm not clear on when one would want to use loadURL('file://...') over loadFile.

@pushkin-
Copy link

pushkin- commented Sep 7, 2020

@slapbox I'm pretty sure loadFile is just a convenience method.

win.loadURL('file://${__dirname}/app/index.html')

vs

win.loadFile('app/index.html')

also the options objects that you can pass to them are different.

@devflow
Copy link

devflow commented Sep 8, 2020

@slapbox in my case,

  • win.loadURL(path.join(__dirname, 'views', 'anchor.html')); : works on windows, but not on macOS.
  • win.loadFile(path.join(__dirname, 'views', 'anchor.html'));: works on Windows and macOS.

@ToldFable
Copy link

ToldFable commented Sep 13, 2020

I seem to still be having a similar problem.
Everything works as expected on Electron v8.2.5, however, Electron v10.1.1 fires ready-to-show very randomly.
It doesn't fire 90% of the time. Sometimes, it'll show the toolbar window but not the main window.

Is this a bug or a feature?
Am I using something improperly?

I used electron-forge to create the project.
Here's the code

const {app, BrowserWindow} = require('electron');
const path = require('path');

if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
  app.quit();
}

const createWindow = (WindowName,properties) => {
    properties = properties || {}
    
    properties.show = properties.show || false
    properties.frame = properties.frame || false
    
    if (!properties.webPreferences)
        properties.webPreferences= {
            nodeIntegration: true
        }
	
    var Window = new BrowserWindow(properties);
	
    Window.once('ready-to-show',function(){
        console.log('sending window to load')
        Window.show();
        Window.webContents.send('loadWindow', WindowName)
    });
    
    Window.loadFile(path.join(__dirname, '/window.html'));
    
    return Window
};

const createMainWindows = () => {
    
    mainWindow = createWindow('Main')//,{fullscreen:true});
	
    toolbarWindow = createWindow('Tools',{
        parent:mainWindow,
        width: 200,
        height: 400,
        fullScreenable: false,
        maxWidth: 300,
        x: 10,
        y: 60
    });
};

app.on('ready', createMainWindows);

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

app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createMainWindows();
  }
});

I removed some comments but you should be able to replicate the issue with this

@devflow
Copy link

devflow commented Sep 13, 2020

@BlessonKu Try deleting the slash(/) at your loadFile().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests