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

[Bug]: app.relaunch() fails to restart app - It only exits. #31726

Closed
3 tasks done
alex-drocks opened this issue Nov 5, 2021 · 7 comments
Closed
3 tasks done

[Bug]: app.relaunch() fails to restart app - It only exits. #31726

alex-drocks opened this issue Nov 5, 2021 · 7 comments
Labels

Comments

@alex-drocks
Copy link

alex-drocks commented Nov 5, 2021

Preflight Checklist

Electron Version

15.3.0

What operating system are you using?

Windows

Operating System Version

Windows 10.0.19043

What arch are you using?

x64

Last Known Working Electron version

15.2.0

Expected Behavior

app.relaunch() should restart the Electron application as expected.

Actual Behavior

The application only quits. It does not relaunch the app as it should.

Testcase Gist URL

https://github.com/alex-drocks/electron-15.3.0-win10-x64-app-relaunch-fails

Additional Information

For documentation I read this: https://www.electronjs.org/docs/latest/api/app#apprelaunchoptions

I have a production build using Electron v15.2.0 in which the app.relaunch() function still works as expected.
I also tried to use Electron v16 beta to see if it was fixed later in beta releases.

Testcase URL is a copy of the electron-quick-start where I jsut added a button in the renderer process to trigger the app.relaunch() function.

@alex-drocks
Copy link
Author

Please note that I tried packaging my electron app and it DOES work when packaged! Wierd.

@baconbrad
Copy link
Contributor

I have cloned and tested your testcase and I am getting the expected behavior on 15.3.0. Does your packaged version still work in the same directory as your Electron dependency dist directory?

@alex-drocks
Copy link
Author

I'm not sure I understand what you mean by the same directory because when packaged it goes into the "out" dir by default with Electron Forge. So I suppose, it is a completely different folder than in dev mode.

Although I can confirm, that it works correctly on my Mac...

I'll do some more testing on my windows machine, but I have already tried deleting the node_modules completely. I'll post back when I have more info. Thank you

@alex-drocks
Copy link
Author

So I've tried a clean install of npm dependencies again. Then, messed around in the node_modules/electron/dist folder as I was trying to figure out what you meant. I tried placing my packaged .exe file beside the electron.exe file in the dist folder and tried running that without success. I don't see why it would have been useful.

I can now confirm these things:

  • on Mac the app.relaunch works as expected in dev mode and also in production builds.
  • on Windows, app.relaunch only works in production builds but not in dev mode.

@alex-drocks
Copy link
Author

alex-drocks commented Nov 6, 2021

I found the problem:
It is caused by a third-party electron library named "electron-reloader"

//auto-reload on save
if (isDev) {
    try {
        // You have to pass the module object so we can read the module graph and figure out which files belong to the main process.
        // The try/catch is needed so it doesn't throw Cannot find module 'electron-reloader' in production.
        require('electron-reloader')(module);
    } catch {
        //return
    }
}

If I comment out the previous lines, the app.relaunch works perfectly.

@azwalzaman
Copy link

I'm facing the same issue. The app reloads in production but not in development. I'm using Electron 23.2.1 with Electron Forge

@juxnpxblo
Copy link

juxnpxblo commented Apr 5, 2023

same issue here in electron 22.2.0 with electron-forge. it was working until just recently.

restarting works fine on prod, but in dev the application never comes back (although I can still see some electron processes running on task manager, and I am unable to npm start my app again until I manually close them)

relevant code:

export const restart = () => {
  app.relaunch();
  app.exit();
};

app.on('window-all-closed', () => {
  app.quit();
});

if (require('electron-squirrel-startup')) {
  app.quit();
}

if (!app.requestSingleInstanceLock()) {
  app.exit();
}

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

No branches or pull requests

4 participants