🔨 Refactor: refactor some code and add error log

This commit is contained in:
萌萌哒赫萝
2023-04-26 17:01:55 +08:00
parent 041018d4cc
commit 8cfb1006a9
11 changed files with 49 additions and 42 deletions

View File

@@ -52,28 +52,21 @@ export const showMessageBox = (options: any) => {
})
}
const thresholds = [
{ limit: 1000, value: 500 },
{ limit: 1500, value: 1000 },
{ limit: 3000, value: 2000 },
{ limit: 5000, value: 3000 },
{ limit: 7000, value: 5000 },
{ limit: 10000, value: 8000 },
{ limit: 12000, value: 10000 },
{ limit: 20000, value: 15000 },
{ limit: 30000, value: 20000 }
]
export const calcDurationRange = (duration: number) => {
if (duration < 1000) {
return 500
} else if (duration < 1500) {
return 1000
} else if (duration < 3000) {
return 2000
} else if (duration < 5000) {
return 3000
} else if (duration < 7000) {
return 5000
} else if (duration < 10000) {
return 8000
} else if (duration < 12000) {
return 10000
} else if (duration < 20000) {
return 15000
} else if (duration < 30000) {
return 20000
}
// max range
return 100000
const foundThreshold = thresholds.find(({ limit }) => duration < limit)
return foundThreshold ? foundThreshold.value : 100000
}
/**

View File

@@ -8,19 +8,11 @@ export const isMacOS = process.platform === 'darwin'
let version: string | undefined
const clean = (version: string) => {
const { length } = version.split('.')
if (length === 1) {
return `${version}.0.0`
}
if (length === 2) {
return `${version}.0`
}
return version
}
const clean = (version: string) => version.split('.').length === 1
? `${version}.0.0`
: version.split('.').length === 2
? `${version}.0`
: version
const parseVersion = (plist: string) => {
const matches = /<key>ProductVersion<\/key>\s*<string>([\d.]+)<\/string>/.exec(plist)
@@ -32,9 +24,7 @@ const parseVersion = (plist: string) => {
}
export function macOSVersion (): string {
if (!isMacOS) {
return ''
}
if (!isMacOS) return ''
if (!version) {
const file = fs.readFileSync('/System/Library/CoreServices/SystemVersion.plist', 'utf8')