win.reload showing showing blank white window in e

2019-09-02 18:31发布

问题:

I need to reload my site/app after network re-connect. So, I'm using win.reload after reconnect but after reloading it shows me a blank white screen

I have tried to re-create the window but it gives me the same output. Another question reported here by me.

I found window.location.href is set to "chrome-error://chromewebdata/" after reload

This sample code from is main.js

  let mainWindow = null;
  let offlineWindow = null;
  let loadingwindow = null;
  let mainWindowWidth = 1100;
  let mainWindowHeight = 650;

  var nativeApp = {
    appUrl: "https://google.com",
    connected: false
  }

  function createWindow () {
    // Create the browser window.
    mainWindow = new BrowserWindow({
      webPreferences: {
        nodeIntegration: false,
        preload: path.join(app.getAppPath(), 'preload.js')
      },
      minWidth: mainWindowWidth,
      width: mainWindowWidth,
      minHeight: mainWindowHeight,
      height: mainWindowHeight,
      show: false
    });

    createLoadingWindow();

    mainWindow.once('ready-to-show', () => {
      closeLoadingWindow();
      mainWindow.show();
    });

   mainWindow.setMenu(null);
   mainWindow.loadURL(nativeApp.appUrl);
   mainWindow.webContents.openDevTools();
 }

  function createLoadingWindow(){
    // codes to create the loading window
    // .....
  }

  function createOfflineWindow(){
    // codes to create the offline window
    //....
  }

  function checkAndConnect() {
    checkInternet(function (connected) {
      if (!connected) {
        if (!offlineWindow) { createOfflineWindow(); }
      } else {
        if (offlineWindow) {
          offlineWindow.close();
          mainWindow.reload();
        }
      }
      nativeApp.connected = connected;
    });
  }

  function checkInternet(callback) {
    if(navigator.onLine){
      return callback(true);
    }
    return callback(false);
  }

I need to reload my site/app after re-connection. Is there anything wrong in my code? or is it a bug by the electron?