Commit 9d61cf82 authored by antoor's avatar antoor

Updated version comparison algorithm

更新版本对比算法
parent e4313af5
......@@ -29,10 +29,7 @@ class Update {
let newVersion = lastInfo['tag_name'];
let curVersion = config['package'].version;
// 比对版本
if (
parseInt(newVersion.replace(/\./g, '')) >
parseInt(curVersion.replace(/\./g, ''))
) {
if (this.CompVersion(curVersion, newVersion)) {
this.logger.info('Found a new version', newVersion);
event.sender.send('notification-update', {
ver: newVersion,
......@@ -46,6 +43,30 @@ class Update {
}
});
}
/**
* 版本比对
* @param {String} curVer 当前版本
* @param {String} newVer 新的版本
* @return {Boolean}
*/
CompVersion(curVer, newVer) {
// 如果版本相同
if (curVer === newVer) { return false }
let currVerArr = curVer.split(".");
let promoteVerArr = newVer.split(".");
let len = Math.max(currVerArr.length, promoteVerArr.length);
for (let i = 0; i < len; i++) {
let proVal = ~~promoteVerArr[i],
curVal = ~~currVerArr[i];
if (proVal < curVal) {
return false;
} else if (proVal > curVal) {
return true;
}
}
return false;
}
}
module.exports = Update;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment