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

electron.app.relaunch doesn't work inside AppImage #1727

Closed
p120ph37 opened this issue Jun 22, 2017 · 10 comments
Closed

electron.app.relaunch doesn't work inside AppImage #1727

p120ph37 opened this issue Jun 22, 2017 · 10 comments

Comments

@p120ph37
Copy link
Contributor

  • 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)

@stale
Copy link

stale bot commented Jul 2, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the backlog label Jul 2, 2019
@stale stale bot closed this as completed Jul 9, 2019
@camhart
Copy link

camhart commented Feb 29, 2020

Unstale please!

@camhart
Copy link

camhart commented Feb 29, 2020

For what it's worth, execFile (From child_process) on the AppImage should cause it to relaunch.

@peteringram0
Copy link

hi @camhart have you got an example of what your doing here please? Im getting the same issue.

@camhart
Copy link

camhart commented May 27, 2020

@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.

taratatach added a commit to cozy-labs/cozy-desktop that referenced this issue Aug 13, 2020
  After disconnecting the client from the remote Cozy, we restart the
  application so the user can go through the on-boarding process again
  on a clean slate.

  This was done by programing a client stop (via `setTimeout`) before
  preparing and spawning a new client.
  However, if the new client is spawned fast enough, the old client
  could not be stopped already.

  To avoid this situation with the potential for unpredictable behavior,
  we switched to the restart solution provided by electron.
  It consists in preparing the arguments of a new client and telling
  electron the next time the app is exited, it should be restarted with
  the given arguments.

  This seems to have fixed the disconnection issue we had on Windows.
  The only caveat is this solution does not work with applications
  packaged as AppImage like we do on Linux (see
  electron-userland/electron-builder#1727). As
  a result, we'll keep the old solution on Linux until this is resolved.
taratatach added a commit to cozy-labs/cozy-desktop that referenced this issue Aug 13, 2020
  After disconnecting the client from the remote Cozy, we restart the
  application so the user can go through the on-boarding process again
  on a clean slate.

  This was done by programing a client stop (via `setTimeout`) before
  preparing and spawning a new client.
  However, if the new client is spawned fast enough, the old client
  could not be stopped already.

  To avoid this situation with the potential for unpredictable behavior,
  we switched to the restart solution provided by electron.
  It consists in preparing the arguments of a new client and telling
  electron the next time the app is exited, it should be restarted with
  the given arguments.

  This seems to have fixed the disconnection issue we had on Windows.
  The only caveat is this solution does not work with applications
  packaged as AppImage like we do on Linux (see
  electron-userland/electron-builder#1727). As
  a result, we'll keep the old solution on Linux until this is resolved.
@Skywalker13
Copy link

@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);

@madmurl0c
Copy link

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 :)

@p120ph37
Copy link
Contributor Author

This might be related to electron/electron#34808 ?

@XilinJia
Copy link

XilinJia commented Nov 18, 2023

I need to modify @madmurl0c 's workaround for it to work with both AppImage version and direct (debug) version. Here it is:

	if (app.isPackaged && process.env.APPIMAGE) {
		const options: RelaunchOptions = {
			args: process.argv,
			execPath: process.execPath,
		};
		execFile(process.env.APPIMAGE, options.args);
		app.quit();
		return;
	}
	app.relaunch();
        app.quit();

@dhaval-rao
Copy link

@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);

this is work for me.

i have relaunch app in specific time interval.
that work for me.

i have ubuntu 22.04

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

8 participants