Problem with app update yml files is not generated in electron?

5k Views Asked by At

I have a problem with the auto-update of electron app, After I finished all the app parts and I am trying to push it to my custom update server , I found this error message in my logger :

Error unknown ENOENT: no such file or directory, open 
'C:\{appPath}\{appName}\resources\app-update.yml'

and here is my package.json build configuration

"build": {
    "appId": "com.server.app",
    "copyright": "Copyright company name",
    "generateUpdatesFilesForAllChannels": true,
    "win": {
      "target": "nsis",
      "icon": "build/icon.ico"
    },
    "mac": {
      "target": "dmg",
      "artifactName": "appName.dmg",
      "icon": "build/icon.icns"
    },
    "dmg": {
      "background": "build/i-bg.tif",
      "icon": "build/setup.icns",
      "iconSize": 80,
      "title": "${productName}-${version}",
      "window": {
        "width": 540,
        "height": 380
      }
    },
    "nsis": {
      "artifactName": "${productName}-Setup-${version}.${ext}",
      "oneClick": false,
      "perMachine": false,
      "allowToChangeInstallationDirectory": true,
      "installerIcon": "build/setup.ico",
      "uninstallerIcon": "build/setup.ico",
      "installerHeader": "build/installerHeader.bmp",
      "installerSidebar": "build/installerSidebar.bmp",
      "runAfterFinish": true,
      "deleteAppDataOnUninstall": true,
      "createDesktopShortcut": "always",
      "createStartMenuShortcut": true,
      "shortcutName": "AppName",
      "publish": [{
        "provider": "generic",
        "url": "https://my-update-server/path"
      }]
    },
    "extraFiles": [
      "data",
      "templates"
    ]
  },
  "publish": [{
    "provider": "generic",
    "url": "https://my-update-server/path"
  }],

and here is the code for triggering the auto-update

//-----------------------------------------------
// Auto-Update event listening 
//-----------------------------------------------

autoUpdater.on('checking-for-update', () => {
  splashLoadingStatus(`Checking for ${appName} update ...`);
})

autoUpdater.on('update-available',(info) => {
  splashLoadingStatus(`${appName} new update available.`);
})

autoUpdater.on('update-progress',(progInfo) => {
  splashLoadingStatus(`Download speed: ${progInfo.bytesPerSecond} - Download ${progInfo.percent}% (${progInfo.transferred}/${progInfo.total})`);
})

autoUpdater.on('error' , (error) => {
  dialog.showErrorBox('Error', error.message);
})

autoUpdater.on('update-downloaded', (info) => {
  const message = {
    type: 'info',
    buttons: ['Restart', 'Update'],
    title: `${appName} Update`,
    detail: `A new version has been downloaded. Restart ${appName} to apply the updates.`
  }

  dialog.showMessageBox(message, (res) => {
    if(res === 0) {
      autoUpdater.quitAndInstall();
    }
  })
})
.....
          autoUpdater.setFeedURL('https://my-update-server/path');
          autoUpdater.checkForUpdatesAndNotify();
.....

then when I am pushing the build it will do everything correct with the latest.yml file generating but after installing I found the app-update.yml is not there ...

2

There are 2 best solutions below

0
On BEST ANSWER

If you have a problem with missing app-update.yml and dev-app-update.yml then paste the following code into index.js:

import path from "path"
import fs from "fs"
const feed = 'your_site/update/windows_64'

let yaml = '';

yaml += "provider: generic\n"
yaml += "url: your_site/update/windows_64\n"
yaml += "useMultipleRangeRequest: false\n"
yaml += "channel: latest\n"
yaml += "updaterCacheDirName: " + app.getName()

let update_file = [path.join(process.resourcesPath, 'app-update.yml'), yaml]
let dev_update_file = [path.join(process.resourcesPath, 'dev-app-update.yml'), yaml]
let chechFiles = [update_file, dev_update_file]

for (let file of chechFiles) {
    if (!fs.existsSync(file[0])) {
        fs.writeFileSync(file[0], file[1], () => { })
    }
}
0
On

I fixed it by using autoUpdater.setFeedURL() before autoUpdater.checkForUpdates(). Below is the code snippet that works for github releases. Also, please make sure there is existing release in Github before running this code.

import { autoUpdater } from "electron-updater";

// ...

autoUpdater.setFeedURL({
  provider: "github",
  owner: "org",
  repo: "repo",
});