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-updater rpm, unable to automatically update #7569

Closed
Lunarequest opened this issue May 6, 2023 · 13 comments · Fixed by #7628 or #7637
Closed

electron-updater rpm, unable to automatically update #7569

Lunarequest opened this issue May 6, 2023 · 13 comments · Fixed by #7628 or #7637
Assignees

Comments

@Lunarequest
Copy link

  • Electron-Builder Version:
  • Node Version: 20.1.0
  • Electron Version: 24.2.0
  • Electron Type (current, beta, nightly):current

electron-updater: 6.1.0

  • Target: Linux Rpm

When i run the outputted app it has a notification like expected, when you close the app it crashes with this output

/usr/bin/pkexec
07:03:50.653 › Error: TypeError: Cannot read properties of null (reading 'trim')
    at RpmUpdater.spawnSyncLog (/opt/NightPDF/resources/app.asar/node_modules/electron-updater/out/BaseUpdater.js:113:32)
    at RpmUpdater.wrapSudo (/opt/NightPDF/resources/app.asar/node_modules/electron-updater/out/BaseUpdater.js:91:27)
    at RpmUpdater.doInstall (/opt/NightPDF/resources/app.asar/node_modules/electron-updater/out/RpmUpdater.js:29:27)
    at RpmUpdater.install (/opt/NightPDF/resources/app.asar/node_modules/electron-updater/out/BaseUpdater.js:54:25)
    at /opt/NightPDF/resources/app.asar/node_modules/electron-updater/out/BaseUpdater.js:85:18
    at App.<anonymous> (/opt/NightPDF/resources/app.asar/node_modules/electron-updater/out/ElectronAppAdapter.js:35:48)
    at Object.onceWrapper (node:events:628:26)
    at App.emit (node:events:525:35)
    at App.<anonymous> (/opt/NightPDF/resources/app.asar/out/main/app.js:1:3937)
    at App.emit (node:events:525:35)

I would also like to request the order of the gui elevation prompt order to use pkexec first. This command is what i used based on the log which gksudo || which kdesudo || which pkexec || which beesu pkexec should come first as gksudo and kdesudo are not present in most distros as the linux world has moved towards pkexec due to standardization across desktop environments. (pkexec also uses de specific prompts meaning it doesn't look out of place on whatever de you are using)

@msaad7777
Copy link

I wan to contribute to this project, can I have any issue assigned ?

@Lunarequest
Copy link
Author

if you do take this up, please change the ordering of prompts since pkexec is guaranteed on any distro where flatpak is present unlike kdesudo and gksudo which can't be found on most distros eg opensuse & arch has neither

@mmaietta
Copy link
Collaborator

mmaietta commented May 9, 2023

@Lunarequest That's awesome you're trying out the Beta autoupdate feature for rpm! I've never seen that error before. Why is the output coming out to null from spawnSync?

@msaad7777 I assigned the ticket to you. Let me know if you need any help getting set up.

@Lunarequest
Copy link
Author

@Lunarequest That's awesome you're trying out the Beta autoupdate feature for rpm! I've never seen that error before. Why is the output coming out to null from spawnSync?

I have no idea, not sure what its trying to call afaik spawnsync should run some command. (Note I am running OpenSuse which uses zypper which may affect this, there are some things if it could be done would be cool. RPMs currently hardcode deps to fedora names considering Opensuse/SLE is the biggest distro that uses rpm outside of the RHEL ecosystem would it be possible to also create rpms for it?)

@bukharin
Copy link

bukharin commented Jun 7, 2023

Have the same issue on ubuntu 22.04

@bukharin
Copy link

bukharin commented Jun 7, 2023

It seems releted to stdio: "inherit"

Removing this parameter fixes the problem

@mmaietta
Copy link
Collaborator

@bukharin would you be willing to open a PR with that change?

@Lunarequest
Copy link
Author

Lunarequest commented Jun 23, 2023

I've patched my downstream electron-updater to test the proposed change and can confirm it works

@bukharin
Copy link

Thanks @mmaietta, now update is working. But we also need ability to relaunch app after update.

Now user need to start app manully after update is installed

@mmaietta
Copy link
Collaborator

mmaietta commented Jun 27, 2023

I'm not sure if there's a way to just restart the app via command line.

In my other project, I was just calling this after the update completed

app.relaunch();
app.quit();

But that was because I couldn't tap into electron-updater events/callbacks with that project and still needed to use a C++ module for handling dmg installations.

Can you give this a patch-package a shot?
electron-updater+6.1.2.patch

diff --git a/node_modules/electron-updater/out/DebUpdater.js b/node_modules/electron-updater/out/DebUpdater.js
index ef75391..422f42f 100644
--- a/node_modules/electron-updater/out/DebUpdater.js
+++ b/node_modules/electron-updater/out/DebUpdater.js
@@ -30,6 +30,9 @@ class DebUpdater extends BaseUpdater_1.BaseUpdater {
         const wrapper = /pkexec/i.test(sudo) ? "" : `"`;
         const cmd = ["dpkg", "-i", options.installerPath, "||", "apt-get", "install", "-f", "-y"];
         this.spawnSyncLog(sudo, [`${wrapper}/bin/bash`, "-c", `'${cmd.join(" ")}'${wrapper}`]);
+        if (options.isForceRunAfter) {
+            this.app.relaunch();
+        }
         return true;
     }
 }
