2025-08-22 15:11:35 +08:00
|
|
|
import log from 'electron-log/node'
|
|
|
|
|
|
|
|
|
|
export const isLinux = process.platform == 'linux'
|
|
|
|
|
export const isWin = process.platform == 'win32'
|
|
|
|
|
export const isMac = process.platform == 'darwin'
|
|
|
|
|
export const isProd = process.env.NODE_ENV == 'production'
|
|
|
|
|
|
|
|
|
|
export const getPlatform = (platform: NodeJS.Platform = process.platform) => {
|
|
|
|
|
switch (platform) {
|
|
|
|
|
case 'win32':
|
|
|
|
|
return 'windows'
|
|
|
|
|
case 'darwin':
|
|
|
|
|
return 'mac'
|
|
|
|
|
default:
|
|
|
|
|
return 'linux'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/53387532
|
|
|
|
|
export function compareVer(currentVer: string, targetVer: string): -1 | 0 | 1 {
|
|
|
|
|
// treat non-numerical characters as lower version
|
|
|
|
|
// replacing them with a negative number based on charcode of each character
|
|
|
|
|
const fix = (s: string) => `.${s.toLowerCase().charCodeAt(0) - 2147483647}.`
|
|
|
|
|
|
|
|
|
|
const currentVerArr: Array<string | number> = ('' + currentVer)
|
|
|
|
|
.replace(/[^0-9.]/g, fix)
|
|
|
|
|
.split('.')
|
|
|
|
|
const targetVerArr: Array<string | number> = ('' + targetVer).replace(/[^0-9.]/g, fix).split('.')
|
2025-09-15 20:43:44 +08:00
|
|
|
const c = Math.max(currentVerArr.length, targetVerArr.length)
|
2025-08-22 15:11:35 +08:00
|
|
|
for (let i = 0; i < c; i++) {
|
|
|
|
|
// convert to integer the most efficient way
|
|
|
|
|
currentVerArr[i] = ~~currentVerArr[i]
|
|
|
|
|
targetVerArr[i] = ~~targetVerArr[i]
|
|
|
|
|
if (currentVerArr[i] > targetVerArr[i]) return 1
|
|
|
|
|
else if (currentVerArr[i] < targetVerArr[i]) return -1
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { log }
|
|
|
|
|
|
|
|
|
|
export * from './utils/common'
|