当前位置: 首页 > 后端技术 > Node.js

如何在线回滚Electron应用版本【降级】

时间:2023-04-03 17:01:42 Node.js

前言:在使用electron的自动更新的时候,有时候出现bug想回滚版本,只能向上升级,很无奈。因为看官方文档和百度搜索(我的搜索技术比较弱)都在教人怎么更新升级,没人说降级,所以我来指导大家怎么回滚版本!(如何在线更新,请自行百度)如何降级废话不多说,先上传结果autoUpdater.allowDowngrade=true好了,到此结束。在查看源码的过程中,发现有一个函数叫allowDowngradeayncisUpdateAvailable(){//....constisLatestVersionNewer=(0,_semver().gt)(latestVersion,currentVersion);constisLatestVersionOlder=(0,_semver().lt)(latestVersion,currentVersion);如果(isLatestVersionNewer){返回真;}returnthis.allowDowngrade&&isLatestVersionOlder;}虽然翻译过来的意思很明白,但是眼见为实,后来才找到这个属性的解释。嗯,这应该是我想要的结果,但我仍然不确定它是否会成功。所以我将autoUpdater的allowDowngrade位设置为true并将其放在测试服务器上。一个1.3.9的本地成功回滚到1.3.10!我的配置如下//autoUpdater中有一个属性是allowDowngrade,用来判断是否可以回滚。autoUpdater.allowDowngrade=trueautoUpdater.setFeedURL(downloadUrl);autoUpdater.on('error',function(error){console.log('err',error);sendUpdateMessage(message.error);});autoUpdater.on('检查更新',function(info){console.log('检查更新',JSON.stringify(info));sendUpdateMessage(message.checking);});autoUpdater.on('update-available',function(info){console.log('update-available',JSON.stringify(info));sendUpdateMessage(message.updateAva);});autoUpdater.on('update-not-available',function(info){console.log('update-not-available',JSON.stringify(info));//sendUpdateMessage(message.updateNotAva);});//更新下载进度事件autoUpdater.on('download-progress',function(progressObj){mainWindow.webContents.send('downloadProgress',progressObj);});autoUpdater.on('update-downloaded',function(event,releaseNotes,releaseName,releaseDate,updateUrl,quitAndUpdate){ipcMain.on('isUpdateNow',(e,arg)=>{//退出并安装autoUpdater.quitAndInstall();});mainWindow.webContents.send('isUpdateNow');});ipcMain.on('checkForUpdate',()=>{//检查是否需要更新autoUpdater.checkForUpdates();});希望这对大家有帮助!