gpt4 book ai didi

node.js - 应用程序更新问题 yml 文件不是在 Electron 中生成的吗?

转载 作者:行者123 更新时间:2023-12-05 06:01:26 26 4
gpt4 key购买 nike

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

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 不存在 ...

最佳答案

如果您遇到缺少 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], () => { })
}
}

关于node.js - 应用程序更新问题 yml 文件不是在 Electron 中生成的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67191654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com