5

I am learning electronJS.
I have a main.dev.js whose content is :

import { app, BrowserWindow } from 'electron';

let mainWindow = null;

if (process.env.NODE_ENV === 'production') {
  const sourceMapSupport = require('source-map-support');
  sourceMapSupport.install();
}

if (
  process.env.NODE_ENV === 'development' ||
  process.env.DEBUG_PROD === 'true'
) {
  require('electron-debug')();
  const path = require('path');
  const p = path.join(__dirname, '..', 'app', 'node_modules');
  require('module').globalPaths.push(p);
}

const installExtensions = async () => {
  const installer = require('electron-devtools-installer');
  const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
  const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS'];

  return Promise.all(
    extensions.map(name => installer.default(installer[name], forceDownload))
  ).catch(console.log);
};

/**
 * Add event listeners...
 */

app.on('window-all-closed', () => {
  // Respect the OSX convention of having the application in memory even
  // after all windows have been closed
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('ready', async () => {
  if (
    process.env.NODE_ENV === 'development' ||
    process.env.DEBUG_PROD === 'true'
  ) {
    await installExtensions();
  }

  mainWindow = new BrowserWindow({
    show: false,
    width: 1024,
    height: 728
  });

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

  // @TODO: Use 'ready-to-show' event
  // https://github.com/electron/electron/blob/master/docs/api/browser-window.md#using-ready-to-show-event
  mainWindow.webContents.on('did-finish-load', () => {
    if (!mainWindow) {
      throw new Error('"mainWindow" is not defined');
    }
    if (process.env.START_MINIMIZED) {
      mainWindow.minimize();
    } else {
      mainWindow.show();
      mainWindow.focus();
    }
  });

  mainWindow.on('closed', () => {
    mainWindow = null;
  });
});

Whose output is :

enter image description here

But nothing is happening on click Toggle Developer Tools option.
I am NOT able to find the issue ?

Note :

I want to debug an electron app whose git repo is : git repo
You can also clone the repo if needed ...


I am NOT able to post my question because of this error (please ignore) :

It looks like your post is mostly code; please add some more details.

It looks like your post is mostly code; please add some more details.

It looks like your post is mostly code; please add some more details.

Abhishek kamal
  • 432
  • 1
  • 5
  • 13
  • Do you have any (error) output on the console? You could try opening the devtools from the Main process, by using `mainWindow.webContents.openDevTools()` after creating the window. – Alexander Leithner Jul 09 '22 at 12:06
  • I have tried everything, but nothing is working. Please use the git repo (given in question description) and try to figure out. – Abhishek kamal Jul 11 '22 at 04:59
  • You can also see [this question](https://stackoverflow.com/questions/72866089/how-to-open-inspect-element-in-electron-app) asked by me. – Abhishek kamal Jul 11 '22 at 05:00
  • This is not how Stack Overflow works (see [ask]). You're responsible for debugging your own app, we cannot clone your repository, then debug the app, write an answer and provide a patch. However, we can provide you with specific solutions to specific problems. It seems your new question duplicated this one, so I'm going to leave this one alone. Btw, "I tried everything" is all but helpful – what I meant was whether you tried calling `openDevTools()` immediately after assigning `mainWindow`. In my experience, this always works and reveals some sort of error. – Alexander Leithner Jul 11 '22 at 06:42
  • I have tried `mainWindow.webContents.openDevTools()` after assigning `mainWindow`. But not working. I am not getting any error on console. – Abhishek kamal Jul 11 '22 at 06:50
  • I saw in your other question that you run Kubuntu 22.04. I'm experiencing the same trouble with Ubuntu 22.04 since I upgraded from 20.04... Maybe it's related. There is maybe a bug with this version of electron. What is your electron version? – SteamFire Mar 03 '23 at 12:26
  • I updated Electron to the last version and now it works. – SteamFire Mar 03 '23 at 12:34

1 Answers1

0

Try to update the electron version to the last one like 23.1.1. It seems to fix the problem in my environment.

SteamFire
  • 367
  • 2
  • 14