mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-24 23:06:51 +00:00
计划优化 P5/5
This commit is contained in:
@@ -14,6 +14,7 @@ class CloudControlService {
|
||||
private deviceId: string = ''
|
||||
private timer: NodeJS.Timeout | null = null
|
||||
private pages: Set<string> = new Set()
|
||||
private platformVersionCache: string | null = null
|
||||
|
||||
async init() {
|
||||
this.deviceId = this.getDeviceId()
|
||||
@@ -47,7 +48,12 @@ class CloudControlService {
|
||||
}
|
||||
|
||||
private getPlatformVersion(): string {
|
||||
if (this.platformVersionCache) {
|
||||
return this.platformVersionCache
|
||||
}
|
||||
|
||||
const os = require('os')
|
||||
const fs = require('fs')
|
||||
const platform = process.platform
|
||||
|
||||
if (platform === 'win32') {
|
||||
@@ -59,21 +65,79 @@ class CloudControlService {
|
||||
|
||||
// Windows 11 是 10.0.22000+,且主版本必须是 10.0
|
||||
if (major === 10 && minor === 0 && build >= 22000) {
|
||||
return 'Windows 11'
|
||||
this.platformVersionCache = 'Windows 11'
|
||||
return this.platformVersionCache
|
||||
} else if (major === 10) {
|
||||
return 'Windows 10'
|
||||
this.platformVersionCache = 'Windows 10'
|
||||
return this.platformVersionCache
|
||||
}
|
||||
return `Windows ${release}`
|
||||
this.platformVersionCache = `Windows ${release}`
|
||||
return this.platformVersionCache
|
||||
}
|
||||
|
||||
if (platform === 'darwin') {
|
||||
// `os.release()` returns Darwin kernel version (e.g. 25.3.0),
|
||||
// while cloud reporting expects the macOS product version (e.g. 26.3).
|
||||
const macVersion = typeof process.getSystemVersion === 'function' ? process.getSystemVersion() : os.release()
|
||||
return `macOS ${macVersion}`
|
||||
this.platformVersionCache = `macOS ${macVersion}`
|
||||
return this.platformVersionCache
|
||||
}
|
||||
|
||||
return platform
|
||||
if (platform === 'linux') {
|
||||
try {
|
||||
const osReleasePaths = ['/etc/os-release', '/usr/lib/os-release']
|
||||
for (const filePath of osReleasePaths) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(filePath, 'utf8')
|
||||
const values: Record<string, string> = {}
|
||||
|
||||
for (const line of content.split('\n')) {
|
||||
const trimmed = line.trim()
|
||||
if (!trimmed || trimmed.startsWith('#')) {
|
||||
continue
|
||||
}
|
||||
|
||||
const separatorIndex = trimmed.indexOf('=')
|
||||
if (separatorIndex <= 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
const key = trimmed.slice(0, separatorIndex)
|
||||
let value = trimmed.slice(separatorIndex + 1).trim()
|
||||
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith('\'') && value.endsWith('\''))) {
|
||||
value = value.slice(1, -1)
|
||||
}
|
||||
values[key] = value
|
||||
}
|
||||
|
||||
if (values.PRETTY_NAME) {
|
||||
this.platformVersionCache = values.PRETTY_NAME
|
||||
return this.platformVersionCache
|
||||
}
|
||||
|
||||
if (values.NAME && values.VERSION_ID) {
|
||||
this.platformVersionCache = `${values.NAME} ${values.VERSION_ID}`
|
||||
return this.platformVersionCache
|
||||
}
|
||||
|
||||
if (values.NAME) {
|
||||
this.platformVersionCache = values.NAME
|
||||
return this.platformVersionCache
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('[CloudControl] Failed to detect Linux distro version:', error)
|
||||
}
|
||||
|
||||
this.platformVersionCache = `Linux ${os.release()}`
|
||||
return this.platformVersionCache
|
||||
}
|
||||
|
||||
this.platformVersionCache = platform
|
||||
return this.platformVersionCache
|
||||
}
|
||||
|
||||
recordPage(pageName: string) {
|
||||
|
||||
Reference in New Issue
Block a user