gpt4 book ai didi

javascript - 错误无法读取未定义的属性 'updaterCacheDirName'

转载 作者:行者123 更新时间:2023-12-03 12:42:41 26 4
gpt4 key购买 nike

我正在尝试创建具有自动更新的应用程序,但是运行版本搜索时出现错误

该应用程序会找到该版本,当它即将崩溃时,我会收到此错误

Error: TypeError: Cannot read property 'updaterCacheDirName' of undefined
at NsisUpdater.getOrCreateDownloadHelper (C:\Users\neyun\Desktop\app\node_modules\electron-updater\out\AppUpdater.js:659:55)
at async NsisUpdater.executeDownload (C:\Users\neyun\Desktop\app\node_modules\electron-updater\out\AppUpdater.js:708:36)
TypeError: Cannot read property 'updaterCacheDirName' of undefined
at NsisUpdater.getOrCreateDownloadHelper (C:\Users\neyun\Desktop\app\node_modules\electron-updater\out\AppUpdater.js:659:55)
at async NsisUpdater.executeDownload (C:\Users\neyun\Desktop\app\node_modules\electron-updater\out\AppUpdater.js:708:36)

我已经检查了执行更新功能的代码,并与Github存储库中的其他代码进行了检查,但都等于我拥有的代码,这是我在应用程序菜单中的代码
const { app, BrowserWindow, ipcMain } = require('electron');
const { autoUpdater } = require("electron-updater");
let token = "";
let v = app.getVersion()
autoUpdater.allowPrerelease = true;
autoUpdater.currentVersion = v;
autoUpdater.logger = log;
autoUpdater.autoDownload = false
autoUpdater.setFeedURL({
"provider": "github",
"owner": "",
//"token": token, //deleted
"private":true,
"repo": ""
});
autoUpdater.logger.transports.file.level = 'info';
log.info('App starting...');
function createWindow () {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
},
});
mainWindow.loadURL(`file://${__dirname}/public/update.html`);
mainWindow.setMenu(null)
mainWindow.on('closed', function () {
mainWindow = null;
});
autoUpdater.checkForUpdates();



}


createWindow();



app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});

app.on('activate', function () {
if (mainWindow === null) {
createWindow();
}
});

ipcMain.on('app_version', (event) => {
event.sender.send('app_version', { version: app.getVersion() });
});

autoUpdater.on('update-available', () => {
mainWindow.webContents.send('update_available');
autoUpdater.downloadUpdate().then((path)=>{
console.log('download path', path)
}).catch((e)=>{
console.log(e)
})
});

autoUpdater.on('update-downloaded', () => {
autoUpdater.autoInstallOnAppQuit()
});
autoUpdater.on('checking-for-update', () => {
mainWindow.webContents.send('check_update');
});
autoUpdater.on('update-not-available', () => {
mainWindow.webContents.send('not_update');
});
ipcMain.on('restart_app', () => {


});

这是在html中同时显示版本和警告的html(是否存在新版本)
<!DOCTYPE html>
<head>
<title>Update</title>
<style>
body {
box-sizing: border-box;
margin: 0;
padding: 20px;
font-family: sans-serif;
background-color: #eaeaea;
text-align: center;
}
#notification {
position: fixed;
bottom: 20px;
left: 20px;
width: 200px;
padding: 20px;
border-radius: 5px;
background-color: white;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
.hidden {
display: none;
}
</style>
</head>
<body>
<h1>app</h1>
<span><p>Version:</p> <p id="version"></p></span>
<div id="notification" class="hidden">
<p id="message"></p>

<button id="close-button" onClick="closeNotification()">
Close
</button>
<button id="restart-button" onClick="restartApp()" class="hidden">
Restart
</button>
</div>
<script>
const { ipcRenderer } = require('electron');
const version = document.getElementById('version');
const notification = document.getElementById('notification');
const message = document.getElementById('message');
const restartButton = document.getElementById('restart-button');

ipcRenderer.send('app_version');
ipcRenderer.on('app_version', (event, arg) => {
ipcRenderer.removeAllListeners('app_version');
version.innerText = 'Version ' + arg.version;
});
ipcRenderer.on('update_available', () => {
ipcRenderer.removeAllListeners('update_available');
message.innerText = 'A new update is available. Downloading now...';
notification.classList.remove('hidden');
});
ipcRenderer.on('check_update', () => {
ipcRenderer.removeAllListeners('check_update');
message.innerText = 'Looking for update...';
notification.classList.remove('hidden');
});
ipcRenderer.on('not_update', () => {
ipcRenderer.removeAllListeners('not_update');
message.innerText = 'update not available...';
notification.classList.remove('hidden');
});
ipcRenderer.on('update_downloaded', () => {
ipcRenderer.removeAllListeners('update_downloaded');
message.innerText = 'Update Downloaded. It will be installed on restart. Restart now?';
restartButton.classList.remove('hidden');
notification.classList.remove('hidden');
});
function closeNotification() {
notification.classList.add('hidden');
}

function restartApp() {
ipcRenderer.send('restart_app');
}
</script>
</body>

最佳答案

您是否在未打包应用程序的情况下在开发模式下测试了自动更新功能?

我遇到了同样的错误,以下解决方案为我工作。

看一看documentation:

Note that in order to develop/test UI/UX of updating without packaging the application you need to have a file named dev-app-update.yml



在这种情况下,请在根目录中创建一个“dev-app-update.yml”文件,并以yaml格式从package.json提供发布属性。

dev-app-update.yml
provider:"github"
owner: "abc"

关于javascript - 错误无法读取未定义的属性 'updaterCacheDirName',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58509526/

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