

Electron应用如何在线回退版本[Downgrade]
source link: https://segmentfault.com/a/1190000040005504
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在使用electron的自动更新的时候,有时候出现BUG时想回退版本时却只能向上升级,十分之无奈。
因为看官方文档和百度搜索(我的搜索技巧比较水)都是在教人如何更新升级,却没有人讲降级,所以由我带领各位了解下如何回退版本! (如何在线更新请自行百度)
如何Downgrade
不废话先上结果
autoUpdater.allowDowngrade = true
嗯这样子就结束了
看源码的过程中我发现关于检测更新的函数里有一个叫 allowDowngrade
aync isUpdateAvailable(){
// ....
const isLatestVersionNewer = (0, _semver().gt)(latestVersion, currentVersion);
const isLatestVersionOlder = (0, _semver().lt)(latestVersion, currentVersion);
if (isLatestVersionNewer) {
return true;
}
return this.allowDowngrade && isLatestVersionOlder;
}
虽说翻译过来意思已经很明确,但眼见为实,然后找到这个属性的解释
嗯应该是我想要的结果了,但还是不确定能不能成功
所以我设置了 autoUpdater的allowDowngrade位true 并且上测试服务器上放置了一个 1.3.9
本地为1.3.10 成功回退!
我的配置如下
// 在autoUpdater有一个属性是allowDowngrade是用来判断是否可以回退的属性
autoUpdater.allowDowngrade = true
autoUpdater.setFeedURL(downloadUrl);
autoUpdater.on('error', function (error) {
console.log('err', error);
sendUpdateMessage(message.error);
});
autoUpdater.on('checking-for-update', function (info) {
console.log('checking-for-update', 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();
});
希望能帮助到大家!
Recommend
-
18
枕边书 | 作者 承香墨...
-
23
code小生 一个专注大前端领域的技术平台 公众号回复 Android 加入安卓技术群 编辑 | 起锋起笔公众号 来源丨...
-
10
Spring Cloud Netflix Zuul 使用自带的 Hystrix 实现回退机制 , 并实现请求在Zuul内部的聚合功能上篇文章主要是搭建了一下Zuul的服务,并且实现了Zuul过滤器的自定义需求。里边讲到了,Zuu...
-
5
以前,如果是要去除某一块功能,我都是选择性删除,选择性注释,然后前后逻辑各种查看,各种比较。每一次,改完这些我总感觉心好累啊!!!然后,我就发现了 Git 一个非常强大的功能:回滚。当然我还是喜欢叫它:版本回...
-
5
@[toc]上周的文章发了后,有小伙伴问如何在 IDEA 中进行 Git 的版本回退?其实这个松哥之前写过文章,但是时间久远了,所以今天再和小伙伴们重新捋一捋这个话题,顺便也来聊聊如何在 IDEA 中进行 Git 的版本回退。Git 中的撤销操作,我们可...
-
4
git是一个很好的版本库, 现在很多人用它, 并在github上创建项目, 相信大家都有过将敏感信息提交版本的经历, 如何删除? 好像只有删除版本库来解决, 其实我们可以通过回退版本库删除相应的commit来将提交的敏感信息去掉. 备份本地代码 首先我们将...
-
7
『现学现忘』Git后悔药 — 28、版本回退git reset --soft命令说明 git reset --soft commit-id命令:回退到指定版本。(soft...
-
7
『现学现忘』Git后悔药 — 30、版本回退git reset --hard命令说明 git reset --hardcommit-id命令:回退到指定版本。(hard...
-
7
Git 回退版本 查看所有的历史版本,获取你git的某个历史版本的id git log 恢复到历史版本 git reset --hard fae6966548e3ae76cfa7...
-
4
学习git reset之前先了解git的四区五状态 一张图理解四个区
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK