question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

electron.app.relaunch doesn't work inside AppImage

See original GitHub issue
  • Version: 19.6.0
  • Target: AppImage

Calling electron.app.relaunch() from within an AppImage does not properly relaunch the application upon electron.app.quit(). This is true both for the no-argument form of relaunch(), as well as if an execPath is provided, even if the execPath is outside the AppImage

e.g.:

electron.app.relaunch({execPath: '/usr/bin/zenity', args: ['--info', '--text=Hello']});
electron.app.quit();

Interestingly, the relaunch() method does work correctly if the application binary within the mounted AppImage is started directly. (e.g., run the AppImage once to cause the /tmp/.mount* to happen, and then go into that mountpoint while the first copy is still running and execute the electron binary directly. This second directly-executed copy is able to correctly relaunch, but the first copy is not)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
Skywalker13commented, Jan 29, 2021

@peteringram0 the code below will launch the new AppImage–just be sure to exit

//I'm using the following to quit (upon upgrade)--I haven't tested whether just app.quit() works in place of this but I would think so
autoUpdater.quitAndInstall(true, true)

const execPath = path.join(getHomeFolder(), 'SomeApp.AppImage')
const { execFile } = require('child_process')
execFile(execPath)

Keep in mind AppImage’s execute from a temp directory, so I don’t think you can use __filename, which is why I’ve hardcoded the execPath and that feature simply doesn’t work if it’s moved from that location. If someone knows how to get the actual AppImage path when executing from a temp directory I’d love to hear how.

It’s my workaround:

  /* ... args ... */
  const {app} = require('electron');
  const options = {args};
  if (process.env.APPIMAGE) {
    options.execPath = process.env.APPIMAGE;
    options.args.unshift('--appimage-extract-and-run');
  }
  app.relaunch(options);
  app.exit(0);
4reactions
madmurl0ccommented, Jul 20, 2021

It’s my workaround:

  /* ... args ... */
  const {app} = require('electron');
  const options = {args};
  if (process.env.APPIMAGE) {
    options.execPath = process.env.APPIMAGE;
    options.args.unshift('--appimage-extract-and-run');
  }
  app.relaunch(options);
  app.exit(0);

After applying the workaround that @Skywalker13 mentioned the app did restart but I wasn’t able to execute any sudo ... commands anymore. (I know it’s not recommended but I use electron on raspberry pi based closed systems and need to change the hostname, touchscreen brightness, etc. from within electron.) I came up with this solution:

const options: RelaunchOptions = {
  args: process.argv.slice(1).concat(['--relaunch']),
  execPath: process.execPath
};
// Fix for .AppImage
if (app.isPackaged && process.env.APPIMAGE) {
  execFile(process.env.APPIMAGE, options.args);
  app.quit();
  return;
}
app.relaunch(options);
app.quit();

Hopefully it will save someone some time 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Restart electron app in new detached process - Stack Overflow
I have an electron (v17) application running in a linux (v20.04) environment as an AppImage. What I want to achieve.
Read more >
Running AppImages
This page shows how a user can run AppImages, on their favorite distribution using the desktop environment tools or via the terminal.
Read more >
What Is AppImage? Benefits, Drawbacks, and Getting Started
The open source AppImage tool enables developers to make their Linux software available for all Linux distributions.
Read more >
Common Configuration - electron-builder
Common Configuration · in the package.json file of your project using the build key on the top level: "build": { "appId": "com.example.app" }...
Read more >
probonopd/AppImageKit - Gitter
I've tried renaming teh appimager.desktop inside AppDirAssistant. ... that will run AppImages which don't have the executable bit set with read-only ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found