♻️ 分离状态代码

This commit is contained in:
yeyang
2024-03-26 01:46:19 +08:00
committed by 🌌
parent 307b643b60
commit d59f2553f4
16 changed files with 629 additions and 600 deletions

View File

@@ -0,0 +1,24 @@
export let si = false
export let osInfo = null
export async function initDependence () {
if (si) return si
try {
si = await import('systeminformation')
osInfo = await si.osInfo()
return si
} catch (error) {
if (error.stack?.includes('Cannot find package')) {
logger.warn('--------椰奶依赖缺失--------')
logger.warn(`yenai-plugin 缺少依赖将无法使用 ${logger.yellow('椰奶状态')}`)
logger.warn(`如需使用请运行:${logger.red('pnpm add systeminformation -w')}`)
logger.warn('---------------------------')
logger.debug(decodeURI(error.stack))
} else {
logger.error(`椰奶载入依赖错误:${logger.red('systeminformation')}`)
logger.error(decodeURI(error.stack))
}
}
}
await initDependence()