Skip to content

Commit

Permalink
debug check_update
Browse files Browse the repository at this point in the history
  • Loading branch information
Xmader committed Jun 24, 2019
1 parent 6110378 commit 6b31964
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions app/check_update.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ const check_update = async () => {
const data = await req.json()

const version = app.getVersion() // 当前版本号, 在package.json中定义
const version_formatted = format_version(version)

const new_version = data["version"]
const new_version_formatted = format_version(new_version)

if (version_formatted < new_version_formatted) {
if (compare_versions(new_version, version) >= 1) {
found_new_version(version, new_version)
}
}
Expand All @@ -56,7 +53,29 @@ const check_update = async () => {
* @param {string} e - 需要被格式化的版本号字符串
*/
const format_version = (e) => {
return e.split(".").map((e) => +e)
return e.split(".").map((e) => +e | 0)
}

/**
* @param {string} a
* @param {string} b
*/
const compare_versions = (a, b) => {
const av = format_version(a)
const bv = format_version(b)

for (let i = 0; i < Math.max(av.length, bv.length); i++) {
const an = +av[i]
const bn = +bv[i]

if (an > bn) {
return 1
} else if (bn > an) {
return -1
}
}

return 0
}

module.exports = check_update
Expand Down

0 comments on commit 6b31964

Please sign in to comment.