Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
How to write electron asar updater?

I want to write an electron updater that only downloads the newest 'app.asar' and replaces it with the old one. I don't want to use 'electron-updater' like solutions because they're mostly exclusive to windows and mac. So I want to write an "asar updater" that works on all platforms including linux. It should more or less work like the discord updater, that compares the local installed version with the newest uploaded version on a webserver.

On Linux most package formats mount the files in directories in which my updater would need root privileges. For example the AppImage mounts all files to random dir inside the '/tmp' folder, or the flatpak mounts it in weird directory '/app/lib/' which I couldn't find on my system yet...

So my question would be, how can I replace an old asar file with an updated one without having problems with root privileges?

This is the part of the updater logic inside 'main.js':

app.whenReady().then(() => {
    // Updater should only be run in "production"
    if (isDev) return;
    // Get path of asar file & resource dir stored on the system
    const asarPath = app.getAppPath(); // => /tmp/.APPNAMExlsjda345/resources/app.asar/src/electron/
    const resourcesPath = path.join(asarPath, ".."); // => /tmp/.APPNAMExlsjda345/resources/

    // TODO: compare current version with newest on webserver
    // TODO: download new version & call it something like "update.asar"
    // TODO: remove app.asar & rename update.asar to app.asar
    // TODO: restart the whole app

    // This is only for testing if I can modify the content of the resources directory
    fs.copyFile(asarPath, path.join(resourcesPath, "update.asar"), (err) => {
      if (err) return console.log({ err }); // throws error, see below!
      console.log("copied: ", fs.readdirSync(resourcesPath)); // if it would be successfull print all the content of resources dir
    });
  }
});

This is the error the copyFile function throws:

{
  err: Error: ENOENT,  not found in /tmp/.mount_Babbel2t0KoE/resources/app.asar
      at createError (node:electron/js2c/asar_bundle:5:1255)
      at Object.t.<computed> [as copyFile] (node:electron/js2c/asar_bundle:5:2526)
      at /tmp/.mount_Babbel2t0KoE/resources/app.asar/src/electron/main.js:44:6 {
    code: 'ENOENT',
    errno: -2
  }
}

EDIT: I also tried "original-fs", which should work with asar files:

{
  err: [Error: EROFS: read-only file system, copyfile '/tmp/.mount_BabbelMjuGx3/resources/app.asar' -> '/tmp/.mount_BabbelMjuGx3/resources/update.asar'] {
    errno: -30,
    code: 'EROFS',
    syscall: 'copyfile',
    path: '/tmp/.mount_BabbelMjuGx3/resources/app.asar',
    dest: '/tmp/.mount_BabbelMjuGx3/resources/update.asar'
  }
}
about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda