diff --git a/src/ntqqapi/native/moehoo/index.ts b/src/ntqqapi/native/moehoo/index.ts index ccb1f6d..d8d0f76 100644 --- a/src/ntqqapi/native/moehoo/index.ts +++ b/src/ntqqapi/native/moehoo/index.ts @@ -34,7 +34,7 @@ export class Native { } const platform = process.platform + '.' + process.arch try { - const fileName = 'MoeHoo.' + platform + '.node' + const fileName = 'MoeHoo.' + platform + '.node' // todo: 需要加入版本号或者hash,不然多开QQ时会导致copyFile失败从而无法进行在线更新 const src = path.join(__dirname, 'Moehoo', fileName) const dest = path.join(TEMP_DIR, fileName) try { diff --git a/src/ntqqapi/native/moehoo/version.ts b/src/ntqqapi/native/moehoo/version.ts new file mode 100644 index 0000000..2d7300c --- /dev/null +++ b/src/ntqqapi/native/moehoo/version.ts @@ -0,0 +1,35 @@ +import os from 'os' +import offset from '@/ntqqapi/helper/offset.json' +import { getFullVersion } from '@/common/utils' + +function getSupportVersions() { + let fullVersionStart: string = '' + switch (os.platform()) { + case 'linux': + fullVersionStart = '3' + break + case 'darwin': + fullVersionStart = '6' + break + case 'win32': + fullVersionStart = '9' + break + } + const supportVersions: string[] = [] + for (const offsetKey in offset) { + if (offsetKey.startsWith(fullVersionStart) && offsetKey.endsWith(os.arch())) { + supportVersions.push(offsetKey) + } + } + return supportVersions +} + +export function checkSupportVersion(){ + // 检查当前 QQ 版本是否支持,不支持则抛出异常 + const qqFullVersion = getFullVersion() // todo: 去除llqqnt依赖 + const _ = offset[qqFullVersion + '-' + os.arch()] + if (!_) { + const supportVersion = getSupportVersions() + throw new Error('当前 QQ 版本不支持, 只支持: ' + supportVersion.join(', ')) + } +}