mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 13:59:28 +08:00
feat: add client ID generation and update user agent headers in AppUpdater
- Introduced a new method in ConfigManager to generate and retrieve a unique client ID. - Updated AppUpdater to include the client ID in the request headers alongside the user agent.
This commit is contained in:
parent
83d2403339
commit
ba7eec64b0
@ -2,7 +2,7 @@ import { loggerService } from '@logger'
|
|||||||
import { isWin } from '@main/constant'
|
import { isWin } from '@main/constant'
|
||||||
import { getIpCountry } from '@main/utils/ipService'
|
import { getIpCountry } from '@main/utils/ipService'
|
||||||
import { locales } from '@main/utils/locales'
|
import { locales } from '@main/utils/locales'
|
||||||
import { generateUserAgent } from '@main/utils/systemInfo'
|
import { generateClientTelemetryHeader, generateUserAgent } from '@main/utils/systemInfo'
|
||||||
import { FeedUrl, UpgradeChannel } from '@shared/config/constant'
|
import { FeedUrl, UpgradeChannel } from '@shared/config/constant'
|
||||||
import { IpcChannel } from '@shared/IpcChannel'
|
import { IpcChannel } from '@shared/IpcChannel'
|
||||||
import { CancellationToken, UpdateInfo } from 'builder-util-runtime'
|
import { CancellationToken, UpdateInfo } from 'builder-util-runtime'
|
||||||
@ -30,7 +30,8 @@ export default class AppUpdater {
|
|||||||
autoUpdater.autoInstallOnAppQuit = configManager.getAutoUpdate()
|
autoUpdater.autoInstallOnAppQuit = configManager.getAutoUpdate()
|
||||||
autoUpdater.requestHeaders = {
|
autoUpdater.requestHeaders = {
|
||||||
...autoUpdater.requestHeaders,
|
...autoUpdater.requestHeaders,
|
||||||
'User-Agent': generateUserAgent()
|
'User-Agent': generateUserAgent(),
|
||||||
|
'X-Client-Id': configManager.getClientId()
|
||||||
}
|
}
|
||||||
|
|
||||||
autoUpdater.on('error', (error) => {
|
autoUpdater.on('error', (error) => {
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { defaultLanguage, UpgradeChannel, ZOOM_SHORTCUTS } from '@shared/config/
|
|||||||
import { LanguageVarious, Shortcut, ThemeMode } from '@types'
|
import { LanguageVarious, Shortcut, ThemeMode } from '@types'
|
||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
import Store from 'electron-store'
|
import Store from 'electron-store'
|
||||||
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
|
|
||||||
import { locales } from '../utils/locales'
|
import { locales } from '../utils/locales'
|
||||||
|
|
||||||
@ -27,7 +28,8 @@ export enum ConfigKeys {
|
|||||||
SelectionAssistantFilterList = 'selectionAssistantFilterList',
|
SelectionAssistantFilterList = 'selectionAssistantFilterList',
|
||||||
DisableHardwareAcceleration = 'disableHardwareAcceleration',
|
DisableHardwareAcceleration = 'disableHardwareAcceleration',
|
||||||
Proxy = 'proxy',
|
Proxy = 'proxy',
|
||||||
EnableDeveloperMode = 'enableDeveloperMode'
|
EnableDeveloperMode = 'enableDeveloperMode',
|
||||||
|
ClientId = 'clientId'
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ConfigManager {
|
export class ConfigManager {
|
||||||
@ -241,6 +243,17 @@ export class ConfigManager {
|
|||||||
this.set(ConfigKeys.EnableDeveloperMode, value)
|
this.set(ConfigKeys.EnableDeveloperMode, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getClientId(): string {
|
||||||
|
let clientId = this.get<string>(ConfigKeys.ClientId)
|
||||||
|
|
||||||
|
if (!clientId) {
|
||||||
|
clientId = uuidv4()
|
||||||
|
this.set(ConfigKeys.ClientId, clientId)
|
||||||
|
}
|
||||||
|
|
||||||
|
return clientId
|
||||||
|
}
|
||||||
|
|
||||||
set(key: string, value: unknown, isNotify: boolean = false) {
|
set(key: string, value: unknown, isNotify: boolean = false) {
|
||||||
this.store.set(key, value)
|
this.store.set(key, value)
|
||||||
isNotify && this.notifySubscribers(key, value)
|
isNotify && this.notifySubscribers(key, value)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user