diff --git a/node_modules/electron-updater/out/ElectronAppAdapter.js b/node_modules/electron-updater/out/ElectronAppAdapter.js
index d0b91f7..8199d40 100644
--- a/node_modules/electron-updater/out/ElectronAppAdapter.js
+++ b/node_modules/electron-updater/out/ElectronAppAdapter.js
@@ -31,6 +31,9 @@ class ElectronAppAdapter {
     quit() {
         this.app.quit();
     }
+    relaunch() {
+        this.app.relaunch();
+    }
     onQuit(handler) {
         this.app.once("quit", (_, exitCode) => handler(exitCode));
     }
diff --git a/node_modules/electron-updater/out/RpmUpdater.js b/node_modules/electron-updater/out/RpmUpdater.js
index ae9843f..32fb0ff 100644
--- a/node_modules/electron-updater/out/RpmUpdater.js
+++ b/node_modules/electron-updater/out/RpmUpdater.js
@@ -56,6 +56,9 @@ class RpmUpdater extends BaseUpdater_1.BaseUpdater {
             ];
         }
         this.spawnSyncLog(sudo, [`${wrapper}/bin/bash`, "-c", `'${cmd.join(" ")}'${wrapper}`]);
+        if (options.isForceRunAfter) {
+            this.app.relaunch();
+        }
         return true;
     }
 }

@bukharin
Copy link

Yes, it works! (tested on Ubuntu). As a workaround for that may handle before-quit-for-update and execute app.relaunch(), but support for forceRunAfter flag is better.

Chould you make a PR for this fix also?

@mmaietta
Copy link
Collaborator

@bukharin released 24.5.2 (electron-updater@6.1.3)

@beeble-wonjunyoon
Copy link

beeble-wonjunyoon commented Jan 10, 2024

@mmaietta

I've tested that auto-update functions correctly with both .appimage and .deb formats.

However, I'm encountering issues with .rpm files. When a new version is available, it gets downloaded, but it doesn't seem to install correctly. As a result, the application restarts using the old version and notifies me that a new version has been downloaded again and again.

Any suggestions will be really appreciated.

I'm using

  • rocky linux 8
  • electron-updater@6.1.7
  • electron-builder@24.9.1

code snippet

import { app, dialog } from "electron";
import { autoUpdater as electronAutoUpdater } from "electron-updater";
import * as log from "electron-log";

export const autoUpdater = electronAutoUpdater;

export const initializeAutoUpdater = () => {
  console.log("Initialize auto updater")
  autoUpdater.on("checking-for-update", () => {
    log.info("Checking for updates...");
  });

  autoUpdater.on("update-not-available", (info: any) => {
    log.info("You are on the latest version.");
  });

  autoUpdater.on("error", (err) => {
    log.info("An error occurred. Error details: " + err);
  });

  autoUpdater.on("update-available", (info: any) => {
    const dialogOpts = {
      type: "info",
      buttons: ["Ok"],
      title: "Update Available",
      message: "A new version download started.\nThe app will be restarted to install the update.",
    };
    dialog.showMessageBox(dialogOpts);
  });

  autoUpdater.on("download-progress", (progressObj: any) => {
    let log_message = "Download speed: " + progressObj.bytesPerSecond;
    log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
    log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')'
    log.info(log_message);
  });

  autoUpdater.on("update-downloaded", (info: any) => {
    const dialogOpts = {
      type: "info",
      buttons: ["Restart", "Later"],
      title: "Application Update",
      message: "A new version has been downloaded.\nRestart the application to apply the updates.",
    };
    dialog.showMessageBox(dialogOpts).then((returnValue) => {
      log.info("LOG: " + returnValue.response);
      if (returnValue.response === 0) autoUpdater.quitAndInstall();
    });
  });
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment