fix: QQ package.json on macOS

This commit is contained in:
linyuchen 2024-05-28 15:42:22 +08:00
parent 27f98a459c
commit a4aeb8171d

View File

@ -3,26 +3,34 @@ import fs from 'node:fs'
import os from 'node:os' import os from 'node:os'
import { systemPlatform } from './system' import { systemPlatform } from './system'
export const exePath = process.execPath; export const exePath = process.execPath
export const pkgInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'package.json'); function getPKGPath() {
let configVersionInfoPath; let p = path.join(path.dirname(exePath), 'resources', 'app', 'package.json')
if (systemPlatform === 'darwin') {
p = path.join(path.dirname(path.dirname(exePath)), 'Resources', 'app', 'package.json')
}
return p
}
export const pkgInfoPath = getPKGPath()
let configVersionInfoPath: string
if (os.platform() !== 'linux') { if (os.platform() !== 'linux') {
configVersionInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'versions', 'config.json'); configVersionInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'versions', 'config.json')
} else { }
const userPath = os.homedir(); else {
const appDataPath = path.resolve(userPath, './.config/QQ'); const userPath = os.homedir()
configVersionInfoPath = path.resolve(appDataPath, './versions/config.json'); const appDataPath = path.resolve(userPath, './.config/QQ')
configVersionInfoPath = path.resolve(appDataPath, './versions/config.json')
} }
if (typeof configVersionInfoPath !== 'string') { if (typeof configVersionInfoPath !== 'string') {
throw new Error('Something went wrong when load QQ info path'); throw new Error('Something went wrong when load QQ info path')
} }
export { configVersionInfoPath }; export { configVersionInfoPath }
type QQPkgInfo = { type QQPkgInfo = {
version: string; version: string;
@ -43,21 +51,21 @@ let _qqVersionConfigInfo: QQVersionConfigInfo = {
'curVersion': '9.9.9-23361', 'curVersion': '9.9.9-23361',
'prevVersion': '', 'prevVersion': '',
'onErrorVersions': [], 'onErrorVersions': [],
'buildId': '23361' 'buildId': '23361',
}; }
if (fs.existsSync(configVersionInfoPath)) { if (fs.existsSync(configVersionInfoPath)) {
try { try {
const _ =JSON.parse(fs.readFileSync(configVersionInfoPath).toString()); const _ = JSON.parse(fs.readFileSync(configVersionInfoPath).toString())
_qqVersionConfigInfo = Object.assign(_qqVersionConfigInfo, _); _qqVersionConfigInfo = Object.assign(_qqVersionConfigInfo, _)
} catch (e) { } catch (e) {
console.error('Load QQ version config info failed, Use default version', e); console.error('Load QQ version config info failed, Use default version', e)
} }
} }
export const qqVersionConfigInfo: QQVersionConfigInfo = _qqVersionConfigInfo; export const qqVersionConfigInfo: QQVersionConfigInfo = _qqVersionConfigInfo
export const qqPkgInfo: QQPkgInfo = require(pkgInfoPath); export const qqPkgInfo: QQPkgInfo = require(pkgInfoPath)
// platform_type: 3, // platform_type: 3,
// app_type: 4, // app_type: 4,
// app_version: '9.9.9-23159', // app_version: '9.9.9-23159',
@ -66,10 +74,10 @@ export const qqPkgInfo: QQPkgInfo = require(pkgInfoPath);
// platVer: '10.0.26100', // platVer: '10.0.26100',
// clientVer: '9.9.9-23159', // clientVer: '9.9.9-23159',
let _appid: string = '537213803'; // 默认为 Windows 平台的 appid let _appid: string = '537213803' // 默认为 Windows 平台的 appid
if (systemPlatform === 'linux') { if (systemPlatform === 'linux') {
_appid = '537213827'; _appid = '537213827'
} }
// todo: mac 平台的 appid // todo: mac 平台的 appid
export const appid = _appid; export const appid = _appid
export const isQQ998: boolean = qqPkgInfo.buildVersion >= '22106' export const isQQ998: boolean = qqPkgInfo.buildVersion >= '22106'