3

我对电子应用程序的自动更新有问题,在完成所有应用程序部分并尝试将其推送到我的自定义更新服务器后,我在记录器中发现了以下错误消息:

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

这是我的 package.json 构建配置

"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"
  }],

这是触发自动更新的代码

//-----------------------------------------------
// 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();
.....

然后,当我推动构建时,它会生成 latest.yml 文件,但安装后我发现 app-update.yml 不存在...

4

1 回答 1

0

如果您对缺少 app-update.yml 和 dev-app-update.yml 有疑问,请将以下代码粘贴到 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], () => { })
    }
}
于 2021-12-30T19:13:42.187 回答