mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 05:39:05 +08:00
fix: enhance AppUpdater with IP country detection (#7235)
* fix: downgrade version in package.json and enhance AppUpdater with IP country detection - Downgraded the application version from 1.4.2 to 1.4.1 in package.json. - Added a new private method `_getIpCountry` in AppUpdater to fetch the user's IP country with a timeout mechanism. - Updated the `setAutoUpdate` method to adjust the feed URL based on the detected country, improving update handling for users outside of China. * fix: adjust timeout duration and enhance IP country logging in AppUpdater * fix: extend timeout duration in AppUpdater for improved fetch reliability --------- Co-authored-by: beyondkmp <beyondkmkp@gmail.com>
This commit is contained in:
parent
477b5d2449
commit
f48e7aadb8
@ -64,6 +64,30 @@ export default class AppUpdater {
|
|||||||
this.autoUpdater = autoUpdater
|
this.autoUpdater = autoUpdater
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _getIpCountry() {
|
||||||
|
try {
|
||||||
|
// add timeout using AbortController
|
||||||
|
const controller = new AbortController()
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 5000)
|
||||||
|
|
||||||
|
const ipinfo = await fetch('https://ipinfo.io/json', {
|
||||||
|
signal: controller.signal,
|
||||||
|
headers: {
|
||||||
|
'User-Agent':
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
|
||||||
|
'Accept-Language': 'en-US,en;q=0.9'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
clearTimeout(timeoutId)
|
||||||
|
const data = await ipinfo.json()
|
||||||
|
return data.country || 'CN'
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Failed to get ipinfo:', error)
|
||||||
|
return 'CN'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public setAutoUpdate(isActive: boolean) {
|
public setAutoUpdate(isActive: boolean) {
|
||||||
autoUpdater.autoDownload = isActive
|
autoUpdater.autoDownload = isActive
|
||||||
autoUpdater.autoInstallOnAppQuit = isActive
|
autoUpdater.autoInstallOnAppQuit = isActive
|
||||||
@ -82,6 +106,12 @@ export default class AppUpdater {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ipCountry = await this._getIpCountry()
|
||||||
|
logger.info('ipCountry', ipCountry)
|
||||||
|
if (ipCountry !== 'CN') {
|
||||||
|
this.autoUpdater.setFeedURL(FeedUrl.EARLY_ACCESS)
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const update = await this.autoUpdater.checkForUpdates()
|
const update = await this.autoUpdater.checkForUpdates()
|
||||||
if (update?.isUpdateAvailable && !this.autoUpdater.autoDownload) {
|
if (update?.isUpdateAvailable && !this.autoUpdater.autoDownload) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user