mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-01 17:59:09 +08:00
feat(AppUpdater): integrate User-Agent generation for autoUpdater req… (#7751)
* feat(AppUpdater): integrate User-Agent generation for autoUpdater requests; add systemInfo utility module * feat(systemInfo): enhance macOS version handling using macos-release package for improved accuracy; update package.json and yarn.lock to include macos-release and opendal dependencies
This commit is contained in:
parent
561c563bd7
commit
df47b174ca
@ -62,6 +62,7 @@
|
||||
"@libsql/win32-x64-msvc": "^0.4.7",
|
||||
"@strongtz/win32-arm64-msvc": "^0.4.7",
|
||||
"jsdom": "26.1.0",
|
||||
"macos-release": "^3.4.0",
|
||||
"node-stream-zip": "^1.15.0",
|
||||
"notion-helper": "^1.3.22",
|
||||
"os-proxy-config": "^1.1.2",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { isWin } from '@main/constant'
|
||||
import { locales } from '@main/utils/locales'
|
||||
import { generateUserAgent } from '@main/utils/systemInfo'
|
||||
import { FeedUrl, UpgradeChannel } from '@shared/config/constant'
|
||||
import { IpcChannel } from '@shared/IpcChannel'
|
||||
import { CancellationToken, UpdateInfo } from 'builder-util-runtime'
|
||||
@ -24,6 +25,10 @@ export default class AppUpdater {
|
||||
autoUpdater.forceDevUpdateConfig = !app.isPackaged
|
||||
autoUpdater.autoDownload = configManager.getAutoUpdate()
|
||||
autoUpdater.autoInstallOnAppQuit = configManager.getAutoUpdate()
|
||||
autoUpdater.requestHeaders = {
|
||||
...autoUpdater.requestHeaders,
|
||||
'User-Agent': generateUserAgent()
|
||||
}
|
||||
|
||||
autoUpdater.on('error', (error) => {
|
||||
// 简单记录错误信息和时间戳
|
||||
|
||||
92
src/main/utils/systemInfo.ts
Normal file
92
src/main/utils/systemInfo.ts
Normal file
@ -0,0 +1,92 @@
|
||||
import { app } from 'electron'
|
||||
import macosRelease from 'macos-release'
|
||||
import os from 'os'
|
||||
|
||||
/**
|
||||
* System information interface
|
||||
*/
|
||||
export interface SystemInfo {
|
||||
platform: NodeJS.Platform
|
||||
arch: string
|
||||
osRelease: string
|
||||
appVersion: string
|
||||
osString: string
|
||||
archString: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Get basic system constants for quick access
|
||||
* @returns {Object} Basic system constants
|
||||
*/
|
||||
export function getSystemConstants() {
|
||||
return {
|
||||
platform: process.platform,
|
||||
arch: process.arch,
|
||||
osRelease: os.release(),
|
||||
appVersion: app.getVersion()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get system information
|
||||
* @returns {SystemInfo} Complete system information object
|
||||
*/
|
||||
export function getSystemInfo(): SystemInfo {
|
||||
const platform = process.platform
|
||||
const arch = process.arch
|
||||
const osRelease = os.release()
|
||||
const appVersion = app.getVersion()
|
||||
|
||||
let osString = ''
|
||||
|
||||
switch (platform) {
|
||||
case 'win32': {
|
||||
// Get Windows version
|
||||
const parts = osRelease.split('.')
|
||||
const buildNumber = parseInt(parts[2], 10)
|
||||
osString = buildNumber >= 22000 ? 'Windows 11' : 'Windows 10'
|
||||
break
|
||||
}
|
||||
case 'darwin': {
|
||||
// macOS version handling using macos-release for better accuracy
|
||||
try {
|
||||
const macVersionInfo = macosRelease()
|
||||
const versionString = macVersionInfo.version.replace(/\./g, '_') // 15.0.0 -> 15_0_0
|
||||
osString = arch === 'arm64' ? `Mac OS X ${versionString}` : `Intel Mac OS X ${versionString}` // Mac OS X 15_0_0
|
||||
} catch (error) {
|
||||
// Fallback to original logic if macos-release fails
|
||||
const macVersion = osRelease.split('.').slice(0, 2).join('_')
|
||||
osString = arch === 'arm64' ? `Mac OS X ${macVersion}` : `Intel Mac OS X ${macVersion}`
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'linux': {
|
||||
osString = `Linux ${arch}`
|
||||
break
|
||||
}
|
||||
default: {
|
||||
osString = `${platform} ${arch}`
|
||||
}
|
||||
}
|
||||
|
||||
const archString = arch === 'x64' ? 'x86_64' : arch === 'arm64' ? 'arm64' : arch
|
||||
|
||||
return {
|
||||
platform,
|
||||
arch,
|
||||
osRelease,
|
||||
appVersion,
|
||||
osString,
|
||||
archString
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate User-Agent string based on user system data
|
||||
* @returns {string} Dynamically generated User-Agent string
|
||||
*/
|
||||
export function generateUserAgent(): string {
|
||||
const systemInfo = getSystemInfo()
|
||||
|
||||
return `Mozilla/5.0 (${systemInfo.osString}; ${systemInfo.archString}) AppleWebKit/537.36 (KHTML, like Gecko) CherryStudio/${systemInfo.appVersion} Chrome/124.0.0.0 Safari/537.36`
|
||||
}
|
||||
@ -5703,6 +5703,7 @@ __metadata:
|
||||
lodash: "npm:^4.17.21"
|
||||
lru-cache: "npm:^11.1.0"
|
||||
lucide-react: "npm:^0.487.0"
|
||||
macos-release: "npm:^3.4.0"
|
||||
markdown-it: "npm:^14.1.0"
|
||||
mermaid: "npm:^11.6.0"
|
||||
mime: "npm:^4.0.4"
|
||||
@ -12194,6 +12195,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"macos-release@npm:^3.4.0":
|
||||
version: 3.4.0
|
||||
resolution: "macos-release@npm:3.4.0"
|
||||
checksum: 10c0/cb6ea203cc2a2b2cc2214db4658d0da0e52f8298c5c43c94cf9cb9e871daac59e4e56a2559859727a4b43b0afec1123f998ef62c58d1ac6c6c8a5c8a808330cb
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"magic-string@npm:^0.30.17":
|
||||
version: 0.30.17
|
||||
resolution: "magic-string@npm:0.30.17"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user