修复版本对比问题

pull/277/head
lyswhut 2020-06-27 21:22:02 +08:00
parent c9d0aafbfa
commit 897a17e303
9 changed files with 76 additions and 135 deletions

108
package-lock.json generated
View File

@ -4942,74 +4942,22 @@
}
},
"browserslist": {
"version": "4.12.0",
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.12.0.tgz",
"integrity": "sha512-UH2GkcEDSI0k/lRkuDSzFl9ZZ87skSy9w2XAn1MsZnL+4c4rqbBd3e82UWHbYDpztABrPBhZsTEeuxVfHppqDg==",
"version": "4.12.2",
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.12.2.tgz",
"integrity": "sha512-MfZaeYqR8StRZdstAK9hCKDd2StvePCYp5rHzQCPicUjfFliDgmuaBNPHYUTpAywBN8+Wc/d7NYVFkO0aqaBUw==",
"dev": true,
"requires": {
"caniuse-lite": "^1.0.30001043",
"electron-to-chromium": "^1.3.413",
"node-releases": "^1.1.53",
"pkg-up": "^2.0.0"
"caniuse-lite": "^1.0.30001088",
"electron-to-chromium": "^1.3.483",
"escalade": "^3.0.1",
"node-releases": "^1.1.58"
},
"dependencies": {
"caniuse-lite": {
"version": "1.0.30001048",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001048.tgz",
"integrity": "sha512-g1iSHKVxornw0K8LG9LLdf+Fxnv7T1Z+mMsf0/YYLclQX4Cd522Ap0Lrw6NFqHgezit78dtyWxzlV2Xfc7vgRg==",
"version": "1.0.30001088",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001088.tgz",
"integrity": "sha512-6eYUrlShRYveyqKG58HcyOfPgh3zb2xqs7NvT2VVtP3hEUeeWvc3lqhpeMTxYWBBeeaT9A4bKsrtjATm66BTHg==",
"dev": true
},
"find-up": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz",
"integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=",
"dev": true,
"requires": {
"locate-path": "^2.0.0"
}
},
"locate-path": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz",
"integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=",
"dev": true,
"requires": {
"p-locate": "^2.0.0",
"path-exists": "^3.0.0"
}
},
"p-limit": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz",
"integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==",
"dev": true,
"requires": {
"p-try": "^1.0.0"
}
},
"p-locate": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz",
"integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=",
"dev": true,
"requires": {
"p-limit": "^1.1.0"
}
},
"p-try": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz",
"integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=",
"dev": true
},
"pkg-up": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/pkg-up/-/pkg-up-2.0.0.tgz",
"integrity": "sha1-yBmscoBZpGHKscOImivjxJoATX8=",
"dev": true,
"requires": {
"find-up": "^2.1.0"
}
}
}
},
@ -7241,9 +7189,9 @@
}
},
"electron-devtools-installer": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/electron-devtools-installer/-/electron-devtools-installer-3.0.0.tgz",
"integrity": "sha512-zll3w/8PvnPiGmL5tBtgSSoSjWnUljsOjJYsYYU12PKLljzWyfD6S75LKTZFn21VYxVbae2OwmjM5uFStLp6nQ==",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/electron-devtools-installer/-/electron-devtools-installer-3.1.0.tgz",
"integrity": "sha512-qZd1Aoya8YOK6QauNX92V5qyKGtb4lbs238bP+qtMBkXts24xJ/1PtOVBPvdg5w3Ts9L5o6I9sDErKuzHeJFDA==",
"dev": true,
"requires": {
"rimraf": "^3.0.2",
@ -7252,9 +7200,9 @@
},
"dependencies": {
"semver": {
"version": "7.2.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.2.1.tgz",
"integrity": "sha512-aHhm1pD02jXXkyIpq25qBZjr3CQgg8KST8uX0OWXch3xE6jw+1bfbWnCjzMwojsTquroUmKFHNzU6x26mEiRxw==",
"version": "7.3.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz",
"integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==",
"dev": true
}
}
@ -7369,9 +7317,9 @@
}
},
"electron-to-chromium": {
"version": "1.3.418",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.418.tgz",
"integrity": "sha512-i2QrQtHes5fK/F9QGG5XacM5WKEuR322fxTYF9e8O9Gu0mc0WmjjwGpV8c7Htso6Zf2Di18lc3SIPxmMeRFBug==",
"version": "1.3.483",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.483.tgz",
"integrity": "sha512-+05RF8S9rk8S0G8eBCqBRBaRq7+UN3lDs2DAvnG8SBSgQO3hjy0+qt4CmRk5eiuGbTcaicgXfPmBi31a+BD3lg==",
"dev": true
},
"electron-updater": {
@ -7569,6 +7517,12 @@
"dev": true,
"optional": true
},
"escalade": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.0.1.tgz",
"integrity": "sha512-DR6NO3h9niOT+MZs7bjxlj2a1k+POu5RN8CLTPX2+i78bRi9eLe7+0zXgUHMnGXWybYcL61E9hGhPKqedy8tQA==",
"dev": true
},
"escape-goat": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz",
@ -11046,9 +11000,9 @@
}
},
"jszip": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/jszip/-/jszip-3.3.0.tgz",
"integrity": "sha512-EJ9k766htB1ZWnsV5ZMDkKLgA+201r/ouFF8R2OigVjVdcm2rurcBrrdXaeqBJbqnUVMko512PYmlncBKE1Huw==",
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/jszip/-/jszip-3.5.0.tgz",
"integrity": "sha512-WRtu7TPCmYePR1nazfrtuF216cIVon/3GWOvHS9QR5bIwSbnxtdpma6un3jyGGNhHsKCSzn5Ypk+EkDRvTGiFA==",
"dev": true,
"requires": {
"lie": "~3.3.0",
@ -12001,9 +11955,9 @@
}
},
"node-releases": {
"version": "1.1.53",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.53.tgz",
"integrity": "sha512-wp8zyQVwef2hpZ/dJH7SfSrIPD6YoJz6BDQDpGEkcA0s3LpAQoxBIYmfIq6QAhC1DhwsyCgTaTTcONwX8qzCuQ==",
"version": "1.1.58",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.58.tgz",
"integrity": "sha512-NxBudgVKiRh/2aPWMgPR7bPTX0VPmGx5QBwCtdHitnqFE5/O8DeBXuIMH1nwNnw/aMo6AjOrpsHzfY3UbUJ7yg==",
"dev": true
},
"normalize-package-data": {

View File

@ -1,6 +1,6 @@
{
"name": "lx-music-desktop",
"version": "0.18.3",
"version": "1.0.0-beta",
"description": "一个免费的音乐下载助手",
"main": "./dist/electron/main.js",
"productName": "lx-music-desktop",
@ -168,7 +168,7 @@
"babel-loader": "^8.1.0",
"babel-minify-webpack-plugin": "^0.3.1",
"babel-preset-minify": "^0.5.1",
"browserslist": "^4.12.0",
"browserslist": "^4.12.2",
"cfonts": "^2.8.5",
"chalk": "^4.1.0",
"changelog-parser": "^2.8.0",
@ -180,7 +180,7 @@
"electron": "^9.0.5",
"electron-builder": "^22.7.0",
"electron-debug": "^3.1.0",
"electron-devtools-installer": "^3.0.0",
"electron-devtools-installer": "^3.1.0",
"eslint": "^7.3.1",
"eslint-config-standard": "^14.1.1",
"eslint-formatter-friendly": "^7.0.0",

View File

@ -25,7 +25,7 @@ const updateChangeLog = async(newVerNum, newChangeLog) => {
let changeLog = fs.readFileSync(changelogPath, 'utf-8')
const prevVer = await getPrevVer()
const log = `## [${newVerNum}](${pkg.repository.url.replace(/^git\+(http.+)\.git$/, '$1')}/compare/v${prevVer}...v${newVerNum}) - ${formatTime()}\n\n${newChangeLog}`
fs.writeFileSync(changelogPath, changeLog.replace(new RegExp(`(## [?0.1.1]?)`), log + '\n$1'), 'utf-8')
fs.writeFileSync(changelogPath, changeLog.replace(new RegExp('(## [?0.1.1]?)'), log + '\n$1'), 'utf-8')
}
const renderChangeLog = md => md_renderer(md)
@ -49,7 +49,7 @@ module.exports = async newVerNum => {
console.log(chalk.blue('new version: ') + chalk.green(newVerNum))
fs.writeFileSync(jp('../version.json'), JSON.stringify(version, null, 2) + '\n', 'utf-8')
fs.writeFileSync(jp('../version.json'), JSON.stringify(version) + '\n', 'utf-8')
fs.writeFileSync(jp(pkgDir), JSON.stringify(pkg, null, 2) + '\n', 'utf-8')

View File

@ -48,28 +48,23 @@ exports.debounce = (fn, delay = 100) => {
exports.log = log
// https://stackoverflow.com/a/53387532
exports.compareVer = (currentVer, targetVer) => {
// treat non-numerical characters as lower version
// replacing them with a negative number based on charcode of each character
const fix = s => `.${s.toLowerCase().charCodeAt(0) - 2147483647}.`
exports.checkVersion = (currentVer, targetVer) => {
// console.log(currentVer)
// console.log(targetVer)
currentVer = currentVer.split('.')
targetVer = targetVer.split('.')
let maxLen = Math.max(currentVer.length, targetVer.length)
if (currentVer.length < maxLen) {
for (let index = 0, len = maxLen - currentVer.length; index < len; index++) {
currentVer.push(0)
}
currentVer = ('' + currentVer).replace(/[^0-9.]/g, fix).split('.')
targetVer = ('' + targetVer).replace(/[^0-9.]/g, fix).split('.')
let c = Math.max(currentVer.length, targetVer.length)
for (let i = 0; i < c; i++) {
// convert to integer the most efficient way
currentVer[i] = ~~currentVer[i]
targetVer[i] = ~~targetVer[i]
if (currentVer[i] > targetVer[i]) return 1
else if (currentVer[i] < targetVer[i]) return -1
}
if (targetVer.length < maxLen) {
for (let index = 0, len = maxLen - targetVer.length; index < len; index++) {
targetVer.push(0)
}
}
for (let index = 0; index < currentVer.length; index++) {
if (parseInt(currentVer[index]) < parseInt(targetVer[index])) return true
if (parseInt(currentVer[index]) > parseInt(targetVer[index])) return false
}
return false
return 0
}
exports.isObject = item => item && typeof item === 'object' && !Array.isArray(item)
@ -109,7 +104,7 @@ exports.mergeSetting = (setting, version) => {
if (!setting) {
setting = defaultSetting
} else if (exports.checkVersion(version, defaultVersion)) {
} else if (exports.compareVer(version, defaultVersion) < 0) {
exports.objectDeepMerge(defaultSetting, setting)
exports.objectDeepMerge(defaultSetting, overwriteSetting)
setting = defaultSetting

View File

@ -16,7 +16,7 @@ electronDebug({
// Install `vue-devtools`
electron.app.on('ready', () => {
installExtension(VUEJS_DEVTOOLS)
.then(info => console.log(`Added Extension: ${info.name}`))
.then(name => console.log(`Added Extension: ${name}`))
.catch(err => console.log('An error occurred: ', err))
})

View File

@ -27,7 +27,7 @@ import { mapMutations, mapGetters, mapActions } from 'vuex'
import { rendererOn, rendererSend, rendererInvoke, NAMES } from '../common/ipc'
import { isLinux } from '../common/utils'
import music from './utils/music'
import { throttle, openUrl } from './utils'
import { throttle, openUrl, compareVer } from './utils'
import { base as eventBaseName } from './event/names'
window.ELECTRON_DISABLE_SECURITY_WARNINGS = process.env.ELECTRON_DISABLE_SECURITY_WARNINGS
@ -269,13 +269,8 @@ export default {
this.setNewVersion(result)
return result
}).then(result => {
let newVer = result.version.replace(/\./g, '')
let currentVer = this.version.version.replace(/\./g, '')
let len = Math.max(newVer.length, currentVer.length)
newVer.padStart(len, '0')
currentVer.padStart(len, '0')
if (result.version == '0.0.0') return this.setVersionModalVisible({ isUnknow: true, isShow: true })
if (parseInt(newVer) <= parseInt(currentVer)) return this.setVersionModalVisible({ isLatestVer: true })
if (compareVer(this.version.version, result.version) != -1) return this.setVersionModalVisible({ isLatestVer: true })
if (result.version === this.setting.ignoreVersion) return
// console.log(this.version)

View File

@ -128,7 +128,7 @@ material-modal(:show="version.showModal" @close="handleClose" v-if="version.newV
<script>
import { mapGetters, mapMutations } from 'vuex'
import { rendererSend, NAMES } from '../../../common/ipc'
import { checkVersion, openUrl, clipboardWriteText, sizeFormate } from '../../utils'
import { compareVer, openUrl, clipboardWriteText, sizeFormate } from '../../utils'
export default {
computed: {
@ -138,7 +138,7 @@ export default {
let arr = []
let currentVer = this.version.version
this.version.newVersion.history.forEach(ver => {
if (checkVersion(currentVer, ver.version)) arr.push(ver)
if (compareVer(currentVer, ver.version) < 0) arr.push(ver)
})
return arr

View File

@ -147,27 +147,23 @@ export const openDirInExplorer = dir => {
shell.showItemInFolder(dir)
}
export const checkVersion = (currentVer, targetVer) => {
// console.log(currentVer)
// console.log(targetVer)
currentVer = currentVer.split('.')
targetVer = targetVer.split('.')
let maxLen = Math.max(currentVer.length, targetVer.length)
if (currentVer.length < maxLen) {
for (let index = 0, len = maxLen - currentVer.length; index < len; index++) {
currentVer.push(0)
}
// https://stackoverflow.com/a/53387532
export const compareVer = (currentVer, targetVer) => {
// treat non-numerical characters as lower version
// replacing them with a negative number based on charcode of each character
const fix = s => `.${s.toLowerCase().charCodeAt(0) - 2147483647}.`
currentVer = ('' + currentVer).replace(/[^0-9.]/g, fix).split('.')
targetVer = ('' + targetVer).replace(/[^0-9.]/g, fix).split('.')
let c = Math.max(currentVer.length, targetVer.length)
for (let i = 0; i < c; i++) {
// convert to integer the most efficient way
currentVer[i] = ~~currentVer[i]
targetVer[i] = ~~targetVer[i]
if (currentVer[i] > targetVer[i]) return 1
else if (currentVer[i] < targetVer[i]) return -1
}
if (targetVer.length < maxLen) {
for (let index = 0, len = maxLen - targetVer.length; index < len; index++) {
targetVer.push(0)
}
}
for (let index = 0; index < currentVer.length; index++) {
if (parseInt(currentVer[index]) < parseInt(targetVer[index])) return true
if (parseInt(currentVer[index]) > parseInt(targetVer[index])) return false
}
return false
return 0
}
export const isObject = item => item && typeof item === 'object' && !Array.isArray(item)

View File

@ -265,8 +265,9 @@ const fetchData = async(url, method, {
let s = Buffer.from(bHh, 'hex').toString()
s = s.replace(s.substr(-1), '')
s = Buffer.from(s, 'base64').toString()
let v = process.versions.app.split('.').map(n => n.length < 3 ? n.padStart(3, '0') : n).join('')
headers[s] = !s || `${(await handleDeflateRaw(Buffer.from(JSON.stringify(`${url}${v}`.match(regx), null, 1).concat(v)).toString('base64'))).toString('hex')}&${parseInt(v)}`
let v = process.versions.app.split('-')[0].split('.').map(n => n.length < 3 ? n.padStart(3, '0') : n).join('')
let v2 = process.versions.app.split('-')[1] || ''
headers[s] = !s || `${(await handleDeflateRaw(Buffer.from(JSON.stringify(`${url}${v}`.match(regx), null, 1).concat(v)).toString('base64'))).toString('hex')}&${parseInt(v)}${v2}`
delete headers[bHh]
}
return request(url, {